root/include/linux/in.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. __ntohl
  2. __constant_ntohl
  3. __ntohs
  4. __constant_ntohs

   1 /*
   2  * INET         An implementation of the TCP/IP protocol suite for the LINUX
   3  *              operating system.  INET is implemented using the  BSD Socket
   4  *              interface as the means of communication with the user level.
   5  *
   6  *              Definitions of the Internet Protocol.
   7  *
   8  * Version:     @(#)in.h        1.0.1   04/21/93
   9  *
  10  * Authors:     Original taken from the GNU Project <netinet/in.h> file.
  11  *              Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  12  *
  13  *              This program is free software; you can redistribute it and/or
  14  *              modify it under the terms of the GNU General Public License
  15  *              as published by the Free Software Foundation; either version
  16  *              2 of the License, or (at your option) any later version.
  17  */
  18 #ifndef _LINUX_IN_H
  19 #define _LINUX_IN_H
  20 
  21 
  22 /* Standard well-defined IP protocols.  */
  23 enum {
  24   IPPROTO_IP = 0,               /* Dummy protocol for TCP               */
  25   IPPROTO_ICMP = 1,             /* Internet Control Message Protocol    */
  26   IPPROTO_IGMP = 2,             /* Internet Gateway Management Protocol */
  27   IPPROTO_TCP = 6,              /* Transmission Control Protocol        */
  28   IPPROTO_EGP = 8,              /* Exterior Gateway Protocol            */
  29   IPPROTO_PUP = 12,             /* PUP protocol                         */
  30   IPPROTO_UDP = 17,             /* User Datagram Protocol               */
  31   IPPROTO_IDP = 22,             /* XNS IDP protocol                     */
  32 
  33   IPPROTO_RAW = 255,            /* Raw IP packets                       */
  34   IPPROTO_MAX
  35 };
  36 
  37 
  38 /* Internet address. */
  39 struct in_addr {
  40         unsigned long int       s_addr;
  41 };
  42 
  43 /* Request struct for multicast socket ops */
  44 
  45 struct ip_mreq 
  46 {
  47         struct in_addr imr_multiaddr;   /* IP multicast address of group */
  48         struct in_addr imr_interface;   /* local IP address of interface */
  49 };
  50 
  51 
  52 /* Structure describing an Internet (IP) socket address. */
  53 #define __SOCK_SIZE__   16              /* sizeof(struct sockaddr)      */
  54 struct sockaddr_in {
  55   short int             sin_family;     /* Address family               */
  56   unsigned short int    sin_port;       /* Port number                  */
  57   struct in_addr        sin_addr;       /* Internet address             */
  58 
  59   /* Pad to size of `struct sockaddr'. */
  60   unsigned char         __pad[__SOCK_SIZE__ - sizeof(short int) -
  61                         sizeof(unsigned short int) - sizeof(struct in_addr)];
  62 };
  63 #define sin_zero        __pad           /* for BSD UNIX comp. -FvK      */
  64 
  65 
  66 /*
  67  * Definitions of the bits in an Internet address integer.
  68  * On subnets, host and network parts are found according
  69  * to the subnet mask, not these masks.
  70  */
  71 #define IN_CLASSA(a)            ((((long int) (a)) & 0x80000000) == 0)
  72 #define IN_CLASSA_NET           0xff000000
  73 #define IN_CLASSA_NSHIFT        24
  74 #define IN_CLASSA_HOST          (0xffffffff & ~IN_CLASSA_NET)
  75 #define IN_CLASSA_MAX           128
  76 
  77 #define IN_CLASSB(a)            ((((long int) (a)) & 0xc0000000) == 0x80000000)
  78 #define IN_CLASSB_NET           0xffff0000
  79 #define IN_CLASSB_NSHIFT        16
  80 #define IN_CLASSB_HOST          (0xffffffff & ~IN_CLASSB_NET)
  81 #define IN_CLASSB_MAX           65536
  82 
  83 #define IN_CLASSC(a)            ((((long int) (a)) & 0xc0000000) == 0xc0000000)
  84 #define IN_CLASSC_NET           0xffffff00
  85 #define IN_CLASSC_NSHIFT        8
  86 #define IN_CLASSC_HOST          (0xffffffff & ~IN_CLASSC_NET)
  87 
  88 #define IN_CLASSD(a)            ((((long int) (a)) & 0xf0000000) == 0xe0000000)
  89 #define IN_MULTICAST(a)         IN_CLASSD(a)
  90 
  91 #define IN_EXPERIMENTAL(a)      ((((long int) (a)) & 0xe0000000) == 0xe0000000)
  92 #define IN_BADCLASS(a)          ((((long int) (a)) & 0xf0000000) == 0xf0000000)
  93 
  94 /* Address to accept any incoming messages. */
  95 #define INADDR_ANY              ((unsigned long int) 0x00000000)
  96 
  97 /* Address to send to all hosts. */
  98 #define INADDR_BROADCAST        ((unsigned long int) 0xffffffff)
  99 
 100 /* Address indicating an error return. */
 101 #define INADDR_NONE             0xffffffff
 102 
 103 /* Network number for local host loopback. */
 104 #define IN_LOOPBACKNET          127
 105 
 106 /* Address to loopback in software to local host.  */
 107 #define INADDR_LOOPBACK         0x7f000001      /* 127.0.0.1            */
 108 
 109 
 110 /*
 111  * Options for use with `getsockopt' and `setsockopt' at
 112  * the IP level.  LINUX does not yet have the IP_OPTIONS
 113  * option (grin), so we undefine it for now.- HJ && FvK
 114  */
 115 #if 0
 116 # define IP_OPTIONS     1               /* IP per-packet options        */
 117 #endif
 118 #define IP_HDRINCL      2               /* raw packet header option     */
 119 
 120 
 121 /* Linux Internet number representation function declarations. */
 122 #undef ntohl
 123 #undef ntohs
 124 #undef htonl
 125 #undef htons
 126 
 127 extern unsigned long int        ntohl(unsigned long int);
 128 extern unsigned short int       ntohs(unsigned short int);
 129 extern unsigned long int        htonl(unsigned long int);
 130 extern unsigned short int       htons(unsigned short int);
 131 
 132 extern __inline__ unsigned long int
 133 __ntohl(unsigned long int x)
     /* [previous][next][first][last][top][bottom][index][help] */
 134 {
 135         __asm__("xchgb %b0,%h0\n\t"     /* swap lower bytes     */
 136                 "rorl $16,%0\n\t"       /* swap words           */
 137                 "xchgb %b0,%h0"         /* swap higher bytes    */
 138                 :"=q" (x)
 139                 : "0" (x));
 140         return x;
 141 }
 142 
 143 extern __inline__ unsigned long int
 144 __constant_ntohl(unsigned long int x)
     /* [previous][next][first][last][top][bottom][index][help] */
 145 {
 146         return (((x & 0x000000ffU) << 24) |
 147                 ((x & 0x0000ff00U) <<  8) |
 148                 ((x & 0x00ff0000U) >>  8) |
 149                 ((x & 0xff000000U) >> 24));
 150 }
 151 
 152 extern __inline__ unsigned short int
 153 __ntohs(unsigned short int x)
     /* [previous][next][first][last][top][bottom][index][help] */
 154 {
 155         __asm__("xchgb %b0,%h0"         /* swap bytes           */
 156                 : "=q" (x)
 157                 :  "0" (x));
 158         return x;
 159 }
 160 
 161 extern __inline__ unsigned short int
 162 __constant_ntohs(unsigned short int x)
     /* [previous][next][first][last][top][bottom][index][help] */
 163 {
 164         return (((x & 0x00ff) << 8) |
 165                 ((x & 0xff00) >> 8));
 166 }
 167 
 168 #define __htonl(x) __ntohl(x)
 169 #define __htons(x) __ntohs(x)
 170 #define __constant_htonl(x) __constant_ntohl(x)
 171 #define __constant_htons(x) __constant_ntohs(x)
 172 
 173 #ifdef  __OPTIMIZE__
 174 #  define ntohl(x) \
 175 (__builtin_constant_p((long)(x)) ? \
 176  __constant_ntohl((x)) : \
 177  __ntohl((x)))
 178 #  define ntohs(x) \
 179 (__builtin_constant_p((short)(x)) ? \
 180  __constant_ntohs((x)) : \
 181  __ntohs((x)))
 182 #  define htonl(x) \
 183 (__builtin_constant_p((long)(x)) ? \
 184  __constant_htonl((x)) : \
 185  __htonl((x)))
 186 #  define htons(x) \
 187 (__builtin_constant_p((short)(x)) ? \
 188  __constant_htons((x)) : \
 189  __htons((x)))
 190 #endif
 191 
 192 #endif  /* _LINUX_IN_H */

/* [previous][next][first][last][top][bottom][index][help] */