iPXE
in.h
Go to the documentation of this file.
1#ifndef _IPXE_IN_H
2#define _IPXE_IN_H
3
4FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
5FILE_SECBOOT ( PERMITTED );
6
7#include <stdint.h>
8#include <byteswap.h>
9#include <ipxe/socket.h>
10
11/* Protocol numbers */
12
13#define IP_ICMP 1
14#define IP_TCP 6
15#define IP_UDP 17
16#define IP_ICMP6 58
17
18/* IP address constants */
19
20#define INADDR_NONE htonl ( 0xffffffff )
21
22#define INADDR_BROADCAST htonl ( 0xffffffff )
23
24#define INADDR_NET_CLASSA htonl ( 0xff000000 )
25#define INADDR_NET_CLASSB htonl ( 0xffff0000 )
26#define INADDR_NET_CLASSC htonl ( 0xffffff00 )
27
28#define IN_IS_CLASSA( addr ) \
29 ( ( (addr) & htonl ( 0x80000000 ) ) == htonl ( 0x00000000 ) )
30#define IN_IS_CLASSB( addr ) \
31 ( ( (addr) & htonl ( 0xc0000000 ) ) == htonl ( 0x80000000 ) )
32#define IN_IS_CLASSC( addr ) \
33 ( ( (addr) & htonl ( 0xe0000000 ) ) == htonl ( 0xc0000000 ) )
34#define IN_IS_MULTICAST( addr ) \
35 ( ( (addr) & htonl ( 0xf0000000 ) ) == htonl ( 0xe0000000 ) )
36
37#define IN_IS_SMALL( mask ) ( (mask) & htonl ( 0x00000003 ) )
38
39/**
40 * IP address structure
41 */
42struct in_addr {
44};
45
46typedef struct in_addr in_addr;
47
48/**
49 * IP6 address structure
50 */
51struct in6_addr {
52 union {
57#define s6_addr in6_u.u6_addr8
58#define s6_addr16 in6_u.u6_addr16
59#define s6_addr32 in6_u.u6_addr32
60};
61
62#define IN6_IS_ADDR_UNSPECIFIED( addr ) \
63 ( ( ( ( ( const uint32_t * ) (addr) )[0] ) | \
64 ( ( ( const uint32_t * ) (addr) )[1] ) | \
65 ( ( ( const uint32_t * ) (addr) )[2] ) | \
66 ( ( ( const uint32_t * ) (addr) )[3] ) ) == 0 )
67
68#define IN6_IS_ADDR_MULTICAST( addr ) \
69 ( *( ( const uint8_t * ) (addr) ) == 0xff )
70
71#define IN6_IS_ADDR_LINKLOCAL( addr ) \
72 ( ( *( ( const uint16_t * ) (addr) ) & htons ( 0xffc0 ) ) == \
73 htons ( 0xfe80 ) )
74
75#define IN6_IS_ADDR_SITELOCAL( addr ) \
76 ( ( *( ( const uint16_t * ) (addr) ) & htons ( 0xffc0 ) ) == \
77 htons ( 0xfec0 ) )
78
79#define IN6_IS_ADDR_ULA( addr ) \
80 ( ( *( ( const uint8_t * ) (addr) ) & 0xfe ) == 0xfc )
81
82/**
83 * IPv4 socket address
84 */
86 /** Socket address family (part of struct @c sockaddr)
87 *
88 * Always set to @c AF_INET for IPv4 addresses
89 */
91 /** Flags (part of struct @c sockaddr_tcpip) */
93 /** TCP/IP port (part of struct @c sockaddr_tcpip) */
95 /** Scope ID (part of struct @c sockaddr_tcpip)
96 *
97 * For multicast addresses, this is the network device index.
98 */
100 /** IPv4 address */
102 /** Padding
103 *
104 * This ensures that a struct @c sockaddr_in is large enough
105 * to hold a socket address for any TCP/IP address family.
106 */
107 char pad[ sizeof ( struct sockaddr ) -
108 ( sizeof ( sa_family_t ) /* sin_family */ +
109 sizeof ( uint16_t ) /* sin_flags */ +
110 sizeof ( uint16_t ) /* sin_port */ +
111 sizeof ( uint16_t ) /* sin_scope_id */ +
112 sizeof ( struct in_addr ) /* sin_addr */ ) ];
113} __attribute__ (( packed, may_alias ));
114
115/**
116 * IPv6 socket address
117 */
119 /** Socket address family (part of struct @c sockaddr)
120 *
121 * Always set to @c AF_INET6 for IPv6 addresses
122 */
124 /** Flags (part of struct @c sockaddr_tcpip) */
126 /** TCP/IP port (part of struct @c sockaddr_tcpip) */
128 /** Scope ID (part of struct @c sockaddr_tcpip)
129 *
130 * For link-local or multicast addresses, this is the network
131 * device index.
132 */
134 /** IPv6 address */
136 /** Padding
137 *
138 * This ensures that a struct @c sockaddr_in6 is large
139 * enough to hold a socket address for any TCP/IP address
140 * family.
141 */
142 char pad[ sizeof ( struct sockaddr ) -
143 ( sizeof ( sa_family_t ) /* sin6_family */ +
144 sizeof ( uint16_t ) /* sin6_flags */ +
145 sizeof ( uint16_t ) /* sin6_port */ +
146 sizeof ( uint16_t ) /* sin6_scope_id */ +
147 sizeof ( struct in6_addr ) /* sin6_addr */ ) ];
148} __attribute__ (( packed, may_alias ));
149
150extern int inet_aton ( const char *cp, struct in_addr *inp );
151extern char * inet_ntoa ( struct in_addr in );
152extern int inet6_aton ( const char *string, struct in6_addr *in );
153extern char * inet6_ntoa ( const struct in6_addr *in );
154
155#endif /* _IPXE_IN_H */
__be32 in[4]
Definition CIB_PRM.h:7
unsigned short uint16_t
Definition stdint.h:11
unsigned int uint32_t
Definition stdint.h:12
unsigned char uint8_t
Definition stdint.h:10
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
char * inet6_ntoa(const struct in6_addr *in)
Convert IPv6 address to standard notation.
Definition ipv6.c:895
int inet_aton(const char *cp, struct in_addr *inp)
Parse IPv4 address.
Definition ipv4.c:787
int inet6_aton(const char *string, struct in6_addr *in)
Parse IPv6 address.
Definition ipv6.c:825
char * inet_ntoa(struct in_addr in)
Convert IPv4 address to dotted-quad notation.
Definition ipv4.c:814
#define __attribute__(x)
Definition compiler.h:10
Socket addresses.
uint16_t sa_family_t
A socket address family.
Definition socket.h:86
IP6 address structure.
Definition in.h:51
uint16_t u6_addr16[8]
Definition in.h:54
uint8_t u6_addr8[16]
Definition in.h:53
union in6_addr::@347247304320251054144374036344124303110102034175 in6_u
uint32_t u6_addr32[4]
Definition in.h:55
IP address structure.
Definition in.h:42
uint32_t s_addr
Definition in.h:43
IPv6 socket address.
Definition in.h:118
uint16_t sin6_flags
Flags (part of struct sockaddr_tcpip)
Definition in.h:125
struct in6_addr sin6_addr
IPv6 address.
Definition in.h:135
uint16_t sin6_port
TCP/IP port (part of struct sockaddr_tcpip)
Definition in.h:127
uint16_t sin6_scope_id
Scope ID (part of struct sockaddr_tcpip)
Definition in.h:133
char pad[sizeof(struct sockaddr) -(sizeof(sa_family_t)+sizeof(uint16_t)+sizeof(uint16_t)+sizeof(uint16_t)+sizeof(struct in6_addr))]
Padding.
Definition in.h:147
sa_family_t sin6_family
Socket address family (part of struct sockaddr)
Definition in.h:123
IPv4 socket address.
Definition in.h:85
uint16_t sin_scope_id
Scope ID (part of struct sockaddr_tcpip)
Definition in.h:99
char pad[sizeof(struct sockaddr) -(sizeof(sa_family_t)+sizeof(uint16_t)+sizeof(uint16_t)+sizeof(uint16_t)+sizeof(struct in_addr))]
Padding.
Definition in.h:112
uint16_t sin_port
TCP/IP port (part of struct sockaddr_tcpip)
Definition in.h:94
struct in_addr sin_addr
IPv4 address.
Definition in.h:101
sa_family_t sin_family
Socket address family (part of struct sockaddr)
Definition in.h:90
uint16_t sin_flags
Flags (part of struct sockaddr_tcpip)
Definition in.h:92
Generalized socket address structure.
Definition socket.h:97