Rev 3846 | Rev 4505 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3846 | Rev 3912 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2008 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_SOCKADDR_H__ |
38 | #define __NET_SOCKADDR_H__ |
38 | #define __NET_SOCKADDR_H__ |
39 | 39 | ||
40 | #include <sys/types.h> |
40 | #include <sys/types.h> |
41 | 41 | ||
42 | #define INET_ADDRSTRLEN ( 4 * 3 + 3 ) |
42 | #define INET_ADDRSTRLEN ( 4 * 3 + 3 ) |
43 | #define INET6_ADDRSTRLEN ( 8 * 4 + 7 ) |
43 | #define INET6_ADDRSTRLEN ( 8 * 4 + 7 ) |
44 | 44 | ||
45 | typedef struct sockaddr sockaddr_t; |
45 | typedef struct sockaddr sockaddr_t; |
46 | typedef struct in_addr in_addr_t; |
46 | typedef struct in_addr in_addr_t; |
47 | typedef struct sockaddr_in sockaddr_in_t; |
47 | typedef struct sockaddr_in sockaddr_in_t; |
48 | typedef struct sockaddr_in6 sockaddr_in6_t; |
48 | typedef struct sockaddr_in6 sockaddr_in6_t; |
49 | typedef struct addrinfo addrinfo_t; |
49 | typedef struct addrinfo addrinfo_t; |
50 | 50 | ||
51 | int inet_ntop( uint16_t family, const uint8_t * data, char * address, size_t length ); |
51 | 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 ); |
52 | int inet_pton( uint16_t family, const char * address, uint8_t * data ); |
53 | 53 | ||
54 | struct sockaddr{ |
54 | struct sockaddr{ |
55 | uint16_t sa_family; // address family, AF_xxx |
55 | uint16_t sa_family; // address family, AF_xxx |
56 | uint8_t sa_data[ 14 ]; // 14 bytes of protocol address |
56 | uint8_t sa_data[ 14 ]; // 14 bytes of protocol address |
57 | }; |
57 | }; |
58 | 58 | ||
59 | struct in_addr{ |
59 | struct in_addr{ |
60 | uint32_t s_addr; // that's a 32-bit int (4 bytes) |
60 | uint32_t s_addr; // that's a 32-bit int (4 bytes) |
61 | }; |
61 | }; |
62 | 62 | ||
63 | struct sockaddr_in{ |
63 | struct sockaddr_in{ |
64 | uint16_t sin_family; // Address family, AF_INET |
64 | uint16_t sin_family; // Address family, AF_INET |
65 | uint16_t sin_port; // Port number |
65 | uint16_t sin_port; // Port number |
66 | struct in_addr sin_addr; // Internet address |
66 | struct in_addr sin_addr; // Internet address |
67 | uint8_t sin_zero[ 8 ]; // Same size as struct sockaddr |
67 | uint8_t sin_zero[ 8 ]; // Same size as struct sockaddr |
68 | }; |
68 | }; |
69 | 69 | ||
70 | struct in6_addr{ |
70 | struct in6_addr{ |
71 | unsigned char s6_addr[ 16 ]; // IPv6 address |
71 | unsigned char s6_addr[ 16 ]; // IPv6 address |
72 | }; |
72 | }; |
73 | 73 | ||
74 | struct sockaddr_in6{ |
74 | struct sockaddr_in6{ |
75 | uint16_t sin6_family; // address family, AF_INET6 |
75 | uint16_t sin6_family; // address family, AF_INET6 |
76 | uint16_t sin6_port; // port number, Network Byte Order |
76 | uint16_t sin6_port; // port number, Network Byte Order |
77 | uint32_t sin6_flowinfo; // IPv6 flow information |
77 | uint32_t sin6_flowinfo; // IPv6 flow information |
78 | struct in6_addr sin6_addr; // IPv6 address |
78 | struct in6_addr sin6_addr; // IPv6 address |
79 | uint32_t sin6_scope_id; // Scope ID |
79 | uint32_t sin6_scope_id; // Scope ID |
80 | }; |
80 | }; |
81 | 81 | ||
82 | struct addrinfo{ |
82 | struct addrinfo{ |
83 | int ai_flags; // AI_PASSIVE, AI_CANONNAME, etc. |
83 | int ai_flags; // AI_PASSIVE, AI_CANONNAME, etc. |
84 | uint16_t ai_family; // AF_INET, AF_INET6, AF_UNSPEC |
84 | uint16_t ai_family; // AF_INET, AF_INET6, AF_UNSPEC |
85 | int ai_socktype; // SOCK_STREAM, SOCK_DGRAM |
85 | int ai_socktype; // SOCK_STREAM, SOCK_DGRAM |
86 | int ai_protocol; // use 0 for "any" |
86 | int ai_protocol; // use 0 for "any" |
87 | size_t ai_addrlen; // size of ai_addr in bytes |
87 | size_t ai_addrlen; // size of ai_addr in bytes |
88 | struct sockaddr * ai_addr; // struct sockaddr_in or _in6 |
88 | struct sockaddr * ai_addr; // struct sockaddr_in or _in6 |
89 | char * ai_canonname; // full canonical hostname |
89 | char * ai_canonname; // full canonical hostname |
90 | struct addrinfo * ai_next; // linked list, next node |
90 | struct addrinfo * ai_next; // linked list, next node |
91 | }; |
91 | }; |
92 | 92 | ||
93 | /*int getaddrinfo(const char *node, // e.g. "www.example.com" or IP |
93 | /*int getaddrinfo(const char *node, // e.g. "www.example.com" or IP |
94 | const char *service, // e.g. "http" or port number |
94 | const char *service, // e.g. "http" or port number |
95 | const struct addrinfo *hints, |
95 | const struct addrinfo *hints, |
96 | struct addrinfo **res); |
96 | struct addrinfo **res); |
97 | 97 | ||
98 | getnameinfo |
98 | getnameinfo |
99 | */ |
99 | */ |
100 | 100 | ||
101 | #endif |
101 | #endif |
102 | 102 | ||
103 | /** @} |
103 | /** @} |
104 | */ |
104 | */ |
105 | 105 |