home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Headers / bsd / netinet / in.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-27  |  6.4 KB  |  228 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.  * 11-Jul-93  Mac Gillon (mgillon) at NeXT
  21.  *    Integrated MULTICAST support
  22.  *
  23.  * 26-Sep-89  Morris Meyer (mmeyer) at NeXT
  24.  *    NFS 4.0 Changes: Added definition of official port numbers.
  25.  */ 
  26.  
  27. #ifndef    _IN_
  28. #define    _IN_
  29.  
  30. #ifdef    KERNEL
  31. #include <sys/protosw.h>
  32. #include <sys/domain.h>
  33. #include <bsd/machine/endian.h>
  34. #endif    KERNEL
  35.  
  36. /*  @(#)in.h    2.2 88/06/10 4.0NFSSRC; from    7.1 (Berkeley) 6/5/86 */
  37.  
  38. /*
  39.  * Constants and structures defined by the internet system,
  40.  * Per RFC 790, September 1981.
  41.  */
  42.  
  43. /*
  44.  * Protocols
  45.  */
  46. #define    IPPROTO_IP        0        /* dummy for IP */
  47. #define    IPPROTO_ICMP        1        /* control message protocol */
  48. #define    IPPROTO_IGMP        2        /* group mgmt protocol */
  49. #define    IPPROTO_GGP        3        /* gateway^2 (deprecated) */
  50. #define    IPPROTO_TCP        6        /* tcp */
  51. #define    IPPROTO_EGP        8        /* exterior gateway protocol */
  52. #define    IPPROTO_PUP        12        /* pup */
  53. #define    IPPROTO_UDP        17        /* user datagram protocol */
  54. #define    IPPROTO_IDP        22        /* xns idp */
  55.  
  56. #define    IPPROTO_RAW        255        /* raw IP packet */
  57. #define    IPPROTO_MAX        256
  58.  
  59. /*
  60.  * Port/socket numbers: network standard functions
  61.  */
  62. #define    IPPORT_ECHO        7
  63. #define    IPPORT_DISCARD        9
  64. #define    IPPORT_SYSTAT        11
  65. #define    IPPORT_DAYTIME        13
  66. #define    IPPORT_NETSTAT        15
  67. #define    IPPORT_FTP        21
  68. #define    IPPORT_TELNET        23
  69. #define    IPPORT_SMTP        25
  70. #define    IPPORT_TIMESERVER    37
  71. #define    IPPORT_NAMESERVER    42
  72. #define    IPPORT_WHOIS        43
  73. #define    IPPORT_MTP        57
  74.  
  75. /*
  76.  * Port/socket numbers: host specific functions
  77.  */
  78. #define    IPPORT_TFTP        69
  79. #define    IPPORT_RJE        77
  80. #define    IPPORT_FINGER        79
  81. #define    IPPORT_TTYLINK        87
  82. #define    IPPORT_SUPDUP        95
  83.  
  84. /*
  85.  * UNIX TCP sockets
  86.  */
  87. #define    IPPORT_EXECSERVER    512
  88. #define    IPPORT_LOGINSERVER    513
  89. #define    IPPORT_CMDSERVER    514
  90. #define    IPPORT_EFSSERVER    520
  91.  
  92. /*
  93.  * UNIX UDP sockets
  94.  */
  95. #define    IPPORT_BIFFUDP        512
  96. #define    IPPORT_WHOSERVER    513
  97. #define    IPPORT_ROUTESERVER    520    /* 520+1 also used */
  98.  
  99. /*
  100.  * Ports < IPPORT_RESERVED are reserved for
  101.  * privileged processes (e.g. root).
  102.  * Ports > IPPORT_USERRESERVED are reserved
  103.  * for servers, not necessarily privileged.
  104.  */
  105. #define    IPPORT_RESERVED        1024
  106. #define    IPPORT_USERRESERVED    5000
  107.  
  108. /*
  109.  * Link numbers
  110.  */
  111. #define    IMPLINK_IP        155
  112. #define    IMPLINK_LOWEXPER    156
  113. #define    IMPLINK_HIGHEXPER    158
  114.  
  115. /*
  116.  * Internet address (a structure for historical reasons)
  117.  */
  118. struct in_addr {
  119. #if    NeXT
  120.     union {
  121.         struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
  122.         struct { u_short s_w1,s_w2; } S_un_w;
  123.         u_long S_addr;
  124.     } S_un;
  125. #define    s_addr    S_un.S_addr    /* can be used for most tcp & ip code */
  126. #define    s_host    S_un.S_un_b.s_b2    /* host on imp */
  127. #define    s_net    S_un.S_un_b.s_b1    /* network */
  128. #define    s_imp    S_un.S_un_w.s_w2    /* imp */
  129. #define    s_impno    S_un.S_un_b.s_b4    /* imp # */
  130. #define    s_lh    S_un.S_un_b.s_b3    /* logical host */
  131. #else    NeXT
  132.     u_long s_addr;
  133. #endif    NeXT
  134. };
  135.  
  136. /*
  137.  * Definitions of bits in internet address integers.
  138.  * On subnets, the decomposition of addresses to host and net parts
  139.  * is done according to subnet mask, not the masks here.
  140.  */
  141. #define    IN_CLASSA(i)        (((long)(i) & 0x80000000) == 0)
  142. #define    IN_CLASSA_NET        0xff000000
  143. #define    IN_CLASSA_NSHIFT    24
  144. #define    IN_CLASSA_HOST        0x00ffffff
  145. #define    IN_CLASSA_MAX        128
  146.  
  147. #define    IN_CLASSB(i)        (((long)(i) & 0xc0000000) == 0x80000000)
  148. #define    IN_CLASSB_NET        0xffff0000
  149. #define    IN_CLASSB_NSHIFT    16
  150. #define    IN_CLASSB_HOST        0x0000ffff
  151. #define    IN_CLASSB_MAX        65536
  152.  
  153. #define    IN_CLASSC(i)        (((long)(i) & 0xe0000000) == 0xc0000000)
  154. #define    IN_CLASSC_NET        0xffffff00
  155. #define    IN_CLASSC_NSHIFT    8
  156. #define    IN_CLASSC_HOST        0x000000ff
  157.  
  158. #define    IN_CLASSD(i)        (((long)(i) & 0xf0000000) == 0xe0000000)
  159. #define    IN_CLASSD_NET        0xf0000000    /* These ones aren't really */
  160. #define    IN_CLASSD_NSHIFT    28        /* net and host fields, but */
  161. #define    IN_CLASSD_HOST        0x0fffffff    /* routing needn't know.    */
  162. #define    IN_MULTICAST(i)        IN_CLASSD(i)
  163.  
  164. #define    IN_EXPERIMENTAL(i)    (((long)(i) & 0xe0000000) == 0xe0000000)
  165. #define    IN_BADCLASS(i)        (((long)(i) & 0xf0000000) == 0xf0000000)
  166.  
  167. #define    INADDR_ANY        (u_long)0x00000000
  168. #define INADDR_LOOPBACK        (u_long)0x7f000001
  169. #define    INADDR_BROADCAST    (u_long)0xffffffff    /* must be masked */
  170.  
  171. #define    INADDR_UNSPEC_GROUP    (u_long)0xe0000000    /* 224.0.0.0   */
  172. #define    INADDR_ALLHOSTS_GROUP    (u_long)0xe0000001    /* 224.0.0.1   */
  173. #define    INADDR_MAX_LOCAL_GROUP     (u_long)0xe00000ff    /* 224.0.0.255 */
  174.  
  175. #ifndef KERNEL
  176. #define    INADDR_NONE        0xffffffff        /* -1 return */
  177. #endif
  178.  
  179. #define    IN_LOOPBACKNET        127            /* official! */
  180.  
  181. /*
  182.  * Define a macro to stuff the loopback address into an Internet address
  183.  */
  184. #define IN_SET_LOOPBACK_ADDR(a)    {(a)->sin_addr.s_addr  = htonl(INADDR_LOOPBACK); \
  185.     (a)->sin_family = AF_INET;}
  186.  
  187. /*
  188.  * Socket address, internet style.
  189.  */
  190. struct sockaddr_in {
  191.     short    sin_family;
  192.     u_short    sin_port;
  193.     struct    in_addr sin_addr;
  194.     char    sin_zero[8];
  195. };
  196.  
  197. /*
  198.  * Options for use with [gs]etsockopt at the IP level.
  199.  */
  200. #define    IP_OPTIONS        1    /* set/get IP per-packet options */
  201. #define    IP_TIMETOLIVE        2    /* set/get IP time-to-live value */
  202. #define    IP_MULTICAST_IF        3    /* set/get IP multicast interface  */
  203. #define    IP_MULTICAST_TTL    4    /* set/get IP multicast timetolive */
  204. #define    IP_MULTICAST_LOOP    5    /* set/get IP multicast loopback   */
  205. #define    IP_ADD_MEMBERSHIP    6    /* add  an IP group membership     */
  206. #define    IP_DROP_MEMBERSHIP    7    /* drop an IP group membership     */
  207.  
  208. #define    IP_DEFAULT_MULTICAST_TTL   1    /* normally limit m'casts to 1 hop  */
  209. #define    IP_DEFAULT_MULTICAST_LOOP  1    /* normally hear sends if a member  */
  210. #define    IP_MAX_MEMBERSHIPS         20    /* per socket; must fit in one mbuf */
  211.  
  212. /*
  213.  * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
  214.  */
  215. struct ip_mreq {
  216.     struct in_addr    imr_multiaddr;    /* IP multicast address of group */
  217.     struct in_addr    imr_interface;    /* local IP address of interface */
  218. };
  219.  
  220. #ifdef    KERNEL
  221. extern    struct domain inetdomain;
  222. extern    struct protosw inetsw[];
  223. struct    in_addr in_makeaddr();
  224. u_long    in_netof(), in_lnaof();
  225. #endif
  226.  
  227. #endif    _IN_
  228.