home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.0 / NeXTSTEP3.0.iso / NextDeveloper / Headers / bsd / netinet / in.h < prev    next >
Text File  |  1992-07-29  |  6KB  |  223 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1987 Carnegie-Mellon University
  4.  * All rights reserved.  The CMU software License Agreement specifies
  5.  * the terms and conditions for use and redistribution.
  6.  */
  7. /*
  8.  * Copyright (c) 1982, 1986 Regents of the University of California.
  9.  * All rights reserved.
  10.  * Redistribution and use in source and binary forms are permitted
  11.  * provided that this notice is preserved and that due credit is given
  12.  * to the University of California at Berkeley. The name of the University
  13.  * may not be used to endorse or promote products derived from this
  14.  * software without specific prior written permission. This software
  15.  * is provided ``as is'' without express or implied warranty.
  16.  *
  17.  *    @(#)in.h    7.5 (Berkeley) 2/22/88
  18.  *
  19.  * HISTORY
  20.  * 26-Sep-89  Morris Meyer (mmeyer) at NeXT
  21.  *    NFS 4.0 Changes: Added definition of official port numbers.
  22.  */ 
  23.  
  24. #ifndef    _IN_
  25. #define    _IN_
  26.  
  27. #ifdef    KERNEL
  28. #import    <sys/protosw.h>
  29. #import    <sys/domain.h>
  30. #endif    KERNEL
  31.  
  32. /*  @(#)in.h    2.2 88/06/10 4.0NFSSRC; from    7.1 (Berkeley) 6/5/86 */
  33.  
  34. /*
  35.  * Constants and structures defined by the internet system,
  36.  * Per RFC 790, September 1981.
  37.  */
  38.  
  39. /*
  40.  * Protocols
  41.  */
  42. #define    IPPROTO_IP        0        /* dummy for IP */
  43. #define    IPPROTO_ICMP        1        /* control message protocol */
  44. #define    IPPROTO_GGP        3        /* gateway^2 (deprecated) */
  45. #define    IPPROTO_TCP        6        /* tcp */
  46. #define    IPPROTO_EGP        8        /* exterior gateway protocol */
  47. #define    IPPROTO_PUP        12        /* pup */
  48. #define    IPPROTO_UDP        17        /* user datagram protocol */
  49. #define    IPPROTO_IDP        22        /* xns idp */
  50.  
  51. #define    IPPROTO_RAW        255        /* raw IP packet */
  52. #define    IPPROTO_MAX        256
  53.  
  54. /*
  55.  * Port/socket numbers: network standard functions
  56.  */
  57. #define    IPPORT_ECHO        7
  58. #define    IPPORT_DISCARD        9
  59. #d@e    IPPORT_SYSTAT        11
  60. #define    IPPORT_DAYTIME        13
  61. #define    IPPORT_NETSTAT        15
  62. #define    IPPORT_FTP        21
  63. #define    IPPORT_TELNET        23
  64. #define    IPPORT_SMTP        25
  65. #define    IPPORT_TIMESERVER    37
  66. #define    IPPORT_NAMESERVER    42
  67. #define    IPPORT_WHOIS        43
  68. #define    IPPORT_MTP        57
  69.  
  70. /*
  71.  * Port/socket numbers: host specific functions
  72.  */
  73. #define    IPPORT_TFTP        69
  74. #define    IPPORT_RJE        77
  75. #define    IPPORT_FINGER        79
  76. #define    IPPORT_TTYLINK        87
  77. #define    IPPORT_SUPDUP        95
  78.  
  79. /*
  80.  * UNIX TCP sockets
  81.  */
  82. #define    IPPORT_EXECSERVER    512
  83. #define    IPPORT_LOGINSERVER    513
  84. #define    IPPORT_CMDSERVER    514
  85. #define    IPPORT_EFSSERVER    520
  86.  
  87. /*
  88.  * UNIX UDP sockets
  89.  */
  90. #define    IPPORT_BIFFUDP        512
  91. #define    IPPORT_WHOSERVER    513
  92. #define    IPPORT_ROUTESERVER    520    /* 520+1 also used */
  93.  
  94. /*
  95.  * Ports < IPPORT_RESERVED are reserved for
  96.  * privileged processes (e.g. root).
  97.  * Ports > IPPORT_USERRESERVED are reserved
  98.  * for servers, not necessarily privileged.
  99.  */
  100. #define    IPPORT_RESERVED        1024
  101. #define    IPPORT_USERRESERVED    5000
  102.  
  103. /*
  104.  * Link numbers
  105.  */
  106. #define    IMPLINK_IP        155
  107. #define    IMPLINK_LOWEXPER    156
  108. #define    IMPLINK_HIGHEXPER    158
  109.  
  110. /*
  111.  * Internet address (a structure for historical reasons)
  112.  */
  113. struct in_addr {
  114. #if    NeXT
  115.     union {
  116.         struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
  117.         struct { u_short s_w1,s_w2; } S_un_w;
  118.         u_long S_addr;
  119.     } S_un;
  120. #define    s_addr    S_un.S_addr    /* can be used for most tcp & ip code */
  121. #define    s_host    S_un.S_un_b.s_b2    /* host on imp */
  122. #define    s_net    S_un.S_un_b.s_b1    /* network */
  123. #define    s_imp    S_un.S_un_w.s_w2    /* imp */
  124. #define    s_impno    S_un.S_un_b.s_b4    /* imp # */
  125. #define    s_lh    S_un.S_un_b.s_b3    /* logical host */
  126. #else    NeXT
  127.     u_long s_addr;
  128. #endif    NeXT
  129. };
  130.  
  131. /*
  132.  * Definitions of bits in internet address integers.
  133.  * On subnets, the decomposition of addresses to host and net parts
  134.  * is done according to subnet mask, not the masks here.
  135.  */
  136. #define    IN_CLASSA(i)        (((long)(i) & 0x80000000) == 0)
  137. #define    IN_CLASSA_NET        0xff000000
  138. #define    IN_CLASSA_NSHIFT    24
  139. #define    IN_CLASSA_HOST        0x00ffffff
  140. #define    IN_CLASSA_MAX        128
  141.  
  142. #define    IN_CLASSB(i)        (((long)(i) & 0xc0000000) == 0x80000000)
  143. #define    IN_CLASSB_NET        0xffff0000
  144. #define    IN_CLASSB_NSHIFT    16
  145. #define    IN_CLASSB_HOST        0x0000ffff
  146. #define    IN_CLASSB_MAX        65536
  147.  
  148. #define    IN_CLASSC(i)        (((long)(i) & 0xe0000000) == 0xc0000000)
  149. #define    IN_CLASSC_NET        0xffffff00
  150. #define    IN_CLASSC_NSHIFT    8
  151. #define    IN_CLASSC_HOST        0x000000ff
  152.  
  153. #define    IN_@SD(i)        (((long)(i) & 0xf0000000) == 0xe0000000)
  154. #define    IN_MULTICAST(i)        IN_CLASSD(i)
  155.  
  156. #define    IN_EXPERIMENTAL(i)    (((long)(i) & 0xe0000000) == 0xe0000000)
  157. #define    IN_BADCLASS(i)        (((long)(i) & 0xf0000000) == 0xf0000000)
  158.  
  159. #define    INADDR_ANY        (u_long)0x00000000
  160. #define INADDR_LOOPBACK        (u_long)0x7f000001
  161. #define    INADDR_BROADCAST    (u_long)0xffffffff    /* must be masked */
  162. #ifndef KERNEL
  163. #define    INADDR_NONE        0xffffffff        /* -1 return */
  164. #endif
  165.  
  166. #define    IN_LOOPBACKNET        127            /* official! */
  167.  
  168. /*
  169.  * Define a macro to stuff the loopback address into an Internet address
  170.  */
  171. #define IN_SET_LOOPBACK_ADDR(a)    {(a)->sin_addr.s_addr  = htonl(INADDR_LOOPBACK); \
  172.     (a)->sin_family = AF_INET;}
  173.  
  174. /*
  175.  * Socket address, internet style.
  176.  */
  177. struct sockaddr_in {
  178.     short    sin_family;
  179.     u_short    sin_port;
  180.     struct    in_addr sin_addr;
  181.     char    sin_zero[8];
  182. };
  183.  
  184. /*
  185.  * Options for use with [gs]etsockopt at the IP level.
  186.  */
  187. #define    IP_OPTIONS    1        /* set/get IP per-packet options */
  188. #define    IP_TIMETOLIVE    2        /* set/get IP time-to-live value */
  189.  
  190. #ifdef KERNEL
  191. #if !defined(vax) && !defined(balance) && !defined(ntohl) && !defined(lint)
  192. /*
  193.  * Macros for number representation conversion.
  194.  */
  195. #if !defined(ns32000)
  196. #define    ntohl(x)    (x)
  197. #define    ntohs(x)    (x)
  198. #define    htonl(x)    (x)
  199. #define    htons(x)    (x)
  200. #else ns32000
  201. /* VAX does these in assembler (sed/inline).  Perhaps we will also someday. */
  202. #define ntohl(x)    ((0xff & (x)>>24) | (0xff00 & (x)>>8) | \
  203.             (0xff0000 & (x)<<8) | (0xff000000 & (x)<<24))
  204. #define ntohs(x)    ((0xff & (x)>>8) | (0xff00 & (x)<<8))
  205. #define htonl(x)    ntohl(x)
  206. #define htons(x)    ntohs(x)
  207. #endif    ns32000
  208. #endif    vax
  209.  
  210. #if !defined(ntohl) && (defined(vax) || defined (balance) || defined(lint))
  211. u_short    ntohs(), htons();
  212. u_long    ntohl(), htonl();
  213. #endif
  214.  
  215. #ifdef    KERNEL
  216. extern    struct domain inetdomain;
  217. extern    struct protosw inetsw[];
  218. struct    in_addr in_makeaddr();
  219. u_long    in_netof(), in_lnaof();
  220. #endif
  221. #endif    KERNEL
  222. #endif    _IN_
  223.