Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. #ifndef _NETINET_IN_H
  2. #define _NETINET_IN_H
  3.  
  4. #include <sys/types.h>
  5. #include <sys/socket.h>
  6. #include <endian.h>
  7.  
  8. __BEGIN_DECLS
  9.  
  10. /* Standard well-defined IP protocols.  */
  11. enum {
  12.   IPPROTO_IP = 0,               /* Dummy protocol for TCP               */
  13. #define IPPROTO_IP IPPROTO_IP
  14.   IPPROTO_ICMP = 1,             /* Internet Control Message Protocol    */
  15. #define IPPROTO_ICMP IPPROTO_ICMP
  16.   IPPROTO_IGMP = 2,             /* Internet Group Management Protocol   */
  17. #define IPPROTO_IGMP IPPROTO_IGMP
  18.   IPPROTO_IPIP = 4,             /* IPIP tunnels (older KA9Q tunnels use 94) */
  19. #define IPPROTO_IPIP IPPROTO_IPIP
  20.   IPPROTO_TCP = 6,              /* Transmission Control Protocol        */
  21. #define IPPROTO_TCP IPPROTO_TCP
  22.   IPPROTO_EGP = 8,              /* Exterior Gateway Protocol            */
  23. #define IPPROTO_EGP IPPROTO_EGP
  24.   IPPROTO_PUP = 12,             /* PUP protocol                         */
  25. #define IPPROTO_PUP IPPROTO_PUP
  26.   IPPROTO_UDP = 17,             /* User Datagram Protocol               */
  27. #define IPPROTO_UDP IPPROTO_UDP
  28.   IPPROTO_IDP = 22,             /* XNS IDP protocol                     */
  29. #define IPPROTO_IDP IPPROTO_IDP
  30.   IPPROTO_RSVP = 46,            /* RSVP protocol                        */
  31. #define IPPROTO_RSVP IPPROTO_RSVP
  32.   IPPROTO_GRE = 47,             /* Cisco GRE tunnels (rfc 1701,1702)    */
  33. #define IPPROTO_GRE IPPROTO_GRE
  34.   IPPROTO_IPV6 = 41,            /* IPv6-in-IPv4 tunnelling              */
  35. #define IPPROTO_IPV6 IPPROTO_IPV6
  36.   IPPROTO_PIM    = 103,         /* Protocol Independent Multicast       */
  37. #define IPPROTO_PIM IPPROTO_PIM
  38.   IPPROTO_ESP = 50,            /* Encapsulation Security Payload protocol */
  39. #define IPPROTO_ESP IPPROTO_ESP
  40.   IPPROTO_AH = 51,             /* Authentication Header protocol       */
  41. #define IPPROTO_AH IPPROTO_AH
  42.   IPPROTO_COMP   = 108,                /* Compression Header protocol */
  43. #define IPPROTO_COMP IPPROTO_COMP
  44.   IPPROTO_RAW    = 255,         /* Raw IP packets                       */
  45. #define IPPROTO_RAW IPPROTO_RAW
  46.   IPPROTO_MAX
  47. };
  48.  
  49. #define IP_TOS          1
  50. #define IP_TTL          2
  51. #define IP_HDRINCL      3
  52. #define IP_OPTIONS      4
  53. #define IP_ROUTER_ALERT 5
  54. #define IP_RECVOPTS     6
  55. #define IP_RETOPTS      7
  56. #define IP_PKTINFO      8
  57. #define IP_PKTOPTIONS   9
  58. #define IP_MTU_DISCOVER 10
  59. #define IP_RECVERR      11
  60. #define IP_RECVTTL      12
  61. #define IP_RECVTOS      13
  62. #define IP_MTU          14
  63. #define IP_FREEBIND     15
  64.  
  65. /* BSD compatibility */
  66. #define IP_RECVRETOPTS  IP_RETOPTS
  67.  
  68. /* IP_MTU_DISCOVER values */
  69. #define IP_PMTUDISC_DONT                0       /* Never send DF frames */
  70. #define IP_PMTUDISC_WANT                1       /* Use per route hints  */
  71. #define IP_PMTUDISC_DO                  2       /* Always DF            */
  72.  
  73. #define IP_MULTICAST_IF                 32
  74. #define IP_MULTICAST_TTL                33
  75. #define IP_MULTICAST_LOOP               34
  76. #define IP_ADD_MEMBERSHIP               35
  77. #define IP_DROP_MEMBERSHIP              36
  78.  
  79. /* These need to appear somewhere around here */
  80. #define IP_DEFAULT_MULTICAST_TTL        1
  81. #define IP_DEFAULT_MULTICAST_LOOP       1
  82.  
  83. #define IN6ADDR_ANY_INIT {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}}
  84. #define IN6ADDR_LOOPBACK_INIT {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }}}
  85. extern const struct in6_addr in6addr_any;
  86. extern const struct in6_addr in6addr_loopback;
  87.  
  88. typedef uint16_t in_port_t;
  89. typedef uint32_t in_addr_t;
  90.  
  91. struct in_addr {
  92.   in_addr_t s_addr;
  93. };
  94.  
  95. struct ip_mreq {
  96.   struct in_addr imr_multiaddr; /* IP multicast address of group */
  97.   struct in_addr imr_interface; /* local IP address of interface */
  98. };
  99.  
  100. struct ip_mreqn {
  101.   struct in_addr        imr_multiaddr;          /* IP multicast address of group */
  102.   struct in_addr        imr_address;            /* local IP address of interface */
  103.   int                   imr_ifindex;            /* Interface index */
  104. };
  105.  
  106. struct in_pktinfo {
  107.   int                   ipi_ifindex;
  108.   struct in_addr        ipi_spec_dst;
  109.   struct in_addr        ipi_addr;
  110. };
  111.  
  112. /* Structure describing an Internet (IP) socket address. */
  113. #define __SOCK_SIZE__   16              /* sizeof(struct sockaddr)      */
  114. struct sockaddr_in {
  115.   sa_family_t           sin_family;     /* Address family               */
  116.   in_port_t             sin_port;       /* Port number                  */
  117.   struct in_addr        sin_addr;       /* Internet address             */
  118.   /* Pad to size of `struct sockaddr'. */
  119.   unsigned char         sin_zero[__SOCK_SIZE__ - sizeof(short int) -
  120.                         sizeof(unsigned short int) - sizeof(struct in_addr)];
  121. };
  122.  
  123.  
  124. /*
  125.  * Definitions of the bits in an Internet address integer.
  126.  * On subnets, host and network parts are found according
  127.  * to the subnet mask, not these masks.
  128.  */
  129. #define IN_CLASSA(a)            ((((long int) (a)) & 0x80000000) == 0)
  130. #define IN_CLASSA_NET           0xff000000
  131. #define IN_CLASSA_NSHIFT        24
  132. #define IN_CLASSA_HOST          (0xffffffff & ~IN_CLASSA_NET)
  133. #define IN_CLASSA_MAX           128
  134.  
  135. #define IN_CLASSB(a)            ((((long int) (a)) & 0xc0000000) == 0x80000000)
  136. #define IN_CLASSB_NET           0xffff0000
  137. #define IN_CLASSB_NSHIFT        16
  138. #define IN_CLASSB_HOST          (0xffffffff & ~IN_CLASSB_NET)
  139. #define IN_CLASSB_MAX           65536
  140.  
  141. #define IN_CLASSC(a)            ((((long int) (a)) & 0xe0000000) == 0xc0000000)
  142. #define IN_CLASSC_NET           0xffffff00
  143. #define IN_CLASSC_NSHIFT        8
  144. #define IN_CLASSC_HOST          (0xffffffff & ~IN_CLASSC_NET)
  145.  
  146. #define IN_CLASSD(a)            ((((long int) (a)) & 0xf0000000) == 0xe0000000)
  147. #define IN_MULTICAST(a)         IN_CLASSD(a)
  148. #define IN_MULTICAST_NET        0xF0000000
  149.  
  150. #define IN_EXPERIMENTAL(a)      ((((long int) (a)) & 0xf0000000) == 0xf0000000)
  151. #define IN_BADCLASS(a)          IN_EXPERIMENTAL((a))
  152.  
  153. /* Address to accept any incoming messages. */
  154. #define INADDR_ANY              ((unsigned long int) 0x00000000)
  155.  
  156. /* Address to send to all hosts. */
  157. #define INADDR_BROADCAST        ((unsigned long int) 0xffffffff)
  158.  
  159. /* Address indicating an error return. */
  160. #define INADDR_NONE             ((unsigned long int) 0xffffffff)
  161.  
  162. /* Network number for local host loopback. */
  163. #define IN_LOOPBACKNET          127
  164.  
  165. /* Address to loopback in software to local host.  */
  166. #define INADDR_LOOPBACK         0x7f000001      /* 127.0.0.1   */
  167. #define IN_LOOPBACK(a)          ((((long int) (a)) & 0xff000000) == 0x7f000000)
  168.  
  169. /* Defines for Multicast INADDR */
  170. #define INADDR_UNSPEC_GROUP     0xe0000000U     /* 224.0.0.0   */
  171. #define INADDR_ALLHOSTS_GROUP   0xe0000001U     /* 224.0.0.1   */
  172. #define INADDR_ALLRTRS_GROUP    0xe0000002U     /* 224.0.0.2 */
  173. #define INADDR_MAX_LOCAL_GROUP  0xe00000ffU     /* 224.0.0.255 */
  174.  
  175. struct in6_addr {
  176.   union {
  177.     uint8_t             u6_addr8[16];
  178.     uint16_t            u6_addr16[8];
  179.     uint32_t            u6_addr32[4];
  180.   } in6_u;
  181. #define s6_addr                 in6_u.u6_addr8
  182. #define s6_addr16               in6_u.u6_addr16
  183. #define s6_addr32               in6_u.u6_addr32
  184. };
  185.  
  186. struct sockaddr_in6 {
  187.   unsigned short int    sin6_family;    /* AF_INET6 */
  188.   uint16_t              sin6_port;      /* Transport layer port # */
  189.   uint32_t              sin6_flowinfo;  /* IPv6 flow information */
  190.   struct in6_addr       sin6_addr;      /* IPv6 address */
  191.   uint32_t              sin6_scope_id;  /* scope id (new in RFC2553) */
  192. };
  193.  
  194. struct sockaddr_in_pad {
  195.   sa_family_t           sin_family;     /* Address family               */
  196.   in_port_t             sin_port;       /* Port number                  */
  197.   struct in_addr        sin_addr;       /* Internet address             */
  198.   /* Pad to size of `struct sockaddr_in6'. */
  199.   unsigned char         sin_zero[sizeof(struct sockaddr_in6) - sizeof(short int) -
  200.                         sizeof(unsigned short int) - sizeof(struct in_addr)];
  201. };
  202.  
  203. struct ipv6_mreq {
  204.   /* IPv6 multicast address of group */
  205.   struct in6_addr ipv6mr_multiaddr;
  206.   /* local IPv6 address of interface */
  207.   int ipv6mr_interface;
  208. };
  209.  
  210. struct in6_flowlabel_req {
  211.   struct in6_addr       flr_dst;
  212.   uint32_t      flr_label;
  213.   uint8_t       flr_action;
  214.   uint8_t       flr_share;
  215.   uint16_t      flr_flags;
  216.   uint16_t      flr_expires;
  217.   uint16_t      flr_linger;
  218.   uint32_t      __flr_pad;
  219.   /* Options in format of IPV6_PKTOPTIONS */
  220. };
  221.  
  222. #define IPV6_FL_A_GET   0
  223. #define IPV6_FL_A_PUT   1
  224. #define IPV6_FL_A_RENEW 2
  225.  
  226. #define IPV6_FL_F_CREATE        1
  227. #define IPV6_FL_F_EXCL          2
  228.  
  229. #define IPV6_FL_S_NONE          0
  230. #define IPV6_FL_S_EXCL          1
  231. #define IPV6_FL_S_PROCESS       2
  232. #define IPV6_FL_S_USER          3
  233. #define IPV6_FL_S_ANY           255
  234.  
  235. #define IPV6_FLOWINFO_FLOWLABEL         0x000fffff
  236. #define IPV6_FLOWINFO_PRIORITY          0x0ff00000
  237.  
  238. /*
  239.  *      IPV6 extension headers
  240.  */
  241. #define IPPROTO_HOPOPTS         0       /* IPv6 hop-by-hop options      */
  242. #define IPPROTO_ROUTING         43      /* IPv6 routing header          */
  243. #define IPPROTO_FRAGMENT        44      /* IPv6 fragmentation header    */
  244. #define IPPROTO_ICMPV6          58      /* ICMPv6                       */
  245. #define IPPROTO_NONE            59      /* IPv6 no next header          */
  246. #define IPPROTO_DSTOPTS         60      /* IPv6 destination options     */
  247.  
  248. /* IPv6 TLV options. */
  249. #define IPV6_TLV_PAD0           0
  250. #define IPV6_TLV_PADN           1
  251. #define IPV6_TLV_ROUTERALERT    5
  252. #define IPV6_TLV_JUMBO          194
  253.  
  254. /* IPV6 socket options. */
  255. #define IPV6_ADDRFORM           1
  256. #define IPV6_PKTINFO            2
  257. #define IPV6_HOPOPTS            3
  258. #define IPV6_DSTOPTS            4
  259. #define IPV6_RTHDR              5
  260. #define IPV6_PKTOPTIONS         6
  261. #define IPV6_CHECKSUM           7
  262. #define IPV6_HOPLIMIT           8
  263. #define IPV6_NEXTHOP            9
  264. #define IPV6_AUTHHDR            10
  265. #define IPV6_FLOWINFO           11
  266.  
  267. #define IPV6_UNICAST_HOPS       16
  268. #define IPV6_MULTICAST_IF       17
  269. #define IPV6_MULTICAST_HOPS     18
  270. #define IPV6_MULTICAST_LOOP     19
  271. #define IPV6_ADD_MEMBERSHIP     20
  272. #define IPV6_DROP_MEMBERSHIP    21
  273. #define IPV6_ROUTER_ALERT       22
  274. #define IPV6_MTU_DISCOVER       23
  275. #define IPV6_MTU                24
  276. #define IPV6_RECVERR            25
  277.  
  278. /* IPV6_MTU_DISCOVER values */
  279. #define IPV6_PMTUDISC_DONT              0
  280. #define IPV6_PMTUDISC_WANT              1
  281. #define IPV6_PMTUDISC_DO                2
  282.  
  283. /* Flowlabel */
  284. #define IPV6_FLOWLABEL_MGR      32
  285. #define IPV6_FLOWINFO_SEND      33
  286.  
  287. #define IPV6_MIN_MTU    1280
  288.  
  289. struct in6_pktinfo {
  290.   struct in6_addr       ipi6_addr;
  291.   int           ipi6_ifindex;
  292. };
  293.  
  294. struct in6_ifreq {
  295.   struct in6_addr       ifr6_addr;
  296.   uint32_t              ifr6_prefixlen;
  297.   int           ifr6_ifindex;
  298. };
  299.  
  300. #define IPV6_SRCRT_STRICT       0x01    /* this hop must be a neighbor  */
  301. #define IPV6_SRCRT_TYPE_0       0       /* IPv6 type 0 Routing Header   */
  302.  
  303. /* routing header */
  304. struct ipv6_rt_hdr {
  305.   uint8_t               nexthdr;
  306.   uint8_t               hdrlen;
  307.   uint8_t               type;
  308.   uint8_t               segments_left;
  309.   /* type specific data, variable length field */
  310. };
  311.  
  312. struct ipv6_opt_hdr {
  313.   uint8_t               nexthdr;
  314.   uint8_t               hdrlen;
  315.   /* TLV encoded option data follows. */
  316. };
  317.  
  318. #define ipv6_destopt_hdr ipv6_opt_hdr
  319. #define ipv6_hopopt_hdr  ipv6_opt_hdr
  320.  
  321. /* routing header type 0 (used in cmsghdr struct) */
  322.  
  323. #ifndef __STRICT_ANSI__
  324. struct rt0_hdr {
  325.   struct ipv6_rt_hdr    rt_hdr;
  326.   uint32_t              bitmap;         /* strict/loose bit map */
  327.   struct in6_addr       addr[0];
  328. #define rt0_type                rt_hdr.type;
  329. };
  330. #endif
  331.  
  332. struct ipv6hdr {
  333. #if __BYTE_ORDER == __LITTLE_ENDIAN
  334.   unsigned int          flow_lbl:20,
  335.                         priority:8,
  336.                         version:4;
  337. #else
  338.   unsigned int          version:4,
  339.                         priority:8,
  340.                         flow_lbl:20;
  341. #endif
  342.  
  343.   uint16_t              payload_len;
  344.   uint8_t               nexthdr;
  345.   uint8_t               hop_limit;
  346.  
  347.   struct in6_addr       saddr;
  348.   struct in6_addr       daddr;
  349. };
  350. /* fnord */
  351.  
  352. #define IPPORT_RESERVED 1024
  353. #define INET6_ADDRSTRLEN 46
  354.  
  355. #undef htonl
  356. #undef htons
  357. #undef ntohl
  358. #undef ntohs
  359. uint32_t htonl(uint32_t hostlong);
  360. uint16_t htons(uint16_t hostshort);
  361. uint32_t ntohl(uint32_t netlong);
  362. uint16_t ntohs(uint16_t netshort);
  363.  
  364. #define IN6_IS_ADDR_UNSPECIFIED(a) \
  365.         (((__const uint32_t *) (a))[0] == 0                                   \
  366.          && ((__const uint32_t *) (a))[1] == 0                                \
  367.          && ((__const uint32_t *) (a))[2] == 0                                \
  368.          && ((__const uint32_t *) (a))[3] == 0)
  369.  
  370. #define IN6_IS_ADDR_LOOPBACK(a) \
  371.         (((__const uint32_t *) (a))[0] == 0                                   \
  372.          && ((__const uint32_t *) (a))[1] == 0                                \
  373.          && ((__const uint32_t *) (a))[2] == 0                                \
  374.          && ((__const uint32_t *) (a))[3] == htonl (1))
  375.  
  376. #define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
  377.  
  378. #define IN6_IS_ADDR_LINKLOCAL(a) \
  379.         ((((__const uint32_t *) (a))[0] & htonl (0xffc00000))                 \
  380.          == htonl (0xfe800000))
  381.  
  382. #define IN6_IS_ADDR_SITELOCAL(a) \
  383.         ((((__const uint32_t *) (a))[0] & htonl (0xffc00000))                 \
  384.          == htonl (0xfec00000))
  385.  
  386. #define IN6_IS_ADDR_V4MAPPED(a) \
  387.         ((((__const uint32_t *) (a))[0] == 0)                                 \
  388.          && (((__const uint32_t *) (a))[1] == 0)                              \
  389.          && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
  390.  
  391. #define IN6_IS_ADDR_V4COMPAT(a) \
  392.         ((((__const uint32_t *) (a))[0] == 0)                                 \
  393.          && (((__const uint32_t *) (a))[1] == 0)                              \
  394.          && (((__const uint32_t *) (a))[2] == 0)                              \
  395.          && (ntohl (((__const uint32_t *) (a))[3]) > 1))
  396.  
  397. #define IN6_ARE_ADDR_EQUAL(a,b) \
  398.         ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0])     \
  399.          && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1])  \
  400.          && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2])  \
  401.          && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
  402.  
  403. /* old legacy bullshit */
  404. int bindresvport(int sd, struct sockaddr_in* _sin);
  405.  
  406. #define IN6_IS_ADDR_MC_NODELOCAL(a) \
  407.         (IN6_IS_ADDR_MULTICAST(a)                                             \
  408.          && ((((__const uint8_t *) (a))[1] & 0xf) == 0x1))
  409.  
  410. #define IN6_IS_ADDR_MC_LINKLOCAL(a) \
  411.         (IN6_IS_ADDR_MULTICAST(a)                                             \
  412.          && ((((__const uint8_t *) (a))[1] & 0xf) == 0x2))
  413.  
  414. #define IN6_IS_ADDR_MC_SITELOCAL(a) \
  415.         (IN6_IS_ADDR_MULTICAST(a)                                             \
  416.          && ((((__const uint8_t *) (a))[1] & 0xf) == 0x5))
  417.  
  418. #define IN6_IS_ADDR_MC_ORGLOCAL(a) \
  419.         (IN6_IS_ADDR_MULTICAST(a)                                             \
  420.          && ((((__const uint8_t *) (a))[1] & 0xf) == 0x8))
  421.  
  422. #define IN6_IS_ADDR_MC_GLOBAL(a) \
  423.         (IN6_IS_ADDR_MULTICAST(a)                                             \
  424.          && ((((__const uint8_t *) (a))[1] & 0xf) == 0xe))
  425.  
  426. __END_DECLS
  427.  
  428. #endif
  429.