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