10Sstevel@tonic-gate /* 2*5577Ssangeeta * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 3*5577Ssangeeta * Use is subject to license terms. 4*5577Ssangeeta * 50Sstevel@tonic-gate * Copyright (c) 1982, 1986 Regents of the University of California. 60Sstevel@tonic-gate * All rights reserved. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * Redistribution and use in source and binary forms are permitted 90Sstevel@tonic-gate * provided that this notice is preserved and that due credit is given 100Sstevel@tonic-gate * to the University of California at Berkeley. The name of the University 110Sstevel@tonic-gate * may not be used to endorse or promote products derived from this 120Sstevel@tonic-gate * software without specific prior written permission. This software 130Sstevel@tonic-gate * is provided ``as is'' without express or implied warranty. 140Sstevel@tonic-gate */ 150Sstevel@tonic-gate 160Sstevel@tonic-gate /* 170Sstevel@tonic-gate * Constants and structures defined by the internet system, 180Sstevel@tonic-gate * Per RFC 790, September 1981. 190Sstevel@tonic-gate */ 200Sstevel@tonic-gate 210Sstevel@tonic-gate #ifndef _netinet_in_h 22*5577Ssangeeta #define _netinet_in_h 230Sstevel@tonic-gate 240Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* 270Sstevel@tonic-gate * Protocols 280Sstevel@tonic-gate */ 290Sstevel@tonic-gate #define IPPROTO_IP 0 /* dummy for IP */ 300Sstevel@tonic-gate #define IPPROTO_ICMP 1 /* control message protocol */ 310Sstevel@tonic-gate #define IPPROTO_IGMP 2 /* group control protocol */ 320Sstevel@tonic-gate #define IPPROTO_GGP 3 /* gateway^2 (deprecated) */ 330Sstevel@tonic-gate #define IPPROTO_TCP 6 /* tcp */ 340Sstevel@tonic-gate #define IPPROTO_EGP 8 /* exterior gateway protocol */ 350Sstevel@tonic-gate #define IPPROTO_PUP 12 /* pup */ 360Sstevel@tonic-gate #define IPPROTO_UDP 17 /* user datagram protocol */ 370Sstevel@tonic-gate #define IPPROTO_IDP 22 /* xns idp */ 380Sstevel@tonic-gate #define IPPROTO_HELLO 63 /* "hello" routing protocol */ 390Sstevel@tonic-gate #define IPPROTO_ND 77 /* UNOFFICIAL net disk proto */ 400Sstevel@tonic-gate 410Sstevel@tonic-gate #define IPPROTO_RAW 255 /* raw IP packet */ 420Sstevel@tonic-gate #define IPPROTO_MAX 256 430Sstevel@tonic-gate 440Sstevel@tonic-gate /* 450Sstevel@tonic-gate * Port/socket numbers: network standard functions 460Sstevel@tonic-gate */ 470Sstevel@tonic-gate #define IPPORT_ECHO 7 480Sstevel@tonic-gate #define IPPORT_DISCARD 9 490Sstevel@tonic-gate #define IPPORT_SYSTAT 11 500Sstevel@tonic-gate #define IPPORT_DAYTIME 13 510Sstevel@tonic-gate #define IPPORT_NETSTAT 15 520Sstevel@tonic-gate #define IPPORT_FTP 21 530Sstevel@tonic-gate #define IPPORT_TELNET 23 540Sstevel@tonic-gate #define IPPORT_SMTP 25 550Sstevel@tonic-gate #define IPPORT_TIMESERVER 37 560Sstevel@tonic-gate #define IPPORT_NAMESERVER 42 570Sstevel@tonic-gate #define IPPORT_WHOIS 43 580Sstevel@tonic-gate #define IPPORT_MTP 57 590Sstevel@tonic-gate 600Sstevel@tonic-gate /* 610Sstevel@tonic-gate * Port/socket numbers: host specific functions 620Sstevel@tonic-gate */ 630Sstevel@tonic-gate #define IPPORT_TFTP 69 640Sstevel@tonic-gate #define IPPORT_RJE 77 650Sstevel@tonic-gate #define IPPORT_FINGER 79 660Sstevel@tonic-gate #define IPPORT_TTYLINK 87 670Sstevel@tonic-gate #define IPPORT_SUPDUP 95 680Sstevel@tonic-gate 690Sstevel@tonic-gate /* 700Sstevel@tonic-gate * UNIX TCP sockets 710Sstevel@tonic-gate */ 720Sstevel@tonic-gate #define IPPORT_EXECSERVER 512 730Sstevel@tonic-gate #define IPPORT_LOGINSERVER 513 740Sstevel@tonic-gate #define IPPORT_CMDSERVER 514 750Sstevel@tonic-gate #define IPPORT_EFSSERVER 520 760Sstevel@tonic-gate 770Sstevel@tonic-gate /* 780Sstevel@tonic-gate * UNIX UDP sockets 790Sstevel@tonic-gate */ 800Sstevel@tonic-gate #define IPPORT_BIFFUDP 512 810Sstevel@tonic-gate #define IPPORT_WHOSERVER 513 820Sstevel@tonic-gate #define IPPORT_ROUTESERVER 520 /* 520+1 also used */ 830Sstevel@tonic-gate 840Sstevel@tonic-gate /* 850Sstevel@tonic-gate * Ports < IPPORT_RESERVED are reserved for 860Sstevel@tonic-gate * privileged processes (e.g. root). 870Sstevel@tonic-gate * Ports > IPPORT_USERRESERVED are reserved 880Sstevel@tonic-gate * for servers, not necessarily privileged. 890Sstevel@tonic-gate */ 900Sstevel@tonic-gate #define IPPORT_RESERVED 1024 910Sstevel@tonic-gate #define IPPORT_USERRESERVED 5000 920Sstevel@tonic-gate 930Sstevel@tonic-gate /* 940Sstevel@tonic-gate * Link numbers 950Sstevel@tonic-gate */ 960Sstevel@tonic-gate #define IMPLINK_IP 155 970Sstevel@tonic-gate #define IMPLINK_LOWEXPER 156 980Sstevel@tonic-gate #define IMPLINK_HIGHEXPER 158 990Sstevel@tonic-gate 1000Sstevel@tonic-gate /* 1010Sstevel@tonic-gate * Internet address 1020Sstevel@tonic-gate * This definition contains obsolete fields for compatibility 1030Sstevel@tonic-gate * with SunOS 3.x and 4.2bsd. The presence of subnets renders 1040Sstevel@tonic-gate * divisions into fixed fields misleading at best. New code 1050Sstevel@tonic-gate * should use only the s_addr field. 1060Sstevel@tonic-gate */ 1070Sstevel@tonic-gate struct in_addr { 1080Sstevel@tonic-gate union { 1090Sstevel@tonic-gate struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b; 1100Sstevel@tonic-gate struct { u_short s_w1,s_w2; } S_un_w; 1110Sstevel@tonic-gate u_long S_addr; 1120Sstevel@tonic-gate } S_un; 1130Sstevel@tonic-gate #define s_addr S_un.S_addr /* should be used for all code */ 1140Sstevel@tonic-gate #define s_host S_un.S_un_b.s_b2 /* OBSOLETE: host on imp */ 1150Sstevel@tonic-gate #define s_net S_un.S_un_b.s_b1 /* OBSOLETE: network */ 1160Sstevel@tonic-gate #define s_imp S_un.S_un_w.s_w2 /* OBSOLETE: imp */ 1170Sstevel@tonic-gate #define s_impno S_un.S_un_b.s_b4 /* OBSOLETE: imp # */ 1180Sstevel@tonic-gate #define s_lh S_un.S_un_b.s_b3 /* OBSOLETE: logical host */ 1190Sstevel@tonic-gate }; 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate /* 1220Sstevel@tonic-gate * Definitions of bits in internet address integers. 1230Sstevel@tonic-gate * On subnets, the decomposition of addresses to host and net parts 1240Sstevel@tonic-gate * is done according to subnet mask, not the masks here. 125*5577Ssangeeta * 126*5577Ssangeeta * Note that with the introduction of CIDR, IN_CLASSA, IN_CLASSB, 127*5577Ssangeeta * IN_CLASSC, IN_CLASSD and IN_CLASSE macros have become "de-facto obsolete". 128*5577Ssangeeta * IN_MULTICAST macro should be used to test if a address is a 129*5577Ssangeeta * multicast address. 1300Sstevel@tonic-gate */ 1310Sstevel@tonic-gate #define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0) 1320Sstevel@tonic-gate #define IN_CLASSA_NET 0xff000000 1330Sstevel@tonic-gate #define IN_CLASSA_NSHIFT 24 1340Sstevel@tonic-gate #define IN_CLASSA_HOST 0x00ffffff 1350Sstevel@tonic-gate #define IN_CLASSA_MAX 128 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate #define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000) 1380Sstevel@tonic-gate #define IN_CLASSB_NET 0xffff0000 1390Sstevel@tonic-gate #define IN_CLASSB_NSHIFT 16 1400Sstevel@tonic-gate #define IN_CLASSB_HOST 0x0000ffff 1410Sstevel@tonic-gate #define IN_CLASSB_MAX 65536 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate #define IN_CLASSC(i) (((long)(i) & 0xe0000000) == 0xc0000000) 1440Sstevel@tonic-gate #define IN_CLASSC_NET 0xffffff00 1450Sstevel@tonic-gate #define IN_CLASSC_NSHIFT 8 1460Sstevel@tonic-gate #define IN_CLASSC_HOST 0x000000ff 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate #define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000) 1490Sstevel@tonic-gate #define IN_MULTICAST(i) IN_CLASSD(i) 1500Sstevel@tonic-gate 151*5577Ssangeeta #define IN_CLASSE(i) (((long)(i) & 0xf0000000) == 0xf0000000) 152*5577Ssangeeta 153*5577Ssangeeta #define IN_CLASSE_NET 0xffffffff 154*5577Ssangeeta 155*5577Ssangeeta /* 156*5577Ssangeeta * We have removed CLASS E checks from the kernel 157*5577Ssangeeta * But we preserve these defines for userland in order 158*5577Ssangeeta * to avoid compile breakage of some 3rd party piece of software 159*5577Ssangeeta */ 160*5577Ssangeeta #ifndef KERNEL 1610Sstevel@tonic-gate #define IN_EXPERIMENTAL(i) (((long)(i) & 0xe0000000) == 0xe0000000) 1620Sstevel@tonic-gate #define IN_BADCLASS(i) (((long)(i) & 0xf0000000) == 0xf0000000) 163*5577Ssangeeta #endif 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate #define INADDR_ANY (u_long)0x00000000 1660Sstevel@tonic-gate #define INADDR_LOOPBACK (u_long)0x7F000001 1670Sstevel@tonic-gate #define INADDR_BROADCAST (u_long)0xffffffff /* must be masked */ 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate #define IN_LOOPBACKNET 127 /* official! */ 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate /* 1720Sstevel@tonic-gate * Define a macro to stuff the loopback address into an Internet address 1730Sstevel@tonic-gate */ 1740Sstevel@tonic-gate #define IN_SET_LOOPBACK_ADDR(a) {(a)->sin_addr.s_addr = htonl(INADDR_LOOPBACK); \ 1750Sstevel@tonic-gate (a)->sin_family = AF_INET;} 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate /* 1780Sstevel@tonic-gate * Socket address, internet style. 1790Sstevel@tonic-gate */ 1800Sstevel@tonic-gate struct sockaddr_in { 1810Sstevel@tonic-gate short sin_family; 1820Sstevel@tonic-gate u_short sin_port; 1830Sstevel@tonic-gate struct in_addr sin_addr; 1840Sstevel@tonic-gate char sin_zero[8]; 1850Sstevel@tonic-gate }; 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate /* 1880Sstevel@tonic-gate * Options for use with [gs]etsockopt at the IP level. 1890Sstevel@tonic-gate */ 1900Sstevel@tonic-gate #define IP_OPTIONS 1 /* set/get IP per-packet options */ 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate #if !defined(vax) && !defined(ntohl) && !defined(lint) && !defined(i386) 1930Sstevel@tonic-gate /* 1940Sstevel@tonic-gate * Macros for number representation conversion. 1950Sstevel@tonic-gate */ 1960Sstevel@tonic-gate #define ntohl(x) (x) 1970Sstevel@tonic-gate #define ntohs(x) (x) 1980Sstevel@tonic-gate #define htonl(x) (x) 1990Sstevel@tonic-gate #define htons(x) (x) 2000Sstevel@tonic-gate #endif 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate #if !defined(ntohl) && (defined(vax) || defined(lint) || defined(i386)) 2030Sstevel@tonic-gate u_short ntohs(), htons(); 2040Sstevel@tonic-gate u_long ntohl(), htonl(); 2050Sstevel@tonic-gate #endif 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate #ifdef KERNEL 2080Sstevel@tonic-gate extern struct domain inetdomain; 2090Sstevel@tonic-gate extern struct protosw inetsw[]; 2100Sstevel@tonic-gate struct in_addr in_makeaddr(); 2110Sstevel@tonic-gate u_long in_netof(), in_lnaof(); 2120Sstevel@tonic-gate #endif 2130Sstevel@tonic-gate 214*5577Ssangeeta #endif /* !_netinet_in_h */ 215