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. __ntohs
  3. __htonl
  4. __htons

   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_GGP = 2,              /* Gateway Protocol (deprecated)        */
  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 
  44 /* Structure describing an Internet (IP) socket address. */
  45 #define __SOCK_SIZE__   16              /* sizeof(struct sockaddr)      */
  46 struct sockaddr_in {
  47   short int             sin_family;     /* Address family               */
  48   unsigned short int    sin_port;       /* Port number                  */
  49   struct in_addr        sin_addr;       /* Internet address             */
  50 
  51   /* Pad to size of `struct sockaddr'. */
  52   unsigned char         __pad[__SOCK_SIZE__ - sizeof(short int) -
  53                         sizeof(unsigned short int) - sizeof(struct in_addr)];
  54 };
  55 #define sin_zero        __pad           /* for BSD UNIX comp. -FvK      */
  56 
  57 
  58 /*
  59  * Definitions of the bits in an Internet address integer.
  60  * On subnets, host and network parts are found according
  61  * to the subnet mask, not these masks.
  62  */
  63 #define IN_CLASSA(a)            ((((long int) (a)) & 0x80000000) == 0)
  64 #define IN_CLASSA_NET           0xff000000
  65 #define IN_CLASSA_NSHIFT        24
  66 #define IN_CLASSA_HOST          (0xffffffff & ~IN_CLASSA_NET)
  67 #define IN_CLASSA_MAX           128
  68 
  69 #define IN_CLASSB(a)            ((((long int) (a)) & 0xc0000000) == 0x80000000)
  70 #define IN_CLASSB_NET           0xffff0000
  71 #define IN_CLASSB_NSHIFT        16
  72 #define IN_CLASSB_HOST          (0xffffffff & ~IN_CLASSB_NET)
  73 #define IN_CLASSB_MAX           65536
  74 
  75 #define IN_CLASSC(a)            ((((long int) (a)) & 0xc0000000) == 0xc0000000)
  76 #define IN_CLASSC_NET           0xffffff00
  77 #define IN_CLASSC_NSHIFT        8
  78 #define IN_CLASSC_HOST          (0xffffffff & ~IN_CLASSC_NET)
  79 
  80 #define IN_CLASSD(a)            ((((long int) (a)) & 0xf0000000) = 0xe0000000)
  81 #define IN_MULTICAST(a)         IN_CLASSD(a)
  82 
  83 #define IN_EXPERIMENTAL(a)      ((((long int) (a)) & 0xe0000000) = 0xe0000000)
  84 #define IN_BADCLASS(a)          ((((long int) (a)) & 0xf0000000) = 0xf0000000)
  85 
  86 /* Address to accept any incoming messages. */
  87 #define INADDR_ANY              ((unsigned long int) 0x00000000)
  88 
  89 /* Address to send to all hosts. */
  90 #define INADDR_BROADCAST        ((unsigned long int) 0xffffffff)
  91 
  92 /* Address indicating an error return. */
  93 #define INADDR_NONE             0xffffffff
  94 
  95 /* Network number for local host loopback. */
  96 #define IN_LOOPBACKNET          127
  97 
  98 /* Address to loopback in software to local host.  */
  99 #define INADDR_LOOPBACK         0x7f000001      /* 127.0.0.1            */
 100 
 101 
 102 /*
 103  * Options for use with `getsockopt' and `setsockopt' at
 104  * the IP level.  LINUX does not yet have the IP_OPTIONS
 105  * option (grin), so we undefine it for now.- HJ && FvK
 106  */
 107 #if 0
 108 # define IP_OPTIONS     1               /* IP per-packet options        */
 109 #endif
 110 #define IP_HDRINCL      2               /* raw packet header option     */
 111 
 112 
 113 /* Linux Internet number representation function declarations. */
 114 #undef ntohl
 115 #undef ntohs
 116 #undef htonl
 117 #undef htons
 118 
 119 extern unsigned long int        ntohl(unsigned long int);
 120 extern unsigned short int       ntohs(unsigned short int);
 121 extern unsigned long int        htonl(unsigned long int);
 122 extern unsigned short int       htons(unsigned short int);
 123 
 124 static __inline__ unsigned long int
 125 __ntohl(unsigned long int x)
     /* [previous][next][first][last][top][bottom][index][help] */
 126 {
 127   register unsigned long int tmp __asm__ ("ax") = x;
 128   __asm__ __volatile__ ("xchgb %%al,%%ah\n\t"   /* swap lower bytes     */
 129                 "rorl $16,%%eax\n\t"            /* swap words           */
 130                 "xchgb %%al,%%ah\n\t"           /* swap higher bytes    */
 131                 : "=a" (tmp) : "a" (tmp) );
 132   return(tmp);
 133 }
 134 
 135 static __inline__ unsigned short int
 136 __ntohs(unsigned short int x)
     /* [previous][next][first][last][top][bottom][index][help] */
 137 {
 138   register unsigned short int tmp __asm__ ("ax") = x;
 139   __asm__ __volatile__ ("xchgb %%al,%%ah\n\t"   /* swap bytes           */
 140                 : "=a" (tmp) : "a" (tmp));
 141   return(tmp);
 142 }
 143 
 144 static __inline__ unsigned long int
 145 __htonl(unsigned long int x)
     /* [previous][next][first][last][top][bottom][index][help] */
 146 {
 147   register unsigned long int tmp __asm__ ("ax") = x;
 148   __asm__ __volatile__ ("xchgb %%al,%%ah\n\t"   /* swap lower bytes     */
 149                 "rorl $16,%%eax\n\t"            /* swap words           */
 150                 "xchgb %%al,%%ah\n\t"           /* swap higher bytes    */
 151                 : "=a" (tmp) : "a" (tmp));
 152   return(tmp);
 153 }
 154 
 155 static __inline__ unsigned short int
 156 __htons(unsigned short int x)
     /* [previous][next][first][last][top][bottom][index][help] */
 157 {
 158   register unsigned short int tmp __asm__ ("ax") = x;
 159   __asm__ __volatile__ ("xchgb %%al,%%ah\n\t"   /* swap bytes */
 160                 : "=a" (tmp) : "a" (tmp));
 161   return(tmp);
 162 }
 163 
 164 #ifdef  __OPTIMIZE__
 165 #  define ntohl(x)      __ntohl((x))
 166 #  define ntohs(x)      __ntohs((x))
 167 #  define htonl(x)      __htonl((x))
 168 #  define htons(x)      __htons((x))
 169 #endif
 170 
 171 #endif  /* _LINUX_IN_H */

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