in.h
001:
002:
003:
004:
005:
006:
007:
008:
009:
010:
011:
012:
013:
014:
015:
016:
017:
018:
019:
020: #ifndef _NETINET_IN_H
021: #define _NETINET_IN_H 1
022:
023: #include <features.h>
024: #include <stdint.h>
025: #include <sys/socket.h>
026: #include <bits/types.h>
027:
028:
029: __BEGIN_DECLS
030:
031:
032: enum
033: {
034: IPPROTO_IP = 0,
035: #define IPPROTO_IP IPPROTO_IP
036: IPPROTO_HOPOPTS = 0,
037: #define IPPROTO_HOPOPTS IPPROTO_HOPOPTS
038: IPPROTO_ICMP = 1,
039: #define IPPROTO_ICMP IPPROTO_ICMP
040: IPPROTO_IGMP = 2,
041: #define IPPROTO_IGMP IPPROTO_IGMP
042: IPPROTO_IPIP = 4,
043: #define IPPROTO_IPIP IPPROTO_IPIP
044: IPPROTO_TCP = 6,
045: #define IPPROTO_TCP IPPROTO_TCP
046: IPPROTO_EGP = 8,
047: #define IPPROTO_EGP IPPROTO_EGP
048: IPPROTO_PUP = 12,
049: #define IPPROTO_PUP IPPROTO_PUP
050: IPPROTO_UDP = 17,
051: #define IPPROTO_UDP IPPROTO_UDP
052: IPPROTO_IDP = 22,
053: #define IPPROTO_IDP IPPROTO_IDP
054: IPPROTO_TP = 29,
055: #define IPPROTO_TP IPPROTO_TP
056: IPPROTO_DCCP = 33,
057: #define IPPROTO_DCCP IPPROTO_DCCP
058: IPPROTO_IPV6 = 41,
059: #define IPPROTO_IPV6 IPPROTO_IPV6
060: IPPROTO_ROUTING = 43,
061: #define IPPROTO_ROUTING IPPROTO_ROUTING
062: IPPROTO_FRAGMENT = 44,
063: #define IPPROTO_FRAGMENT IPPROTO_FRAGMENT
064: IPPROTO_RSVP = 46,
065: #define IPPROTO_RSVP IPPROTO_RSVP
066: IPPROTO_GRE = 47,
067: #define IPPROTO_GRE IPPROTO_GRE
068: IPPROTO_ESP = 50,
069: #define IPPROTO_ESP IPPROTO_ESP
070: IPPROTO_AH = 51,
071: #define IPPROTO_AH IPPROTO_AH
072: IPPROTO_ICMPV6 = 58,
073: #define IPPROTO_ICMPV6 IPPROTO_ICMPV6
074: IPPROTO_NONE = 59,
075: #define IPPROTO_NONE IPPROTO_NONE
076: IPPROTO_DSTOPTS = 60,
077: #define IPPROTO_DSTOPTS IPPROTO_DSTOPTS
078: IPPROTO_MTP = 92,
079: #define IPPROTO_MTP IPPROTO_MTP
080: IPPROTO_ENCAP = 98,
081: #define IPPROTO_ENCAP IPPROTO_ENCAP
082: IPPROTO_PIM = 103,
083: #define IPPROTO_PIM IPPROTO_PIM
084: IPPROTO_COMP = 108,
085: #define IPPROTO_COMP IPPROTO_COMP
086: IPPROTO_SCTP = 132,
087: #define IPPROTO_SCTP IPPROTO_SCTP
088: IPPROTO_UDPLITE = 136,
089: #define IPPROTO_UDPLITE IPPROTO_UDPLITE
090: IPPROTO_RAW = 255,
091: #define IPPROTO_RAW IPPROTO_RAW
092: IPPROTO_MAX
093: };
094:
095:
096:
097: typedef uint16_t in_port_t;
098:
099:
100: enum
101: {
102: IPPORT_ECHO = 7,
103: IPPORT_DISCARD = 9,
104: IPPORT_SYSTAT = 11,
105: IPPORT_DAYTIME = 13,
106: IPPORT_NETSTAT = 15,
107: IPPORT_FTP = 21,
108: IPPORT_TELNET = 23,
109: IPPORT_SMTP = 25,
110: IPPORT_TIMESERVER = 37,
111: IPPORT_NAMESERVER = 42,
112: IPPORT_WHOIS = 43,
113: IPPORT_MTP = 57,
114:
115: IPPORT_TFTP = 69,
116: IPPORT_RJE = 77,
117: IPPORT_FINGER = 79,
118: IPPORT_TTYLINK = 87,
119: IPPORT_SUPDUP = 95,
120:
121:
122: IPPORT_EXECSERVER = 512,
123: IPPORT_LOGINSERVER = 513,
124: IPPORT_CMDSERVER = 514,
125: IPPORT_EFSSERVER = 520,
126:
127:
128: IPPORT_BIFFUDP = 512,
129: IPPORT_WHOSERVER = 513,
130: IPPORT_ROUTESERVER = 520,
131:
132:
133: IPPORT_RESERVED = 1024,
134:
135:
136: IPPORT_USERRESERVED = 5000
137: };
138:
139:
140:
141: typedef uint32_t in_addr_t;
142: struct in_addr
143: {
144: in_addr_t s_addr;
145: };
146:
147:
148:
149:
150:
151:
152:
153: #define IN_CLASSA(a) ((((in_addr_t)(a)) & 0x80000000) == 0)
154: #define IN_CLASSA_NET 0xff000000
155: #define IN_CLASSA_NSHIFT 24
156: #define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET)
157: #define IN_CLASSA_MAX 128
158:
159: #define IN_CLASSB(a) ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000)
160: #define IN_CLASSB_NET 0xffff0000
161: #define IN_CLASSB_NSHIFT 16
162: #define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET)
163: #define IN_CLASSB_MAX 65536
164:
165: #define IN_CLASSC(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000)
166: #define IN_CLASSC_NET 0xffffff00
167: #define IN_CLASSC_NSHIFT 8
168: #define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET)
169:
170: #define IN_CLASSD(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000)
171: #define IN_MULTICAST(a) IN_CLASSD(a)
172:
173: #define IN_EXPERIMENTAL(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000)
174: #define IN_BADCLASS(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000)
175:
176:
177: #define INADDR_ANY ((in_addr_t) 0x00000000)
178:
179: #define INADDR_BROADCAST ((in_addr_t) 0xffffffff)
180:
181: #define INADDR_NONE ((in_addr_t) 0xffffffff)
182:
183:
184: #define IN_LOOPBACKNET 127
185:
186: #ifndef INADDR_LOOPBACK
187: # define INADDR_LOOPBACK ((in_addr_t) 0x7f000001)
188: #endif
189:
190:
191: #define INADDR_UNSPEC_GROUP ((in_addr_t) 0xe0000000)
192: #define INADDR_ALLHOSTS_GROUP ((in_addr_t) 0xe0000001)
193: #define INADDR_ALLRTRS_GROUP ((in_addr_t) 0xe0000002)
194: #define INADDR_MAX_LOCAL_GROUP ((in_addr_t) 0xe00000ff)
195:
196:
197:
198: struct in6_addr
199: {
200: union
201: {
202: uint8_t __u6_addr8[16];
203: #if defined __USE_MISC || defined __USE_GNU
204: uint16_t __u6_addr16[8];
205: uint32_t __u6_addr32[4];
206: #endif
207: } __in6_u;
208: #define s6_addr __in6_u.__u6_addr8
209: #if defined __USE_MISC || defined __USE_GNU
210: # define s6_addr16 __in6_u.__u6_addr16
211: # define s6_addr32 __in6_u.__u6_addr32
212: #endif
213: };
214:
215: extern const struct in6_addr in6addr_any;
216: extern const struct in6_addr in6addr_loopback;
217: #define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
218: #define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
219:
220: #define INET_ADDRSTRLEN 16
221: #define INET6_ADDRSTRLEN 46
222:
223:
224:
225: struct sockaddr_in
226: {
227: __SOCKADDR_COMMON (sin_);
228: in_port_t sin_port;
229: struct in_addr sin_addr;
230:
231:
232: unsigned char sin_zero[sizeof (struct sockaddr) -
233: __SOCKADDR_COMMON_SIZE -
234: sizeof (in_port_t) -
235: sizeof (struct in_addr)];
236: };
237:
238:
239: struct sockaddr_in6
240: {
241: __SOCKADDR_COMMON (sin6_);
242: in_port_t sin6_port;
243: uint32_t sin6_flowinfo;
244: struct in6_addr sin6_addr;
245: uint32_t sin6_scope_id;
246: };
247:
248:
249: #if defined __USE_MISC || defined __USE_GNU
250:
251: struct ip_mreq
252: {
253:
254: struct in_addr imr_multiaddr;
255:
256:
257: struct in_addr imr_interface;
258: };
259:
260: struct ip_mreq_source
261: {
262:
263: struct in_addr imr_multiaddr;
264:
265:
266: struct in_addr imr_interface;
267:
268:
269: struct in_addr imr_sourceaddr;
270: };
271: #endif
272:
273:
274:
275: struct ipv6_mreq
276: {
277:
278: struct in6_addr ipv6mr_multiaddr;
279:
280:
281: unsigned int ipv6mr_interface;
282: };
283:
284:
285: #if defined __USE_MISC || defined __USE_GNU
286:
287: struct group_req
288: {
289:
290: uint32_t gr_interface;
291:
292:
293: struct sockaddr_storage gr_group;
294: };
295:
296: struct group_source_req
297: {
298:
299: uint32_t gsr_interface;
300:
301:
302: struct sockaddr_storage gsr_group;
303:
304:
305: struct sockaddr_storage gsr_source;
306: };
307:
308:
309:
310: struct ip_msfilter
311: {
312:
313: struct in_addr imsf_multiaddr;
314:
315:
316: struct in_addr imsf_interface;
317:
318:
319: uint32_t imsf_fmode;
320:
321:
322: uint32_t imsf_numsrc;
323:
324: struct in_addr imsf_slist[1];
325: };
326:
327: #define IP_MSFILTER_SIZE(numsrc) (sizeof (struct ip_msfilter) \
328: - sizeof (struct in_addr) \
329: + (numsrc) * sizeof (struct in_addr))
330:
331: struct group_filter
332: {
333:
334: uint32_t gf_interface;
335:
336:
337: struct sockaddr_storage gf_group;
338:
339:
340: uint32_t gf_fmode;
341:
342:
343: uint32_t gf_numsrc;
344:
345: struct sockaddr_storage gf_slist[1];
346: };
347:
348: #define GROUP_FILTER_SIZE(numsrc) (sizeof (struct group_filter) \
349: - sizeof (struct sockaddr_storage) \
350: + ((numsrc) \
351: * sizeof (struct sockaddr_storage)))
352: #endif
353:
354:
355:
356: #include <bits/in.h>
357:
358:
359:
360:
361:
362:
363:
364:
365: extern uint32_t ntohl (uint32_t __netlong) __THROW __attribute__ ((__const__));
366: extern uint16_t ntohs (uint16_t __netshort)
367: __THROW __attribute__ ((__const__));
368: extern uint32_t htonl (uint32_t __hostlong)
369: __THROW __attribute__ ((__const__));
370: extern uint16_t htons (uint16_t __hostshort)
371: __THROW __attribute__ ((__const__));
372:
373: #include <endian.h>
374:
375:
376: #include <bits/byteswap.h>
377:
378: #ifdef __OPTIMIZE__
379:
380:
381:
382: # if __BYTE_ORDER == __BIG_ENDIAN
383:
384:
385: # define ntohl(x) (x)
386: # define ntohs(x) (x)
387: # define htonl(x) (x)
388: # define htons(x) (x)
389: # else
390: # if __BYTE_ORDER == __LITTLE_ENDIAN
391: # define ntohl(x) __bswap_32 (x)
392: # define ntohs(x) __bswap_16 (x)
393: # define htonl(x) __bswap_32 (x)
394: # define htons(x) __bswap_16 (x)
395: # endif
396: # endif
397: #endif
398:
399: #ifdef __GNUC__
400: # define IN6_IS_ADDR_UNSPECIFIED(a) \
401: (__extension__ \
402: ({ __const struct in6_addr *__a = (__const struct in6_addr *) (a); \
403: __a->s6_addr32[0] == 0 \
404: && __a->s6_addr32[1] == 0 \
405: && __a->s6_addr32[2] == 0 \
406: && __a->s6_addr32[3] == 0; }))
407:
408: # define IN6_IS_ADDR_LOOPBACK(a) \
409: (__extension__ \
410: ({ __const struct in6_addr *__a = (__const struct in6_addr *) (a); \
411: __a->s6_addr32[0] == 0 \
412: && __a->s6_addr32[1] == 0 \
413: && __a->s6_addr32[2] == 0 \
414: && __a->s6_addr32[3] == htonl (1); }))
415:
416: # define IN6_IS_ADDR_LINKLOCAL(a) \
417: (__extension__ \
418: ({ __const struct in6_addr *__a = (__const struct in6_addr *) (a); \
419: (__a->s6_addr32[0] & htonl (0xffc00000)) == htonl (0xfe800000); }))
420:
421: # define IN6_IS_ADDR_SITELOCAL(a) \
422: (__extension__ \
423: ({ __const struct in6_addr *__a = (__const struct in6_addr *) (a); \
424: (__a->s6_addr32[0] & htonl (0xffc00000)) == htonl (0xfec00000); }))
425:
426: # define IN6_IS_ADDR_V4MAPPED(a) \
427: (__extension__ \
428: ({ __const struct in6_addr *__a = (__const struct in6_addr *) (a); \
429: __a->s6_addr32[0] == 0 \
430: && __a->s6_addr32[1] == 0 \
431: && __a->s6_addr32[2] == htonl (0xffff); }))
432:
433: # define IN6_IS_ADDR_V4COMPAT(a) \
434: (__extension__ \
435: ({ __const struct in6_addr *__a = (__const struct in6_addr *) (a); \
436: __a->s6_addr32[0] == 0 \
437: && __a->s6_addr32[1] == 0 \
438: && __a->s6_addr32[2] == 0 \
439: && ntohl (__a->s6_addr32[3]) > 1; }))
440:
441: # define IN6_ARE_ADDR_EQUAL(a,b) \
442: (__extension__ \
443: ({ __const struct in6_addr *__a = (__const struct in6_addr *) (a); \
444: __const struct in6_addr *__b = (__const struct in6_addr *) (b); \
445: __a->s6_addr32[0] == __b->s6_addr32[0] \
446: && __a->s6_addr32[1] == __b->s6_addr32[1] \
447: && __a->s6_addr32[2] == __b->s6_addr32[2] \
448: && __a->s6_addr32[3] == __b->s6_addr32[3]; }))
449: #else
450: # define IN6_IS_ADDR_UNSPECIFIED(a) \
451: (((__const uint32_t *) (a))[0] == 0 \
452: && ((__const uint32_t *) (a))[1] == 0 \
453: && ((__const uint32_t *) (a))[2] == 0 \
454: && ((__const uint32_t *) (a))[3] == 0)
455:
456: # define IN6_IS_ADDR_LOOPBACK(a) \
457: (((__const uint32_t *) (a))[0] == 0 \
458: && ((__const uint32_t *) (a))[1] == 0 \
459: && ((__const uint32_t *) (a))[2] == 0 \
460: && ((__const uint32_t *) (a))[3] == htonl (1))
461:
462: # define IN6_IS_ADDR_LINKLOCAL(a) \
463: ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
464: == htonl (0xfe800000))
465:
466: # define IN6_IS_ADDR_SITELOCAL(a) \
467: ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
468: == htonl (0xfec00000))
469:
470: # define IN6_IS_ADDR_V4MAPPED(a) \
471: ((((__const uint32_t *) (a))[0] == 0) \
472: && (((__const uint32_t *) (a))[1] == 0) \
473: && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
474:
475: # define IN6_IS_ADDR_V4COMPAT(a) \
476: ((((__const uint32_t *) (a))[0] == 0) \
477: && (((__const uint32_t *) (a))[1] == 0) \
478: && (((__const uint32_t *) (a))[2] == 0) \
479: && (ntohl (((__const uint32_t *) (a))[3]) > 1))
480:
481: # define IN6_ARE_ADDR_EQUAL(a,b) \
482: ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0]) \
483: && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1]) \
484: && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2]) \
485: && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
486: #endif
487:
488: #define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
489:
490: #if defined __USE_MISC || defined __USE_GNU
491:
492: extern int bindresvport (int __sockfd, struct sockaddr_in *__sock_in) __THROW;
493:
494:
495: extern int bindresvport6 (int __sockfd, struct sockaddr_in6 *__sock_in)
496: __THROW;
497: #endif
498:
499:
500: #define IN6_IS_ADDR_MC_NODELOCAL(a) \
501: (IN6_IS_ADDR_MULTICAST(a) \
502: && ((((__const uint8_t *) (a))[1] & 0xf) == 0x1))
503:
504: #define IN6_IS_ADDR_MC_LINKLOCAL(a) \
505: (IN6_IS_ADDR_MULTICAST(a) \
506: && ((((__const uint8_t *) (a))[1] & 0xf) == 0x2))
507:
508: #define IN6_IS_ADDR_MC_SITELOCAL(a) \
509: (IN6_IS_ADDR_MULTICAST(a) \
510: && ((((__const uint8_t *) (a))[1] & 0xf) == 0x5))
511:
512: #define IN6_IS_ADDR_MC_ORGLOCAL(a) \
513: (IN6_IS_ADDR_MULTICAST(a) \
514: && ((((__const uint8_t *) (a))[1] & 0xf) == 0x8))
515:
516: #define IN6_IS_ADDR_MC_GLOBAL(a) \
517: (IN6_IS_ADDR_MULTICAST(a) \
518: && ((((__const uint8_t *) (a))[1] & 0xf) == 0xe))
519:
520:
521: #ifdef __USE_GNU
522:
523: struct in6_pktinfo
524: {
525: struct in6_addr ipi6_addr;
526: unsigned int ipi6_ifindex;
527: };
528:
529:
530: struct ip6_mtuinfo
531: {
532: struct sockaddr_in6 ip6m_addr;
533: uint32_t ip6m_mtu;
534: };
535:
536:
537:
538: extern int inet6_option_space (int __nbytes)
539: __THROW __attribute_deprecated__;
540: extern int inet6_option_init (void *__bp, struct cmsghdr **__cmsgp,
541: int __type) __THROW __attribute_deprecated__;
542: extern int inet6_option_append (struct cmsghdr *__cmsg,
543: __const uint8_t *__typep, int __multx,
544: int __plusy) __THROW __attribute_deprecated__;
545: extern uint8_t *inet6_option_alloc (struct cmsghdr *__cmsg, int __datalen,
546: int __multx, int __plusy)
547: __THROW __attribute_deprecated__;
548: extern int inet6_option_next (__const struct cmsghdr *__cmsg,
549: uint8_t **__tptrp)
550: __THROW __attribute_deprecated__;
551: extern int inet6_option_find (__const struct cmsghdr *__cmsg,
552: uint8_t **__tptrp, int __type)
553: __THROW __attribute_deprecated__;
554:
555:
556:
557: extern int inet6_opt_init (void *__extbuf, socklen_t __extlen) __THROW;
558: extern int inet6_opt_append (void *__extbuf, socklen_t __extlen, int __offset,
559: uint8_t __type, socklen_t __len, uint8_t __align,
560: void **__databufp) __THROW;
561: extern int inet6_opt_finish (void *__extbuf, socklen_t __extlen, int __offset)
562: __THROW;
563: extern int inet6_opt_set_val (void *__databuf, int __offset, void *__val,
564: socklen_t __vallen) __THROW;
565: extern int inet6_opt_next (void *__extbuf, socklen_t __extlen, int __offset,
566: uint8_t *__typep, socklen_t *__lenp,
567: void **__databufp) __THROW;
568: extern int inet6_opt_find (void *__extbuf, socklen_t __extlen, int __offset,
569: uint8_t __type, socklen_t *__lenp,
570: void **__databufp) __THROW;
571: extern int inet6_opt_get_val (void *__databuf, int __offset, void *__val,
572: socklen_t __vallen) __THROW;
573:
574:
575:
576: extern socklen_t inet6_rth_space (int __type, int __segments) __THROW;
577: extern void *inet6_rth_init (void *__bp, socklen_t __bp_len, int __type,
578: int __segments) __THROW;
579: extern int inet6_rth_add (void *__bp, __const struct in6_addr *__addr) __THROW;
580: extern int inet6_rth_reverse (__const void *__in, void *__out) __THROW;
581: extern int inet6_rth_segments (__const void *__bp) __THROW;
582: extern struct in6_addr *inet6_rth_getaddr (__const void *__bp, int __index)
583: __THROW;
584:
585:
586:
587:
588:
589: extern int getipv4sourcefilter (int __s, struct in_addr __interface_addr,
590: struct in_addr __group, uint32_t *__fmode,
591: uint32_t *__numsrc, struct in_addr *__slist)
592: __THROW;
593:
594:
595: extern int setipv4sourcefilter (int __s, struct in_addr __interface_addr,
596: struct in_addr __group, uint32_t __fmode,
597: uint32_t __numsrc,
598: __const struct in_addr *__slist)
599: __THROW;
600:
601:
602:
603: extern int getsourcefilter (int __s, uint32_t __interface_addr,
604: __const struct sockaddr *__group,
605: socklen_t __grouplen, uint32_t *__fmode,
606: uint32_t *__numsrc,
607: struct sockaddr_storage *__slist) __THROW;
608:
609:
610: extern int setsourcefilter (int __s, uint32_t __interface_addr,
611: __const struct sockaddr *__group,
612: socklen_t __grouplen, uint32_t __fmode,
613: uint32_t __numsrc,
614: __const struct sockaddr_storage *__slist) __THROW;
615: #endif
616:
617: __END_DECLS
618:
619: #endif
620:
© Andrew Scott 2006 -
2024,
All Rights Reserved