4 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
8 #include <ipxe/socket.h>
10 /* Protocol numbers */
17 /* IP address constants */
19 #define INADDR_NONE htonl ( 0xffffffff )
21 #define INADDR_BROADCAST htonl ( 0xffffffff )
23 #define INADDR_NET_CLASSA htonl ( 0xff000000 )
24 #define INADDR_NET_CLASSB htonl ( 0xffff0000 )
25 #define INADDR_NET_CLASSC htonl ( 0xffffff00 )
27 #define IN_IS_CLASSA( addr ) \
28 ( ( (addr) & htonl ( 0x80000000 ) ) == htonl ( 0x00000000 ) )
29 #define IN_IS_CLASSB( addr ) \
30 ( ( (addr) & htonl ( 0xc0000000 ) ) == htonl ( 0x80000000 ) )
31 #define IN_IS_CLASSC( addr ) \
32 ( ( (addr) & htonl ( 0xe0000000 ) ) == htonl ( 0xc0000000 ) )
33 #define IN_IS_MULTICAST( addr ) \
34 ( ( (addr) & htonl ( 0xf0000000 ) ) == htonl ( 0xe0000000 ) )
37 * IP address structure
43 typedef struct in_addr in_addr;
46 * IP6 address structure
51 uint16_t u6_addr16[8];
52 uint32_t u6_addr32[4];
54 #define s6_addr in6_u.u6_addr8
55 #define s6_addr16 in6_u.u6_addr16
56 #define s6_addr32 in6_u.u6_addr32
59 #define IN6_IS_ADDR_UNSPECIFIED( addr ) \
60 ( ( ( ( ( const uint32_t * ) (addr) )[0] ) | \
61 ( ( ( const uint32_t * ) (addr) )[1] ) | \
62 ( ( ( const uint32_t * ) (addr) )[2] ) | \
63 ( ( ( const uint32_t * ) (addr) )[3] ) ) == 0 )
65 #define IN6_IS_ADDR_MULTICAST( addr ) \
66 ( *( ( const uint8_t * ) (addr) ) == 0xff )
68 #define IN6_IS_ADDR_LINKLOCAL( addr ) \
69 ( ( *( ( const uint16_t * ) (addr) ) & htons ( 0xffc0 ) ) == \
72 #define IN6_IS_ADDR_NONGLOBAL( addr ) \
73 ( IN6_IS_ADDR_LINKLOCAL (addr) || IN6_IS_ADDR_MULTICAST (addr) )
79 /** Socket address family (part of struct @c sockaddr)
81 * Always set to @c AF_INET for IPv4 addresses
83 sa_family_t sin_family;
84 /** Flags (part of struct @c sockaddr_tcpip) */
86 /** TCP/IP port (part of struct @c sockaddr_tcpip) */
88 /** Scope ID (part of struct @c sockaddr_tcpip)
90 * For multicast addresses, this is the network device index.
92 uint16_t sin_scope_id;
94 struct in_addr sin_addr;
97 * This ensures that a struct @c sockaddr_in is large enough
98 * to hold a socket address for any TCP/IP address family.
100 char pad[ sizeof ( struct sockaddr ) -
101 ( sizeof ( sa_family_t ) /* sin_family */ +
102 sizeof ( uint16_t ) /* sin_flags */ +
103 sizeof ( uint16_t ) /* sin_port */ +
104 sizeof ( uint16_t ) /* sin_scope_id */ +
105 sizeof ( struct in_addr ) /* sin_addr */ ) ];
106 } __attribute__ (( packed, may_alias ));
109 * IPv6 socket address
111 struct sockaddr_in6 {
112 /** Socket address family (part of struct @c sockaddr)
114 * Always set to @c AF_INET6 for IPv6 addresses
116 sa_family_t sin6_family;
117 /** Flags (part of struct @c sockaddr_tcpip) */
119 /** TCP/IP port (part of struct @c sockaddr_tcpip) */
121 /** Scope ID (part of struct @c sockaddr_tcpip)
123 * For link-local or multicast addresses, this is the network
126 uint16_t sin6_scope_id;
128 struct in6_addr sin6_addr;
131 * This ensures that a struct @c sockaddr_in6 is large
132 * enough to hold a socket address for any TCP/IP address
135 char pad[ sizeof ( struct sockaddr ) -
136 ( sizeof ( sa_family_t ) /* sin6_family */ +
137 sizeof ( uint16_t ) /* sin6_flags */ +
138 sizeof ( uint16_t ) /* sin6_port */ +
139 sizeof ( uint16_t ) /* sin6_scope_id */ +
140 sizeof ( struct in6_addr ) /* sin6_addr */ ) ];
141 } __attribute__ (( packed, may_alias ));
143 extern int inet_aton ( const char *cp, struct in_addr *inp );
144 extern char * inet_ntoa ( struct in_addr in );
145 extern int inet6_aton ( const char *string, struct in6_addr *in );
146 extern char * inet6_ntoa ( const struct in6_addr *in );
148 #endif /* _IPXE_IN_H */