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