1 #ifndef __netinet_in__ 2 #define __netinet_in__ 3 4 #ifdef __cplusplus 5 extern "C" { 6 #endif 7 8 /* 9 * Copyright (c) 1982, 1986, 1990 Regents of the University of California. 10 * All rights reserved. 11 * 12 * Redistribution is only permitted until one year after the first shipment 13 * of 4.4BSD by the Regents. Otherwise, redistribution and use in source and 14 * binary forms are permitted provided that: (1) source distributions retain 15 * this entire copyright notice and comment, and (2) distributions including 16 * binaries display the following acknowledgement: This product includes 17 * software developed by the University of California, Berkeley and its 18 * contributors'' in the documentation or other materials provided with the 19 * distribution and in all advertising materials mentioning features or use 20 * of this software. Neither the name of the University nor the names of 21 * its contributors may be used to endorse or promote products derived from 22 * this software without specific prior written permission. 23 * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 24 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 26 * 27 * @(#)in.h 7.10 (Berkeley) 6/28/90 plus MULTICAST 1.1 28 */ 29 30 /* 31 * Constants and structures defined by the internet system, 32 * Per RFC 790, September 1981. 33 */ 34 35 /* 36 * Protocols 37 */ 38 #define IPPROTO_IP 0 /* dummy for IP */ 39 #define IPPROTO_ICMP 1 /* control message protocol */ 40 #define IPPROTO_GGP 3 /* gateway^2 (deprecated) */ 41 #define IPPROTO_TCP 6 /* tcp */ 42 #define IPPROTO_EGP 8 /* exterior gateway protocol */ 43 #define IPPROTO_PUP 12 /* pup */ 44 #define IPPROTO_UDP 17 /* user datagram protocol */ 45 #define IPPROTO_IDP 22 /* xns idp */ 46 #define IPPROTO_TP 29 /* tp-4 w/ class negotiation */ 47 #define IPPROTO_EON 80 /* ISO cnlp */ 48 49 #define IPPROTO_RAW 255 /* raw IP packet */ 50 #define IPPROTO_MAX 256 51 52 53 /* 54 * Local port number conventions: 55 * Ports < IPPORT_RESERVED are reserved for 56 * privileged processes (e.g. root). 57 * Ports > IPPORT_USERRESERVED are reserved 58 * for servers, not necessarily privileged. 59 */ 60 #define IPPORT_RESERVED 1024 61 #define IPPORT_USERRESERVED 5000 62 63 /* 64 * Internet address (a structure for historical reasons) 65 */ 66 struct in_addr { 67 unsigned long s_addr; 68 }; 69 70 /* 71 * Definitions of bits in internet address integers. 72 * On subnets, the decomposition of addresses to host and net parts 73 * is done according to subnet mask, not the masks here. 74 */ 75 #define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0) 76 #define IN_CLASSA_NET 0xff000000 77 #define IN_CLASSA_NSHIFT 24 78 #define IN_CLASSA_HOST 0x00ffffff 79 #define IN_CLASSA_MAX 128 80 81 #define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000) 82 #define IN_CLASSB_NET 0xffff0000 83 #define IN_CLASSB_NSHIFT 16 84 #define IN_CLASSB_HOST 0x0000ffff 85 #define IN_CLASSB_MAX 65536 86 87 #define IN_CLASSC(i) (((long)(i) & 0xe0000000) == 0xc0000000) 88 #define IN_CLASSC_NET 0xffffff00 89 #define IN_CLASSC_NSHIFT 8 90 #define IN_CLASSC_HOST 0x000000ff 91 92 #define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000) 93 #define IN_MULTICAST(i) IN_CLASSD(i) 94 95 #define IN_EXPERIMENTAL(i) (((long)(i) & 0xe0000000) == 0xe0000000) 96 #define IN_BADCLASS(i) (((long)(i) & 0xf0000000) == 0xf0000000) 97 98 #define INADDR_ANY (unsigned long)0x00000000 99 #define INADDR_BROADCAST (unsigned long)0xffffffff /* must be masked */ 100 #define INADDR_NONE (unsigned long)0xffffffff /* -1 return */ 101 102 #define IN_LOOPBACKNET 127 /* official! */ 103 104 /* 105 * Socket address, internet style. 106 */ 107 struct sockaddr_in { 108 short sin_family; 109 unsigned short sin_port; 110 struct in_addr sin_addr; 111 char sin_zero[8]; 112 }; 113 114 /* 115 * Structure used to describe IP options. 116 * Used to store options internally, to pass them to a process, 117 * or to restore options retrieved earlier. 118 * The ip_dst is used for the first-hop gateway when using a source route 119 * (this gets put into the header proper). 120 */ 121 struct ip_opts { 122 struct in_addr ip_dst; /* first hop, 0 w/o src rt */ 123 char ip_opts[40]; /* actually variable in size */ 124 }; 125 126 /* 127 * Options for use with [gs]etsockopt at the IP level. 128 * First word of comment is data type; bool is stored in int. 129 */ 130 #define IP_OPTIONS 1 /* buf/ip_opts; set/get IP per-packet options */ 131 #define IP_HDRINCL 7 /* int; header is included with data (raw) */ 132 #define IP_TOS 8 /* int; IP type of service and precedence */ 133 #define IP_TTL 9 /* int; IP time to live */ 134 135 extern unsigned long ntohl(unsigned long x); 136 extern unsigned short ntohs(unsigned short x); 137 extern unsigned long htonl(unsigned long x); 138 extern unsigned short htons(unsigned short x); 139 extern unsigned long inet_addr(char*); 140 extern char* inet_ntoa(struct in_addr); 141 extern unsigned long nptohl(void*); 142 143 #ifdef __cplusplus 144 } 145 #endif 146 147 #endif /* __netinet_in__ */ 148