home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue2 / SDL.ARC / !unixlib / source / clib / netinet / h / in < prev    next >
Encoding:
Text File  |  2004-09-05  |  13.0 KB  |  389 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /usr/local/cvsroot/gccsdk/unixlib/source/clib/netinet/in.h,v $
  4.  * $Date: 2004/08/08 11:32:41 $
  5.  * $Revision: 1.6 $
  6.  * $State: Exp $
  7.  * $Author: peter $
  8.  *
  9.  ***************************************************************************/
  10.  
  11. /*
  12.  * File taken from glibc 2.2.5.
  13.  * Following changes were made:
  14.  *  - Changed "#include <features.h>" into "#include <unixlib/features.h>"
  15.  *  - Changed "#include <bits/types.h>" into "#include <unixlib/types.h>"
  16.  *  - The ntohl(), ntohs(), htonl() and htons() are always 'optimized'.
  17.  */
  18.  
  19. /* Copyright (C) 1991-1999, 2000, 2001 Free Software Foundation, Inc.
  20.    This file is part of the GNU C Library.
  21.  
  22.    The GNU C Library is free software; you can redistribute it and/or
  23.    modify it under the terms of the GNU Lesser General Public
  24.    License as published by the Free Software Foundation; either
  25.    version 2.1 of the License, or (at your option) any later version.
  26.  
  27.    The GNU C Library is distributed in the hope that it will be useful,
  28.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  29.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  30.    Lesser General Public License for more details.
  31.  
  32.    You should have received a copy of the GNU Lesser General Public
  33.    License along with the GNU C Library; if not, write to the Free
  34.    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  35.    02111-1307 USA.  */
  36.  
  37. #ifndef    __NETINET_IN_H
  38. #define    __NETINET_IN_H    1
  39.  
  40. #include <unixlib/features.h>
  41. #include <stdint.h>
  42. #include <unixlib/types.h>
  43. #include <sys/param.h>
  44.  
  45.  
  46. __BEGIN_DECLS
  47.  
  48. /* Standard well-defined IP protocols.  */
  49. enum
  50.   {
  51.     IPPROTO_IP = 0,       /* Dummy protocol for TCP.  */
  52. #define IPPROTO_IP        IPPROTO_IP
  53.     IPPROTO_HOPOPTS = 0,   /* IPv6 Hop-by-Hop options.  */
  54. #define IPPROTO_HOPOPTS        IPPROTO_HOPOPTS
  55.     IPPROTO_ICMP = 1,       /* Internet Control Message Protocol.  */
  56. #define IPPROTO_ICMP        IPPROTO_ICMP
  57.     IPPROTO_IGMP = 2,       /* Internet Group Management Protocol. */
  58. #define IPPROTO_IGMP        IPPROTO_IGMP
  59.     IPPROTO_IPIP = 4,       /* IPIP tunnels (older KA9Q tunnels use 94).  */
  60. #define IPPROTO_IPIP        IPPROTO_IPIP
  61.     IPPROTO_TCP = 6,       /* Transmission Control Protocol.  */
  62. #define IPPROTO_TCP        IPPROTO_TCP
  63.     IPPROTO_EGP = 8,       /* Exterior Gateway Protocol.  */
  64. #define IPPROTO_EGP        IPPROTO_EGP
  65.     IPPROTO_PUP = 12,       /* PUP protocol.  */
  66. #define IPPROTO_PUP        IPPROTO_PUP
  67.     IPPROTO_UDP = 17,       /* User Datagram Protocol.  */
  68. #define IPPROTO_UDP        IPPROTO_UDP
  69.     IPPROTO_IDP = 22,       /* XNS IDP protocol.  */
  70. #define IPPROTO_IDP        IPPROTO_IDP
  71.     IPPROTO_TP = 29,       /* SO Transport Protocol Class 4.  */
  72. #define IPPROTO_TP        IPPROTO_TP
  73.     IPPROTO_IPV6 = 41,     /* IPv6 header.  */
  74. #define IPPROTO_IPV6        IPPROTO_IPV6
  75.     IPPROTO_ROUTING = 43,  /* IPv6 routing header.  */
  76. #define IPPROTO_ROUTING        IPPROTO_ROUTING
  77.     IPPROTO_FRAGMENT = 44, /* IPv6 fragmentation header.  */
  78. #define IPPROTO_FRAGMENT    IPPROTO_FRAGMENT
  79.     IPPROTO_RSVP = 46,       /* Reservation Protocol.  */
  80. #define IPPROTO_RSVP        IPPROTO_RSVP
  81.     IPPROTO_GRE = 47,       /* General Routing Encapsulation.  */
  82. #define IPPROTO_GRE        IPPROTO_GRE
  83.     IPPROTO_ESP = 50,      /* encapsulating security payload.  */
  84. #define IPPROTO_ESP        IPPROTO_ESP
  85.     IPPROTO_AH = 51,       /* authentication header.  */
  86. #define IPPROTO_AH        IPPROTO_AH
  87.     IPPROTO_ICMPV6 = 58,   /* ICMPv6.  */
  88. #define IPPROTO_ICMPV6        IPPROTO_ICMPV6
  89.     IPPROTO_NONE = 59,     /* IPv6 no next header.  */
  90. #define IPPROTO_NONE        IPPROTO_NONE
  91.     IPPROTO_DSTOPTS = 60,  /* IPv6 destination options.  */
  92. #define IPPROTO_DSTOPTS        IPPROTO_DSTOPTS
  93.     IPPROTO_MTP = 92,       /* Multicast Transport Protocol.  */
  94. #define IPPROTO_MTP        IPPROTO_MTP
  95.     IPPROTO_ENCAP = 98,       /* Encapsulation Header.  */
  96. #define IPPROTO_ENCAP        IPPROTO_ENCAP
  97.     IPPROTO_PIM = 103,       /* Protocol Independent Multicast.  */
  98. #define IPPROTO_PIM        IPPROTO_PIM
  99.     IPPROTO_COMP = 108,       /* Compression Header Protocol.  */
  100. #define IPPROTO_COMP        IPPROTO_COMP
  101.     IPPROTO_RAW = 255,       /* Raw IP packets.  */
  102. #define IPPROTO_RAW        IPPROTO_RAW
  103.     IPPROTO_MAX
  104.   };
  105.  
  106.  
  107. /* Type to represent a port.  */
  108. typedef uint16_t in_port_t;
  109.  
  110. /* Standard well-known ports.  */
  111. enum
  112.   {
  113.     IPPORT_ECHO = 7,        /* Echo service.  */
  114.     IPPORT_DISCARD = 9,        /* Discard transmissions service.  */
  115.     IPPORT_SYSTAT = 11,        /* System status service.  */
  116.     IPPORT_DAYTIME = 13,    /* Time of day service.  */
  117.     IPPORT_NETSTAT = 15,    /* Network status service.  */
  118.     IPPORT_FTP = 21,        /* File Transfer Protocol.  */
  119.     IPPORT_TELNET = 23,        /* Telnet protocol.  */
  120.     IPPORT_SMTP = 25,        /* Simple Mail Transfer Protocol.  */
  121.     IPPORT_TIMESERVER = 37,    /* Timeserver service.  */
  122.     IPPORT_NAMESERVER = 42,    /* Domain Name Service.  */
  123.     IPPORT_WHOIS = 43,        /* Internet Whois service.  */
  124.     IPPORT_MTP = 57,
  125.  
  126.     IPPORT_TFTP = 69,        /* Trivial File Transfer Protocol.  */
  127.     IPPORT_RJE = 77,
  128.     IPPORT_FINGER = 79,        /* Finger service.  */
  129.     IPPORT_TTYLINK = 87,
  130.     IPPORT_SUPDUP = 95,        /* SUPDUP protocol.  */
  131.  
  132.  
  133.     IPPORT_EXECSERVER = 512,    /* execd service.  */
  134.     IPPORT_LOGINSERVER = 513,    /* rlogind service.  */
  135.     IPPORT_CMDSERVER = 514,
  136.     IPPORT_EFSSERVER = 520,
  137.  
  138.     /* UDP ports.  */
  139.     IPPORT_BIFFUDP = 512,
  140.     IPPORT_WHOSERVER = 513,
  141.     IPPORT_ROUTESERVER = 520,
  142.  
  143.     /* Ports less than this value are reserved for privileged processes.  */
  144.     IPPORT_RESERVED = 1024,
  145.  
  146.     /* Ports greater this value are reserved for (non-privileged) servers.  */
  147.     IPPORT_USERRESERVED = 5000
  148.   };
  149.  
  150.  
  151. /* Internet address.  */
  152. typedef uint32_t in_addr_t;
  153. struct in_addr
  154.   {
  155.     in_addr_t s_addr;
  156.   };
  157.  
  158.  
  159. /* Definitions of the bits in an Internet address integer.
  160.  
  161.    On subnets, host and network parts are found according to
  162.    the subnet mask, not these masks.  */
  163.  
  164. #define    IN_CLASSA(a)        ((((in_addr_t)(a)) & 0x80000000) == 0)
  165. #define    IN_CLASSA_NET        0xff000000
  166. #define    IN_CLASSA_NSHIFT    24
  167. #define    IN_CLASSA_HOST        (0xffffffff & ~IN_CLASSA_NET)
  168. #define    IN_CLASSA_MAX        128
  169.  
  170. #define    IN_CLASSB(a)        ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000)
  171. #define    IN_CLASSB_NET        0xffff0000
  172. #define    IN_CLASSB_NSHIFT    16
  173. #define    IN_CLASSB_HOST        (0xffffffff & ~IN_CLASSB_NET)
  174. #define    IN_CLASSB_MAX        65536
  175.  
  176. #define    IN_CLASSC(a)        ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000)
  177. #define    IN_CLASSC_NET        0xffffff00
  178. #define    IN_CLASSC_NSHIFT    8
  179. #define    IN_CLASSC_HOST        (0xffffffff & ~IN_CLASSC_NET)
  180.  
  181. #define    IN_CLASSD(a)        ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000)
  182. #define    IN_MULTICAST(a)        IN_CLASSD(a)
  183.  
  184. #define    IN_EXPERIMENTAL(a)    ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000)
  185. #define    IN_BADCLASS(a)        ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000)
  186.  
  187. /* Address to accept any incoming messages.  */
  188. #define    INADDR_ANY        ((in_addr_t) 0x00000000)
  189. /* Address to send to all hosts.  */
  190. #define    INADDR_BROADCAST    ((in_addr_t) 0xffffffff)
  191. /* Address indicating an error return.  */
  192. #define    INADDR_NONE        ((in_addr_t) 0xffffffff)
  193.  
  194. /* Network number for local host loopback.  */
  195. #define    IN_LOOPBACKNET        127
  196. /* Address to loopback in software to local host.  */
  197. #ifndef INADDR_LOOPBACK
  198. # define INADDR_LOOPBACK    ((in_addr_t) 0x7f000001) /* Inet 127.0.0.1.  */
  199. #endif
  200.  
  201. /* Defines for Multicast INADDR.  */
  202. #define INADDR_UNSPEC_GROUP    ((in_addr_t) 0xe0000000) /* 224.0.0.0 */
  203. #define INADDR_ALLHOSTS_GROUP    ((in_addr_t) 0xe0000001) /* 224.0.0.1 */
  204. #define INADDR_ALLRTRS_GROUP    ((in_addr_t) 0xe0000002) /* 224.0.0.2 */
  205. #define INADDR_MAX_LOCAL_GROUP  ((in_addr_t) 0xe00000ff) /* 224.0.0.255 */
  206.  
  207.  
  208. /* IPv6 address */
  209. struct in6_addr
  210.   {
  211.     union
  212.       {
  213.     uint8_t    u6_addr8[16];
  214.     uint16_t u6_addr16[8];
  215.     uint32_t u6_addr32[4];
  216.       } in6_u;
  217. #define s6_addr            in6_u.u6_addr8
  218. #define s6_addr16        in6_u.u6_addr16
  219. #define s6_addr32        in6_u.u6_addr32
  220.   };
  221.  
  222. extern const struct in6_addr in6addr_any;        /* :: */
  223. extern const struct in6_addr in6addr_loopback;   /* ::1 */
  224. #define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
  225. #define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
  226.  
  227. #define INET_ADDRSTRLEN 16
  228. #define INET6_ADDRSTRLEN 46
  229.  
  230. /* Get the definition of the macro to define the common sockaddr members.  */
  231. #include <bits/socket.h>
  232.  
  233.  
  234. /* Structure describing an Internet socket address.  */
  235. struct sockaddr_in
  236.   {
  237.     __SOCKADDR_COMMON (sin_);
  238.     in_port_t sin_port;            /* Port number.  */
  239.     struct in_addr sin_addr;        /* Internet address.  */
  240.  
  241.     /* Pad to size of `struct sockaddr'.  */
  242.     unsigned char sin_zero[sizeof (struct sockaddr) -
  243.                __SOCKADDR_COMMON_SIZE -
  244.                sizeof (in_port_t) -
  245.                sizeof (struct in_addr)];
  246.   };
  247.  
  248. /* Ditto, for IPv6.  */
  249. struct sockaddr_in6
  250.   {
  251.     __SOCKADDR_COMMON (sin6_);
  252.     in_port_t sin6_port;    /* Transport layer port # */
  253.     uint32_t sin6_flowinfo;    /* IPv6 flow information */
  254.     struct in6_addr sin6_addr;    /* IPv6 address */
  255.     uint32_t sin6_scope_id;    /* IPv6 scope-id */
  256.   };
  257.  
  258. /* IPv6 multicast request.  */
  259. struct ipv6_mreq
  260.   {
  261.     /* IPv6 multicast address of group */
  262.     struct in6_addr ipv6mr_multiaddr;
  263.  
  264.     /* local interface */
  265.     unsigned int ipv6mr_interface;
  266.   };
  267.  
  268. /* Get system-specific definitions.  */
  269. #include <bits/in.h>
  270.  
  271. /* Functions to convert between host and network byte order.
  272.  
  273.    Please note that these functions normally take `unsigned long int' or
  274.    `unsigned short int' values as arguments and also return them.  But
  275.    this was a short-sighted decision since on different systems the types
  276.    may have different representations but the values are always the same.  */
  277.  
  278. extern uint32_t ntohl (uint32_t __netlong) __THROW __attribute__ ((__const__));
  279. extern uint16_t ntohs (uint16_t __netshort)
  280.      __THROW __attribute__ ((__const__));
  281. extern uint32_t htonl (uint32_t __hostlong)
  282.      __THROW __attribute__ ((__const__));
  283. extern uint16_t htons (uint16_t __hostshort)
  284.      __THROW __attribute__ ((__const__));
  285.  
  286. #include <endian.h>
  287.  
  288. /* Get machine dependent optimized versions of byte swapping functions.  */
  289. #include <bits/byteswap.h>
  290.  
  291. /* #ifdef __OPTIMIZE__ */
  292. /* We can optimize calls to the conversion functions.  Either nothing has
  293.    to be done or we are using directly the byte-swapping functions which
  294.    often can be inlined.  */
  295. # if __BYTE_ORDER == __BIG_ENDIAN
  296. /* The host byte order is the same as network byte order,
  297.    so these functions are all just identity.  */
  298. # define ntohl(x)    (x)
  299. # define ntohs(x)    (x)
  300. # define htonl(x)    (x)
  301. # define htons(x)    (x)
  302. # else
  303. #  if __BYTE_ORDER == __LITTLE_ENDIAN
  304. #   define ntohl(x)    __bswap_32 (x)
  305. #   define ntohs(x)    __bswap_16 (x)
  306. #   define htonl(x)    __bswap_32 (x)
  307. #   define htons(x)    __bswap_16 (x)
  308. #  endif
  309. # endif
  310. /* #endif */
  311.  
  312. #define IN6_IS_ADDR_UNSPECIFIED(a) \
  313.     (((__const uint32_t *) (a))[0] == 0                      \
  314.      && ((__const uint32_t *) (a))[1] == 0                      \
  315.      && ((__const uint32_t *) (a))[2] == 0                      \
  316.      && ((__const uint32_t *) (a))[3] == 0)
  317.  
  318. #define IN6_IS_ADDR_LOOPBACK(a) \
  319.     (((__const uint32_t *) (a))[0] == 0                      \
  320.      && ((__const uint32_t *) (a))[1] == 0                      \
  321.      && ((__const uint32_t *) (a))[2] == 0                      \
  322.      && ((__const uint32_t *) (a))[3] == htonl (1))
  323.  
  324. #define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
  325.  
  326. #define IN6_IS_ADDR_LINKLOCAL(a) \
  327.     ((((__const uint32_t *) (a))[0] & htonl (0xffc00000))              \
  328.      == htonl (0xfe800000))
  329.  
  330. #define IN6_IS_ADDR_SITELOCAL(a) \
  331.     ((((__const uint32_t *) (a))[0] & htonl (0xffc00000))              \
  332.      == htonl (0xfec00000))
  333.  
  334. #define IN6_IS_ADDR_V4MAPPED(a) \
  335.     ((((__const uint32_t *) (a))[0] == 0)                      \
  336.      && (((__const uint32_t *) (a))[1] == 0)                  \
  337.      && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
  338.  
  339. #define IN6_IS_ADDR_V4COMPAT(a) \
  340.     ((((__const uint32_t *) (a))[0] == 0)                      \
  341.      && (((__const uint32_t *) (a))[1] == 0)                  \
  342.      && (((__const uint32_t *) (a))[2] == 0)                  \
  343.      && (ntohl (((__const uint32_t *) (a))[3]) > 1))
  344.  
  345. #define IN6_ARE_ADDR_EQUAL(a,b) \
  346.     ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0])     \
  347.      && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1])  \
  348.      && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2])  \
  349.      && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
  350.  
  351. /* Bind socket to a privileged IP port.  */
  352. extern int bindresvport (int __sockfd, struct sockaddr_in *__sock_in) __THROW;
  353.  
  354. /* The IPv6 version of this function.  */
  355. extern int bindresvport6 (int __sockfd, struct sockaddr_in6 *__sock_in)
  356.      __THROW;
  357.  
  358.  
  359. #define IN6_IS_ADDR_MC_NODELOCAL(a) \
  360.     (IN6_IS_ADDR_MULTICAST(a)                          \
  361.      && ((((__const uint8_t *) (a))[1] & 0xf) == 0x1))
  362.  
  363. #define IN6_IS_ADDR_MC_LINKLOCAL(a) \
  364.     (IN6_IS_ADDR_MULTICAST(a)                          \
  365.      && ((((__const uint8_t *) (a))[1] & 0xf) == 0x2))
  366.  
  367. #define IN6_IS_ADDR_MC_SITELOCAL(a) \
  368.     (IN6_IS_ADDR_MULTICAST(a)                          \
  369.      && ((((__const uint8_t *) (a))[1] & 0xf) == 0x5))
  370.  
  371. #define IN6_IS_ADDR_MC_ORGLOCAL(a) \
  372.     (IN6_IS_ADDR_MULTICAST(a)                          \
  373.      && ((((__const uint8_t *) (a))[1] & 0xf) == 0x8))
  374.  
  375. #define IN6_IS_ADDR_MC_GLOBAL(a) \
  376.     (IN6_IS_ADDR_MULTICAST(a)                          \
  377.      && ((((__const uint8_t *) (a))[1] & 0xf) == 0xe))
  378.  
  379. /* IPv6 packet information.  */
  380. struct in6_pktinfo
  381.   {
  382.     struct in6_addr    ipi6_addr;    /* src/dst IPv6 address */
  383.     unsigned int    ipi6_ifindex; /* send/recv interface index */
  384.   };
  385.  
  386. __END_DECLS
  387.  
  388. #endif    /* netinet/in.h */
  389.