initial check-in, version 0.5.0
[musl] / include / netinet / in.h
1 #ifndef _NETINET_IN_H
2 #define _NETINET_IN_H
3
4 #define __NEED_in_addr_t
5 #define __NEED_in_port_t
6 #define __NEED_sa_family_t
7 #define __NEED_struct_in_addr
8 #define __NEED_uint8_t
9 #define __NEED_uint16_t
10 #define __NEED_uint32_t
11
12 #include <bits/alltypes.h>
13
14 struct sockaddr_in
15 {
16         sa_family_t sin_family;
17         in_port_t sin_port;
18         struct in_addr sin_addr;
19         uint8_t sin_zero[8];
20 };
21
22 struct in6_addr
23 {
24         union {
25                 uint8_t __s6_addr[16];
26                 uint32_t __s6_addr32[4];
27         } __in6_union;
28 };
29 #define s6_addr __in6_union.__s6_addr
30 #define s6_addr32 __in6_union.__s6_addr32
31
32 struct sockaddr_in6
33 {
34         sa_family_t     sin6_family;
35         in_port_t       sin6_port;
36         uint32_t        sin6_flowinfo;
37         struct in6_addr sin6_addr;
38         uint32_t        sin6_scope_id;
39 };
40
41 struct ipv6_mreq
42 {
43         struct in6_addr ipv6mr_multiaddr;
44         unsigned        ipv6mr_interface;
45 };
46
47 #define INADDR_ANY        ((in_addr_t) 0x00000000)
48 #define INADDR_BROADCAST  ((in_addr_t) 0xffffffff)
49 #define INADDR_NONE       ((in_addr_t) 0xffffffff)
50 #define INADDR_LOOPBACK   ((in_addr_t) 0x7f000001)
51
52 #define IN6ADDR_ANY_INIT      { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
53 #define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
54
55 extern const struct in6_addr in6addr_any, in6addr_loopback;
56
57 #undef INET_ADDRSTRLEN
58 #undef INET6_ADDRSTRLEN
59 #define INET_ADDRSTRLEN  16
60 #define INET6_ADDRSTRLEN 46
61
62 uint32_t htonl(uint32_t);
63 uint16_t htons(uint16_t);
64 uint32_t ntohl(uint32_t);
65 uint16_t ntohs(uint16_t);
66
67 #define IPPROTO_IP       0
68 #define IPPROTO_ICMP     1
69 #define IPPROTO_IGMP     2
70 #define IPPROTO_IPIP     4
71 #define IPPROTO_TCP      6
72 #define IPPROTO_EGP      8
73 #define IPPROTO_PUP      12
74 #define IPPROTO_UDP      17
75 #define IPPROTO_IDP      22
76 #define IPPROTO_TP       29
77 #define IPPROTO_IPV6     41
78 #define IPPROTO_ROUTING  43
79 #define IPPROTO_FRAGMENT 44
80 #define IPPROTO_RSVP     46
81 #define IPPROTO_GRE      47
82 #define IPPROTO_ESP      50
83 #define IPPROTO_AH       51
84 #define IPPROTO_ICMPV6   58
85 #define IPPROTO_NONE     59
86 #define IPPROTO_DSTOPTS  60
87 #define IPPROTO_MTP      92
88 #define IPPROTO_ENCAP    98
89 #define IPPROTO_PIM      103
90 #define IPPROTO_COMP     108
91 #define IPPROTO_RAW      255
92
93 #define IN6_IS_ADDR_UNSPECIFIED(a) \
94         (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \
95          ((uint32_t *) (a))[2] == 0 && ((uint32_t *) (a))[3] == 0)
96
97 #define IN6_IS_ADDR_LOOPBACK(a) \
98         (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \
99          ((uint32_t *) (a))[2] == 0 && \
100          ((uint8_t *) (a))[12] == 0 && ((uint8_t *) (a))[13] == 0 && \
101          ((uint8_t *) (a))[14] == 0 && ((uint8_t *) (a))[15] == 1 )
102
103 #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
104
105 #define IN6_IS_ADDR_LINKLOCAL(a) \
106         ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0x80)
107
108 #define IN6_IS_ADDR_SITELOCAL(a) \
109         ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0xc0)
110
111 #define IN6_IS_ADDR_V4MAPPED(a) \
112         (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \
113          ((uint8_t *) (a))[8] == 0 && ((uint8_t *) (a))[9] == 0 && \
114          ((uint8_t *) (a))[10] == 0xff && ((uint8_t *) (a))[11] == 0xff)
115
116 #define IN6_IS_ADDR_V4COMPAT(a) \
117         (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \
118          ((uint32_t *) (a))[2] == 0 && ((uint8_t *) (a))[15] > 1)
119
120 #define IN6_IS_ADDR_MC_NODELOCAL(a) \
121         (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x1))
122
123 #define IN6_IS_ADDR_MC_LINKLOCAL(a) \
124         (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x2))
125
126 #define IN6_IS_ADDR_MC_SITELOCAL(a) \
127         (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x5))
128
129 #define IN6_IS_ADDR_MC_ORGLOCAL(a) \
130         (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x8))
131
132 #define IN6_IS_ADDR_MC_GLOBAL(a) \
133         (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0xe))
134
135 #include <bits/in.h>
136
137 #if 1 /* FIXME: namespace violation */
138 #define IN_CLASSA(a)            ((((in_addr_t)(a)) & 0x80000000) == 0)
139 #define IN_CLASSA_NET           0xff000000
140 #define IN_CLASSA_NSHIFT        24
141 #define IN_CLASSA_HOST          (0xffffffff & ~IN_CLASSA_NET)
142 #define IN_CLASSA_MAX           128
143 #define IN_CLASSB(a)            ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000)
144 #define IN_CLASSB_NET           0xffff0000
145 #define IN_CLASSB_NSHIFT        16
146 #define IN_CLASSB_HOST          (0xffffffff & ~IN_CLASSB_NET)
147 #define IN_CLASSB_MAX           65536
148 #define IN_CLASSC(a)            ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000)
149 #define IN_CLASSC_NET           0xffffff00
150 #define IN_CLASSC_NSHIFT        8
151 #define IN_CLASSC_HOST          (0xffffffff & ~IN_CLASSC_NET)
152 #define IN_CLASSD(a)            ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000)
153 #define IN_MULTICAST(a)         IN_CLASSD(a)
154 #define IN_EXPERIMENTAL(a)      ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000)
155 #define IN_BADCLASS(a)          ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000)
156 #endif
157
158 #endif