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