4 FILE_LICENCE ( GPL2_OR_LATER );
7 #include <ipxe/socket.h>
16 /* IP address constants */
18 #define INADDR_NONE 0xffffffff
20 #define INADDR_BROADCAST 0xffffffff
22 #define IN_CLASSA(addr) ( ( (addr) & 0x80000000 ) == 0x00000000 )
23 #define IN_CLASSA_NET 0xff000000
24 #define IN_CLASSB(addr) ( ( (addr) & 0xc0000000 ) == 0x80000000 )
25 #define IN_CLASSB_NET 0xffff0000
26 #define IN_CLASSC(addr) ( ( (addr) & 0xe0000000 ) == 0xc0000000 )
27 #define IN_CLASSC_NET 0xffffff00
28 #define IN_MULTICAST(addr) ( ( (addr) & 0xf0000000 ) == 0xe0000000 )
31 * IP address structure
37 typedef struct in_addr in_addr;
40 * IP6 address structure
45 uint16_t u6_addr16[8];
46 uint32_t u6_addr32[4];
48 #define s6_addr in6_u.u6_addr8
49 #define s6_addr16 in6_u.u6_addr16
50 #define s6_addr32 in6_u.u6_addr32
53 #define IN6_IS_ADDR_UNSPECIFIED( addr ) \
54 ( ( ( ( ( const uint32_t * ) (addr) )[0] ) | \
55 ( ( ( const uint32_t * ) (addr) )[1] ) | \
56 ( ( ( const uint32_t * ) (addr) )[2] ) | \
57 ( ( ( const uint32_t * ) (addr) )[3] ) ) == 0 )
59 #define IN6_IS_ADDR_MULTICAST( addr ) \
60 ( *( ( const uint8_t * ) (addr) ) == 0xff )
62 #define IN6_IS_ADDR_LINKLOCAL( addr ) \
63 ( ( *( ( const uint16_t * ) (addr) ) & htons ( 0xffc0 ) ) == \
70 /** Socket address family (part of struct @c sockaddr)
72 * Always set to @c AF_INET for IPv4 addresses
74 sa_family_t sin_family;
75 /** Flags (part of struct @c sockaddr_tcpip) */
77 /** TCP/IP port (part of struct @c sockaddr_tcpip) */
80 struct in_addr sin_addr;
83 * This ensures that a struct @c sockaddr_in is large enough
84 * to hold a socket address for any TCP/IP address family.
86 char pad[ sizeof ( struct sockaddr ) -
87 ( sizeof ( sa_family_t ) /* sin_family */ +
88 sizeof ( uint16_t ) /* sin_flags */ +
89 sizeof ( uint16_t ) /* sin_port */ +
90 sizeof ( struct in_addr ) /* sin_addr */ ) ];
91 } __attribute__ (( packed, may_alias ));
97 /** Socket address family (part of struct @c sockaddr)
99 * Always set to @c AF_INET6 for IPv6 addresses
101 sa_family_t sin6_family;
102 /** Flags (part of struct @c sockaddr_tcpip) */
104 /** TCP/IP port (part of struct @c sockaddr_tcpip) */
108 * For link-local addresses, this is the network device index.
110 uint16_t sin6_scope_id;
112 struct in6_addr sin6_addr;
115 * This ensures that a struct @c sockaddr_in6 is large
116 * enough to hold a socket address for any TCP/IP address
119 char pad[ sizeof ( struct sockaddr ) -
120 ( sizeof ( sa_family_t ) /* sin6_family */ +
121 sizeof ( uint16_t ) /* sin6_flags */ +
122 sizeof ( uint16_t ) /* sin6_port */ +
123 sizeof ( uint16_t ) /* sin6_scope_id */ +
124 sizeof ( struct in6_addr ) /* sin6_addr */ ) ];
125 } __attribute__ (( packed, may_alias ));
127 extern int inet_aton ( const char *cp, struct in_addr *inp );
128 extern char * inet_ntoa ( struct in_addr in );
129 extern int inet6_aton ( const char *string, struct in6_addr *in );
130 extern char * inet6_ntoa ( const struct in6_addr *in );
132 #endif /* _IPXE_IN_H */