Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / include / ipxe / in.h
1 #ifndef _IPXE_IN_H
2 #define _IPXE_IN_H
3
4 FILE_LICENCE ( GPL2_OR_LATER );
5
6 #include <stdint.h>
7 #include <ipxe/socket.h>
8
9 /* Protocol numbers */
10
11 #define IP_ICMP         1
12 #define IP_TCP          6
13 #define IP_UDP          17
14 #define IP_ICMP6        58
15
16 /* IP address constants */
17
18 #define INADDR_NONE 0xffffffff
19
20 #define INADDR_BROADCAST 0xffffffff
21
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 )
29
30 /**
31  * IP address structure
32  */
33 struct in_addr {
34         uint32_t        s_addr;
35 };
36
37 typedef struct in_addr in_addr;
38
39 /**
40  * IP6 address structure
41  */
42 struct in6_addr {
43         union {
44                 uint8_t u6_addr8[16];
45                 uint16_t u6_addr16[8];
46                 uint32_t u6_addr32[4];
47         } in6_u;
48 #define s6_addr         in6_u.u6_addr8
49 #define s6_addr16       in6_u.u6_addr16
50 #define s6_addr32       in6_u.u6_addr32
51 };
52
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 )
58
59 #define IN6_IS_ADDR_MULTICAST( addr )                                   \
60         ( *( ( const uint8_t * ) (addr) ) == 0xff )
61
62 #define IN6_IS_ADDR_LINKLOCAL( addr )                                   \
63         ( ( *( ( const uint16_t * ) (addr) ) & htons ( 0xffc0 ) ) ==    \
64           htons ( 0xfe80 ) )
65
66 /**
67  * IPv4 socket address
68  */
69 struct sockaddr_in {
70         /** Socket address family (part of struct @c sockaddr)
71          *
72          * Always set to @c AF_INET for IPv4 addresses
73          */
74         sa_family_t sin_family;
75         /** Flags (part of struct @c sockaddr_tcpip) */
76         uint16_t sin_flags;
77         /** TCP/IP port (part of struct @c sockaddr_tcpip) */
78         uint16_t sin_port;
79         /** IPv4 address */
80         struct in_addr sin_addr;
81         /** Padding
82          *
83          * This ensures that a struct @c sockaddr_in is large enough
84          * to hold a socket address for any TCP/IP address family.
85          */
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 ));
92
93 /**
94  * IPv6 socket address
95  */
96 struct sockaddr_in6 {
97         /** Socket address family (part of struct @c sockaddr)
98          *
99          * Always set to @c AF_INET6 for IPv6 addresses
100          */
101         sa_family_t sin6_family;
102         /** Flags (part of struct @c sockaddr_tcpip) */
103         uint16_t sin6_flags;
104         /** TCP/IP port (part of struct @c sockaddr_tcpip) */
105         uint16_t sin6_port;
106         /** Scope ID
107          *
108          * For link-local addresses, this is the network device index.
109          */
110         uint16_t sin6_scope_id;
111         /** IPv6 address */
112         struct in6_addr sin6_addr;
113         /** Padding
114          *
115          * This ensures that a struct @c sockaddr_in6 is large
116          * enough to hold a socket address for any TCP/IP address
117          * family.
118          */
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 ));
126
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 );
131
132 #endif  /* _IPXE_IN_H */