1 //Written in the D programming language
2 
3 /++
4     D header file for Linux's extensions to POSIX's netinet/in.h.
5 
6     Copyright: Copyright 2017 -
7     License:   $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
8     Authors:   $(HTTP jmdavisprog.com, Jonathan M Davis)
9  +/
10 module core.sys.linux.netinet.in_;
11 
12 import core.sys.posix.config;
13 
14 public import core.sys.posix.netinet.in_;
15 
16 version (CRuntime_Glibc)         version = linux_libc;
17 else version (CRuntime_Musl)     version = linux_libc;
18 else version (CRuntime_Bionic)   version = linux_libc;
19 else version (CRuntime_UClibc)   version = linux_libc;
20 
21 version (CRuntime_Glibc)         version = gnu_libc;
22 else version (CRuntime_UClibc)   version = gnu_libc;
23 
24 version (linux_libc)
25 {
26     extern(C) nothrow @nogc:
27 
28     enum IPPROTO_IPIP    = 4;
29     enum IPPROTO_EGP     = 8;
30     enum IPPROTO_TP      = 29;
31     enum IPPROTO_DCCP    = 33;
32     enum IPPROTO_RSVP    = 46;
33     enum IPPROTO_GRE     = 47;
34     enum IPPROTO_ESP     = 50;
35     enum IPPROTO_AH      = 51;
36     enum IPPROTO_MTP     = 92;
37     enum IPPROTO_BEETPH  = 94;
38     enum IPPROTO_ENCAP   = 98;
39     enum IPPROTO_PIM     = 103;
40     enum IPPROTO_COMP    = 108;
41     enum IPPROTO_SCTP    = 132;
42     enum IPPROTO_UDPLITE = 136;
43     enum IPPROTO_MPLS    = 137;
44 
45     enum IPPROTO_HOPOPTS  = 0;
46     enum IPPROTO_ROUTING  = 43;
47     enum IPPROTO_FRAGMENT = 44;
48     enum IPPROTO_ICMPV6   = 58;
49     enum IPPROTO_NONE     = 59;
50     enum IPPROTO_DSTOPTS  = 60;
51     enum IPPROTO_MH       = 135;
52 
53     enum IPPORT_ECHO       = 7;
54     enum IPPORT_DISCARD    = 9;
55     enum IPPORT_SYSTAT     = 11;
56     enum IPPORT_DAYTIME    = 13;
57     enum IPPORT_NETSTAT    = 15;
58     enum IPPORT_FTP        = 21;
59     enum IPPORT_TELNET     = 23;
60     enum IPPORT_SMTP       = 25;
61     enum IPPORT_TIMESERVER = 37;
62     enum IPPORT_NAMESERVER = 42;
63     enum IPPORT_WHOIS      = 43;
64     enum IPPORT_MTP        = 57;
65 
66     enum IPPORT_TFTP    = 69;
67     enum IPPORT_RJE     = 77;
68     enum IPPORT_FINGER  = 79;
69     enum IPPORT_TTYLINK = 87;
70     enum IPPORT_SUPDUP  = 95;
71 
72     enum IPPORT_EXECSERVER = 512;
73     enum IPPORT_LOGINSERVER = 513;
74     enum IPPORT_CMDSERVER = 514;
75     enum IPPORT_EFSSERVER = 520;
76 
77     enum IPPORT_BIFFUDP = 512;
78     enum IPPORT_WHOSERVER = 513;
79     enum IPPORT_ROUTESERVER = 520;
80 
81     enum IPPORT_RESERVED = 1024;
82 
83     enum IPPORT_USERRESERVED = 5000;
84 
85     extern(D) bool IN_CLASSA(in_addr_t i) pure @safe { return (i & 0x80000000) == 0; }
86     enum IN_CLASSA_NET    = 0xff000000;
87     enum IN_CLASSA_NSHIFT = 24;
88     enum IN_CLASSA_HOST   = 0xffffffff & ~IN_CLASSA_NET;
89     enum IN_CLASSA_MAX    = 128;
90 
91     extern(D) bool IN_CLASSB(in_addr_t i) pure @safe { return (i & 0xc0000000) == 0x80000000; }
92     enum IN_CLASSB_NET    = 0xffff0000;
93     enum IN_CLASSB_NSHIFT = 16;
94     enum IN_CLASSB_HOST   = 0xffffffff & ~IN_CLASSB_NET;
95     enum IN_CLASSB_MAX    = 65536;
96 
97     extern(D) bool IN_CLASSC(in_addr_t i) pure @safe { return (i & 0xe0000000) == 0xc0000000; }
98     enum IN_CLASSC_NET    = 0xffffff00;
99     enum IN_CLASSC_NSHIFT = 8;
100     enum IN_CLASSC_HOST   = 0xffffffff & ~IN_CLASSC_NET;
101 
102     extern(D) bool IN_CLASSD(in_addr_t i) pure @safe { return (i & 0xf0000000) == 0xe0000000; }
103     extern(D) bool IN_MULTICAST(in_addr_t i) { return IN_CLASSD(i); }
104 
105     extern(D) bool IN_EXPERIMENTAL(in_addr_t i) pure @safe { return (i & 0xe0000000) == 0xe0000000; }
106     extern(D) bool IN_BADCLASS(in_addr_t i) pure @safe { return (i & 0xf0000000) == 0xf0000000; }
107 
108     enum IN_LOOPBACKNET = 127;
109 
110     enum INADDR_UNSPEC_GROUP    = 0xe0000000;
111     enum INADDR_ALLHOSTS_GROUP  = 0xe0000001;
112     enum INADDR_ALLRTRS_GROUP   = 0xe0000002;
113     enum INADDR_MAX_LOCAL_GROUP = 0xe00000ff;
114 
115     enum IN6ADDR_ANY_INIT      = in6_addr.init;
116     enum IN6ADDR_LOOPBACK_INIT = in6_addr([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]);
117 
118     version (gnu_libc) static if (_DEFAULT_SOURCE)
119     {
120         struct ip_mreq
121         {
122             in_addr imr_multiaddr;
123             in_addr imr_interface;
124         }
125 
126         struct ip_mreq_source
127         {
128             in_addr imr_multiaddr;
129             in_addr imr_interface;
130             in_addr imr_sourceaddr;
131         }
132 
133         struct group_req
134         {
135             uint gr_interface;
136             sockaddr_storage gr_group;
137         }
138 
139         struct group_source_req
140         {
141             uint gsr_interface;
142             sockaddr_storage gsr_group;
143             sockaddr_storage gsr_source;
144         }
145 
146         struct ip_msfilter
147         {
148             in_addr imsf_multiaddr;
149             in_addr imsf_interface;
150             uint imsf_fmode;
151             uint imsf_numsrc;
152             in_addr[1] imsf_slist;
153         }
154 
155         extern(D) size_t IP_MSFILTER_SIZE(int numsrc)
156         {
157             return ip_msfilter.sizeof - in_addr.sizeof + numsrc * in_addr.sizeof;
158         }
159 
160         struct group_filter
161         {
162             uint gf_interface;
163             sockaddr_storage gf_group;
164             uint gf_fmode;
165             uint gf_numsrc;
166             sockaddr_storage[1] gf_slist;
167         }
168 
169         extern(D) size_t GROUP_FILTER_SIZE(int numsrc) pure @safe
170         {
171             return group_filter.sizeof - sockaddr_storage.sizeof + numsrc * sockaddr_storage.sizeof;
172         }
173     }
174 
175     extern(D) bool IN6_ARE_ADDR_EQUAL(in6_addr* a, in6_addr* b) pure @safe { return *a == *b; }
176 
177     version (gnu_libc) static if (_DEFAULT_SOURCE)
178     {
179         int bindresvport(int __sockfd, sockaddr_in* __sock_in);
180         int bindresvport6(int __sockfd, sockaddr_in6* _);
181     }
182 
183     version (gnu_libc) static if (_GNU_SOURCE)
184     {
185         struct in6_pktinfo
186         {
187             in6_addr ipi6_addr;
188             uint ipi6_ifindex;
189         }
190 
191         struct ip6_mtuinfo
192         {
193             sockaddr_in6 ip6m_addr;
194             uint ip6m_mtu;
195         }
196 
197         int inet6_opt_init(void* __extbuf, socklen_t __extlen);
198         int inet6_opt_append(void* __extbuf, socklen_t __extlen, int __offset,
199                              ubyte __type, socklen_t __len, ubyte __align, void** __databufp);
200         int inet6_opt_finish(void* __extbuf, socklen_t __extlen, int __offset);
201         int inet6_opt_set_val(void* __databuf, int __offset, void* __val, socklen_t __vallen);
202         int inet6_opt_next(void* __extbuf, socklen_t __extlen, int __offset,
203                            ubyte* __typep, socklen_t* __lenp, void** __databufp);
204         int inet6_opt_find(void* __extbuf, socklen_t __extlen, int __offset,
205                            ubyte __type, socklen_t* __lenp, void** __databufp);
206         int inet6_opt_get_val(void* __databuf, int __offset, void* __val, socklen_t __vallen);
207 
208         socklen_t inet6_rth_space(int __type, int __segments);
209         void* inet6_rth_init(void* __bp, socklen_t __bp_len, int __type, int __segments);
210         int inet6_rth_add(void* __bp, const in6_addr* __addr);
211         int inet6_rth_reverse(const void* __in, void* __out);
212         int inet6_rth_segments(const void* __bp);
213         in6_addr* inet6_rth_getaddr(const void* __bp, int __index);
214 
215         int getipv4sourcefilter(int __s, in_addr __interface_addr, in_addr __group,
216                                 uint* __fmode, uint* __numsrc, in_addr* __slist);
217 
218         int setipv4sourcefilter(int __s, in_addr __interface_addr, in_addr __group,
219                                 uint __fmode, uint __numsrc, const in_addr* __slist);
220 
221 
222         int getsourcefilter(int __s, uint __interface_addr, const sockaddr* __group,
223                             socklen_t __grouplen, uint* __fmode, uint* __numsrc,
224                             sockaddr_storage* __slist);
225 
226         int setsourcefilter(int __s, uint __interface_addr, const sockaddr* __group,
227                             socklen_t __grouplen, uint __fmode, uint __numsrc,
228                             const sockaddr_storage* __slist);
229     }
230 
231     // =============================================================================
232     // What follows is from bits/in.h, but since bits/in.h specifically says that it
233     // should only be #included by #including netinet/in.h, it makes more sense to
234     // put them in here so that the way they're imported corresponds with the
235     // correct way of #including them in C/C++.
236     // =============================================================================
237 
238     enum IP_OPTIONS  = 4;
239     enum IP_HDRINCL  = 3;
240     enum IP_TOS      = 1;
241     enum IP_TTL      = 2;
242     enum IP_RECVOPTS = 6;
243 
244     enum IP_RECVRETOPTS            = IP_RETOPTS;
245     enum IP_RETOPTS                = 7;
246     enum IP_MULTICAST_IF           = 32;
247     enum IP_MULTICAST_TTL          = 33;
248     enum IP_MULTICAST_LOOP         = 34;
249     enum IP_ADD_MEMBERSHIP         = 35;
250     enum IP_DROP_MEMBERSHIP        = 36;
251     enum IP_UNBLOCK_SOURCE         = 37;
252     enum IP_BLOCK_SOURCE           = 38;
253     enum IP_ADD_SOURCE_MEMBERSHIP  = 39;
254     enum IP_DROP_SOURCE_MEMBERSHIP = 40;
255     enum IP_MSFILTER               = 41;
256 
257     version (gnu_libc) static if (_DEFAULT_SOURCE)
258     {
259         enum MCAST_JOIN_GROUP         = 42;
260         enum MCAST_BLOCK_SOURCE       = 43;
261         enum MCAST_UNBLOCK_SOURCE     = 44;
262         enum MCAST_LEAVE_GROUP        = 45;
263         enum MCAST_JOIN_SOURCE_GROUP  = 46;
264         enum MCAST_LEAVE_SOURCE_GROUP = 47;
265         enum MCAST_MSFILTER           = 48;
266         enum IP_MULTICAST_ALL         = 49;
267         enum IP_UNICAST_IF            = 50;
268 
269         enum MCAST_EXCLUDE = 0;
270         enum MCAST_INCLUDE = 1;
271     }
272 
273     enum IP_ROUTER_ALERT  = 5;
274     enum IP_PKTINFO       = 8;
275     enum IP_PKTOPTIONS    = 9;
276     enum IP_PMTUDISC      = 10;
277     enum IP_MTU_DISCOVER  = 10;
278     enum IP_RECVERR       = 11;
279     enum IP_RECVTTL       = 12;
280     enum IP_RECVTOS       = 13;
281     enum IP_MTU           = 14;
282     enum IP_FREEBIND      = 15;
283     enum IP_IPSEC_POLICY  = 16;
284     enum IP_XFRM_POLICY   = 17;
285     enum IP_PASSSEC       = 18;
286     enum IP_TRANSPARENT   = 19;
287     enum IP_MULTICAST_ALL = 49;
288 
289     enum IP_ORIGDSTADDR     = 20;
290     enum IP_RECVORIGDSTADDR = IP_ORIGDSTADDR;
291 
292     enum IP_MINTTL               = 21;
293     enum IP_NODEFRAG             = 22;
294     enum IP_CHECKSUM             = 23;
295     enum IP_BIND_ADDRESS_NO_PORT = 24;
296 
297     enum IP_PMTUDISC_DONT      = 0;
298     enum IP_PMTUDISC_WANT      = 1;
299     enum IP_PMTUDISC_DO        = 2;
300     enum IP_PMTUDISC_PROBE     = 3;
301     enum IP_PMTUDISC_INTERFACE = 4;
302     enum IP_PMTUDISC_OMIT      = 5;
303 
304     enum SOL_IP = 0;
305 
306     enum IP_DEFAULT_MULTICAST_TTL  = 1;
307     enum IP_DEFAULT_MULTICAST_LOOP = 1;
308     enum IP_MAX_MEMBERSHIPS        = 20;
309 
310     version (gnu_libc) static if (_DEFAULT_SOURCE)
311     {
312         struct ip_opts
313         {
314             in_addr ip_dst;
315             char[40] ip_opts = 0;
316         }
317 
318         struct ip_mreqn
319         {
320             in_addr imr_multiaddr;
321             in_addr imr_address;
322             int imr_ifindex;
323         }
324 
325         struct in_pktinfo
326         {
327             int ipi_ifindex;
328             in_addr ipi_spec_dst;
329             in_addr ipi_addr;
330         }
331     }
332 
333     enum IPV6_ADDRFORM       = 1;
334     enum IPV6_2292PKTINFO    = 2;
335     enum IPV6_2292HOPOPTS    = 3;
336     enum IPV6_2292DSTOPTS    = 4;
337     enum IPV6_2292RTHDR      = 5;
338     enum IPV6_2292PKTOPTIONS = 6;
339     enum IPV6_CHECKSUM       = 7;
340     enum IPV6_2292HOPLIMIT   = 8;
341 
342     enum IPV6_NEXTHOP        = 9;
343     enum IPV6_AUTHHDR        = 10;
344     enum IPV6_UNICAST_HOPS   = 16;
345     enum IPV6_MULTICAST_IF   = 17;
346     enum IPV6_MULTICAST_HOPS = 18;
347     enum IPV6_MULTICAST_LOOP = 19;
348     enum IPV6_JOIN_GROUP     = 20;
349     enum IPV6_LEAVE_GROUP    = 21;
350     enum IPV6_ROUTER_ALERT   = 22;
351     enum IPV6_MTU_DISCOVER   = 23;
352     enum IPV6_MTU            = 24;
353     enum IPV6_RECVERR        = 25;
354     enum IPV6_V6ONLY         = 26;
355     enum IPV6_JOIN_ANYCAST   = 27;
356     enum IPV6_LEAVE_ANYCAST  = 28;
357     enum IPV6_IPSEC_POLICY   = 34;
358     enum IPV6_XFRM_POLICY    = 35;
359     enum IPV6_HDRINCL        = 36;
360 
361     enum IPV6_RECVPKTINFO  = 49;
362     enum IPV6_PKTINFO      = 50;
363     enum IPV6_RECVHOPLIMIT = 51;
364     enum IPV6_HOPLIMIT     = 52;
365     enum IPV6_RECVHOPOPTS  = 53;
366     enum IPV6_HOPOPTS      = 54;
367     enum IPV6_RTHDRDSTOPTS = 55;
368     enum IPV6_RECVRTHDR    = 56;
369     enum IPV6_RTHDR        = 57;
370     enum IPV6_RECVDSTOPTS  = 58;
371     enum IPV6_DSTOPTS      = 59;
372     enum IPV6_RECVPATHMTU  = 60;
373     enum IPV6_PATHMTU      = 61;
374     enum IPV6_DONTFRAG     = 62;
375 
376     enum IPV6_RECVTCLASS = 66;
377     enum IPV6_TCLASS     = 67;
378 
379     enum IPV6_PMTUDISC_DONT      = 0;
380     enum IPV6_PMTUDISC_WANT      = 1;
381     enum IPV6_PMTUDISC_DO        = 2;
382     enum IPV6_PMTUDISC_PROBE     = 3;
383     enum IPV6_PMTUDISC_INTERFACE = 4;
384     enum IPV6_PMTUDISC_OMIT      = 5;
385 
386     enum SOL_IPV6   = 41;
387     enum SOL_ICMPV6 = 58;
388 
389     enum IPV6_RTHDR_LOOSE  = 0;
390     enum IPV6_RTHDR_STRICT = 1;
391 
392     enum IPV6_RTHDR_TYPE_0 = 0;
393 }