Rev 4505 | Rev 4704 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4505 | Rev 4559 | ||
---|---|---|---|
Line 32... | Line 32... | ||
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 | 54 | ||
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 | - | ||
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" |