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