in.h

Go to the documentation of this file.
00001 /**
00002 *
00003 
00004  * INET         An implementation of the TCP/IP protocol suite for the LINUX
00005  *              operating system.  INET is implemented using the  BSD Socket
00006  *              interface as the means of communication with the user level.
00007  *
00008  *              Definitions of the Internet Protocol.
00009  *
00010  * Version:     @(#)in.h        1.0.1   04/21/93
00011  *
00012  * Authors:     Original taken from the GNU Project <netinet/in.h> file.
00013  *              Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
00014  *
00015  *              This program is free software; you can redistribute it and/or
00016  *              modify it under the terms of the GNU General Public License
00017  *              as published by the Free Software Foundation; either version
00018  *              2 of the License, or (at your option) any later version.
00019 
00020 
00021 */
00022 #ifndef _LINUX_IN_H
00023 #define _LINUX_IN_H
00024 
00025 
00026 /// Standard well-defined IP protocols.  
00027 enum {
00028   IPPROTO_IP = 0,               ///< Dummy protocol for TCP             
00029   IPPROTO_ICMP = 1,             ///< Internet Control Message Protocol  
00030   IPPROTO_GGP = 2,              ///< Gateway Protocol (deprecated)      
00031   IPPROTO_TCP = 6,              ///< Transmission Control Protocol      
00032   IPPROTO_EGP = 8,              ///< Exterior Gateway Protocol          
00033   IPPROTO_PUP = 12,             ///< PUP protocol                               
00034   IPPROTO_UDP = 17,             ///< User Datagram Protocol             
00035   IPPROTO_IDP = 22,             ///< XNS IDP protocol                   
00036 
00037   IPPROTO_RAW = 255,            ///< Raw IP packets                     
00038   IPPROTO_MAX
00039 };
00040 
00041 
00042 /// Internet address. 
00043 struct in_addr {
00044         unsigned long int       s_addr;
00045 };
00046 
00047 
00048 /// Structure describing an Internet (IP) socket address. 
00049 #define __SOCK_SIZE__   16              ///< sizeof(struct sockaddr)    
00050 struct sockaddr_in {
00051   short int             sin_family;     ///< Address family             
00052   unsigned short int    sin_port;       ///< Port number                        
00053   struct in_addr        sin_addr;       ///< Internet address           
00054 
00055   /// Pad to size of `struct sockaddr'. 
00056   unsigned char         __pad[__SOCK_SIZE__ - sizeof(short int) -
00057                         sizeof(unsigned short int) - sizeof(struct in_addr)];
00058 };
00059 #define sin_zero        __pad           ///< for BSD UNIX comp. -FvK    
00060 
00061 
00062 /**
00063 *
00064 
00065  * Definitions of the bits in an Internet address integer.
00066  * On subnets, host and network parts are found according
00067  * to the subnet mask, not these masks.
00068 
00069 
00070 */
00071 #define IN_CLASSA(a)            ((((long int) (a)) & 0x80000000) == 0)
00072 #define IN_CLASSA_NET           0xff000000
00073 #define IN_CLASSA_NSHIFT        24
00074 #define IN_CLASSA_HOST          (0xffffffff & ~IN_CLASSA_NET)
00075 #define IN_CLASSA_MAX           128
00076 
00077 #define IN_CLASSB(a)            ((((long int) (a)) & 0xc0000000) == 0x80000000)
00078 #define IN_CLASSB_NET           0xffff0000
00079 #define IN_CLASSB_NSHIFT        16
00080 #define IN_CLASSB_HOST          (0xffffffff & ~IN_CLASSB_NET)
00081 #define IN_CLASSB_MAX           65536
00082 
00083 #define IN_CLASSC(a)            ((((long int) (a)) & 0xc0000000) == 0xc0000000)
00084 #define IN_CLASSC_NET           0xffffff00
00085 #define IN_CLASSC_NSHIFT        8
00086 #define IN_CLASSC_HOST          (0xffffffff & ~IN_CLASSC_NET)
00087 
00088 #define IN_CLASSD(a)            ((((long int) (a)) & 0xf0000000) == 0xe0000000)
00089 #define IN_MULTICAST(a)         IN_CLASSD(a)
00090 
00091 #define IN_EXPERIMENTAL(a)      ((((long int) (a)) & 0xe0000000) == 0xe0000000)
00092 #define IN_BADCLASS(a)          ((((long int) (a)) & 0xf0000000) == 0xf0000000)
00093 
00094 /// Address to accept any incoming messages. 
00095 #define INADDR_ANY              ((unsigned long int) 0x00000000)
00096 
00097 /// Address to send to all hosts. 
00098 #define INADDR_BROADCAST        ((unsigned long int) 0xffffffff)
00099 
00100 /// Address indicating an error return. 
00101 #define INADDR_NONE             0xffffffff
00102 
00103 /// Network number for local host loopback. 
00104 #define IN_LOOPBACKNET          127
00105 
00106 /// Address to loopback in software to local host.  
00107 #define INADDR_LOOPBACK         0x7f000001      ///< 127.0.0.1          
00108 
00109 
00110 /**
00111 *
00112 
00113  * Options for use with `getsockopt' and `setsockopt' at
00114  * the IP level.  LINUX does not yet have the IP_OPTIONS
00115  * option (grin), so we undefine it for now.- HJ && FvK
00116 
00117 
00118 */
00119 #if 0
00120 # define IP_OPTIONS     1               ///< IP per-packet options      
00121 #endif
00122 #define IP_HDRINCL      2               ///< raw packet header option   
00123 
00124 
00125 /// Linux Internet number representation function declarations. 
00126 #undef ntohl
00127 #undef ntohs
00128 #undef htonl
00129 #undef htons
00130 
00131 extern unsigned long int        ntohl(unsigned long int);
00132 extern unsigned short int       ntohs(unsigned short int);
00133 extern unsigned long int        htonl(unsigned long int);
00134 extern unsigned short int       htons(unsigned short int);
00135 
00136 static __inline__ unsigned long int
00137 __ntohl(unsigned long int x)
00138 {
00139         __asm__("xchgb %b0,%h0\n\t"     ///< swap lower bytes   
00140                 "rorl $16,%0\n\t"       ///< swap words         
00141                 "xchgb %b0,%h0"         ///< swap higher bytes  
00142                 :"=q" (x)
00143                 : "0" (x));
00144         return x;
00145 }
00146 
00147 static __inline__ unsigned long int
00148 __constant_ntohl(unsigned long int x)
00149 {
00150         return (((x & 0x000000ff) << 24) |
00151                 ((x & 0x0000ff00) <<  8) |
00152                 ((x & 0x00ff0000) >>  8) |
00153                 ((x & 0xff000000) >> 24));
00154 }
00155 
00156 static __inline__ unsigned short int
00157 __ntohs(unsigned short int x)
00158 {
00159         __asm__("xchgb %b0,%h0"         ///< swap bytes         
00160                 : "=q" (x)
00161                 :  "0" (x));
00162         return x;
00163 }
00164 
00165 static __inline__ unsigned short int
00166 __constant_ntohs(unsigned short int x)
00167 {
00168         return (((x & 0x00ff) << 8) |
00169                 ((x & 0xff00) >> 8));
00170 }
00171 
00172 #define __htonl(x) __ntohl(x)
00173 #define __htons(x) __ntohs(x)
00174 #define __constant_htonl(x) __constant_ntohl(x)
00175 #define __constant_htons(x) __constant_ntohs(x)
00176 
00177 #ifdef  __OPTIMIZE__
00178 #  define ntohl(x) \
00179 (__builtin_constant_p((x)) ? \
00180  __constant_ntohl((x)) : \
00181  __ntohl((x)))
00182 #  define ntohs(x) \
00183 (__builtin_constant_p((x)) ? \
00184  __constant_ntohs((x)) : \
00185  __ntohs((x)))
00186 #  define htonl(x) \
00187 (__builtin_constant_p((x)) ? \
00188  __constant_htonl((x)) : \
00189  __htonl((x)))
00190 #  define htons(x) \
00191 (__builtin_constant_p((x)) ? \
00192  __constant_htons((x)) : \
00193  __htons((x)))
00194 #endif
00195 
00196 #endif  // _LINUX_IN_H 

Generated on Mon May 1 21:47:00 2006 for KernelAPI by  doxygen 1.4.6-5