Rev 4505 | Rev 4704 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4505 | Rev 4559 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Lukas Mejdrech |
2 | * Copyright (c) 2009 Lukas Mejdrech |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup net |
29 | /** @addtogroup net |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** @file |
33 | /** @file |
34 | * |
34 | * |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #ifndef __NET_SOCKADDR_H__ |
37 | #ifndef __NET_INET_H__ |
38 | #define __NET_SOCKADDR_H__ |
38 | #define __NET_INET_H__ |
39 | 39 | ||
40 | #include <sys/types.h> |
40 | #include <sys/types.h> |
41 | 41 | ||
42 | #define INET_ADDRSTRLEN ( 4 * 3 + 3 + 1 ) |
- | |
43 | #define INET6_ADDRSTRLEN ( 8 * 4 + 7 + 1 ) |
42 | #include "byteorder.h" |
44 | 43 | ||
45 | typedef struct sockaddr sockaddr_t; |
44 | typedef struct sockaddr sockaddr_t; |
46 | typedef struct in_addr in_addr_t; |
- | |
47 | typedef struct sockaddr_in sockaddr_in_t; |
- | |
48 | typedef struct sockaddr_in6 sockaddr_in6_t; |
- | |
49 | typedef struct addrinfo addrinfo_t; |
45 | typedef struct addrinfo addrinfo_t; |
50 | 46 | ||
51 | int inet_ntop( uint16_t family, const uint8_t * data, char * address, size_t length ); |
47 | int inet_ntop( uint16_t family, const uint8_t * data, char * address, size_t length ); |
52 | int inet_pton( uint16_t family, const char * address, uint8_t * data ); |
48 | int inet_pton( uint16_t family, const char * address, uint8_t * data ); |
53 | 49 | ||
54 | struct sockaddr{ |
50 | struct sockaddr{ |
55 | uint16_t sa_family; // address family, AF_xxx |
51 | uint16_t sa_family; // address family, AF_xxx |
56 | uint8_t sa_data[ 14 ]; // 14 bytes of protocol address |
52 | uint8_t sa_data[ 14 ]; // 14 bytes of protocol address |
57 | }; |
53 | }; |
58 | - | ||
59 | struct in_addr{ |
- | |
60 | uint32_t s_addr; // that's a 32-bit int (4 bytes) |
- | |
61 | }; |
- | |
62 | - | ||
63 | struct sockaddr_in{ |
- | |
64 | uint16_t sin_family; // Address family, AF_INET |
- | |
65 | uint16_t sin_port; // Port number |
- | |
66 | struct in_addr sin_addr; // Internet address |
- | |
67 | uint8_t sin_zero[ 8 ]; // Same size as struct sockaddr |
- | |
68 | }; |
- | |
69 | - | ||
70 | struct in6_addr{ |
- | |
71 | unsigned char s6_addr[ 16 ]; // IPv6 address |
- | |
72 | }; |
- | |
73 | - | ||
74 | struct sockaddr_in6{ |
- | |
75 | uint16_t sin6_family; // address family, AF_INET6 |
- | |
76 | uint16_t sin6_port; // port number, Network Byte Order |
- | |
77 | uint32_t sin6_flowinfo; // IPv6 flow information |
- | |
78 | struct in6_addr sin6_addr; // IPv6 address |
- | |
79 | uint32_t sin6_scope_id; // Scope ID |
- | |
80 | }; |
- | |
81 | 54 | ||
82 | struct addrinfo{ |
55 | struct addrinfo{ |
83 | int ai_flags; // AI_PASSIVE, AI_CANONNAME, etc. |
56 | int ai_flags; // AI_PASSIVE, AI_CANONNAME, etc. |
84 | uint16_t ai_family; // AF_INET, AF_INET6, AF_UNSPEC |
57 | uint16_t ai_family; // AF_INET, AF_INET6, AF_UNSPEC |
85 | int ai_socktype; // SOCK_STREAM, SOCK_DGRAM |
58 | int ai_socktype; // SOCK_STREAM, SOCK_DGRAM |
86 | int ai_protocol; // use 0 for "any" |
59 | int ai_protocol; // use 0 for "any" |
87 | size_t ai_addrlen; // size of ai_addr in bytes |
60 | size_t ai_addrlen; // size of ai_addr in bytes |
88 | struct sockaddr * ai_addr; // struct sockaddr_in or _in6 |
61 | struct sockaddr * ai_addr; // struct sockaddr_in or _in6 |
89 | char * ai_canonname; // full canonical hostname |
62 | char * ai_canonname; // full canonical hostname |
90 | struct addrinfo * ai_next; // linked list, next node |
63 | struct addrinfo * ai_next; // linked list, next node |
91 | }; |
64 | }; |
92 | 65 | ||
93 | /*int getaddrinfo(const char *node, // e.g. "www.example.com" or IP |
66 | /*int getaddrinfo(const char *node, // e.g. "www.example.com" or IP |
94 | const char *service, // e.g. "http" or port number |
67 | const char *service, // e.g. "http" or port number |
95 | const struct addrinfo *hints, |
68 | const struct addrinfo *hints, |
96 | struct addrinfo **res); |
69 | struct addrinfo **res); |
97 | 70 | ||
98 | getnameinfo |
71 | getnameinfo |
99 | */ |
72 | */ |
100 | 73 | ||
101 | #endif |
74 | #endif |
102 | 75 | ||
103 | /** @} |
76 | /** @} |
104 | */ |
77 | */ |
105 | 78 |