17c478bd9Sstevel@tonic-gate /* 2*2a9459bdSsangeeta * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 3*2a9459bdSsangeeta * Use is subject to license terms. 4*2a9459bdSsangeeta * 57c478bd9Sstevel@tonic-gate * Copyright (c) 1982, 1986 Regents of the University of California. 67c478bd9Sstevel@tonic-gate * All rights reserved. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * Redistribution and use in source and binary forms are permitted 97c478bd9Sstevel@tonic-gate * provided that this notice is preserved and that due credit is given 107c478bd9Sstevel@tonic-gate * to the University of California at Berkeley. The name of the University 117c478bd9Sstevel@tonic-gate * may not be used to endorse or promote products derived from this 127c478bd9Sstevel@tonic-gate * software without specific prior written permission. This software 137c478bd9Sstevel@tonic-gate * is provided ``as is'' without express or implied warranty. 147c478bd9Sstevel@tonic-gate */ 157c478bd9Sstevel@tonic-gate 167c478bd9Sstevel@tonic-gate /* 177c478bd9Sstevel@tonic-gate * Constants and structures defined by the internet system, 187c478bd9Sstevel@tonic-gate * Per RFC 790, September 1981. 197c478bd9Sstevel@tonic-gate */ 207c478bd9Sstevel@tonic-gate 217c478bd9Sstevel@tonic-gate #ifndef _netinet_in_h 227c478bd9Sstevel@tonic-gate #define _netinet_in_h 237c478bd9Sstevel@tonic-gate 247c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* 277c478bd9Sstevel@tonic-gate * Protocols 287c478bd9Sstevel@tonic-gate */ 297c478bd9Sstevel@tonic-gate #define IPPROTO_IP 0 /* dummy for IP */ 307c478bd9Sstevel@tonic-gate #define IPPROTO_ICMP 1 /* control message protocol */ 317c478bd9Sstevel@tonic-gate #define IPPROTO_IGMP 2 /* group control protocol */ 327c478bd9Sstevel@tonic-gate #define IPPROTO_GGP 3 /* gateway^2 (deprecated) */ 337c478bd9Sstevel@tonic-gate #define IPPROTO_TCP 6 /* tcp */ 347c478bd9Sstevel@tonic-gate #define IPPROTO_EGP 8 /* exterior gateway protocol */ 357c478bd9Sstevel@tonic-gate #define IPPROTO_PUP 12 /* pup */ 367c478bd9Sstevel@tonic-gate #define IPPROTO_UDP 17 /* user datagram protocol */ 377c478bd9Sstevel@tonic-gate #define IPPROTO_IDP 22 /* xns idp */ 387c478bd9Sstevel@tonic-gate #define IPPROTO_HELLO 63 /* "hello" routing protocol */ 397c478bd9Sstevel@tonic-gate #define IPPROTO_ND 77 /* UNOFFICIAL net disk proto */ 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate #define IPPROTO_RAW 255 /* raw IP packet */ 427c478bd9Sstevel@tonic-gate #define IPPROTO_MAX 256 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate /* 457c478bd9Sstevel@tonic-gate * Port/socket numbers: network standard functions 467c478bd9Sstevel@tonic-gate */ 477c478bd9Sstevel@tonic-gate #define IPPORT_ECHO 7 487c478bd9Sstevel@tonic-gate #define IPPORT_DISCARD 9 497c478bd9Sstevel@tonic-gate #define IPPORT_SYSTAT 11 507c478bd9Sstevel@tonic-gate #define IPPORT_DAYTIME 13 517c478bd9Sstevel@tonic-gate #define IPPORT_NETSTAT 15 527c478bd9Sstevel@tonic-gate #define IPPORT_FTP 21 537c478bd9Sstevel@tonic-gate #define IPPORT_TELNET 23 547c478bd9Sstevel@tonic-gate #define IPPORT_SMTP 25 557c478bd9Sstevel@tonic-gate #define IPPORT_TIMESERVER 37 567c478bd9Sstevel@tonic-gate #define IPPORT_NAMESERVER 42 577c478bd9Sstevel@tonic-gate #define IPPORT_WHOIS 43 587c478bd9Sstevel@tonic-gate #define IPPORT_MTP 57 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate /* 617c478bd9Sstevel@tonic-gate * Port/socket numbers: host specific functions 627c478bd9Sstevel@tonic-gate */ 637c478bd9Sstevel@tonic-gate #define IPPORT_TFTP 69 647c478bd9Sstevel@tonic-gate #define IPPORT_RJE 77 657c478bd9Sstevel@tonic-gate #define IPPORT_FINGER 79 667c478bd9Sstevel@tonic-gate #define IPPORT_TTYLINK 87 677c478bd9Sstevel@tonic-gate #define IPPORT_SUPDUP 95 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate /* 707c478bd9Sstevel@tonic-gate * UNIX TCP sockets 717c478bd9Sstevel@tonic-gate */ 727c478bd9Sstevel@tonic-gate #define IPPORT_EXECSERVER 512 737c478bd9Sstevel@tonic-gate #define IPPORT_LOGINSERVER 513 747c478bd9Sstevel@tonic-gate #define IPPORT_CMDSERVER 514 757c478bd9Sstevel@tonic-gate #define IPPORT_EFSSERVER 520 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate /* 787c478bd9Sstevel@tonic-gate * UNIX UDP sockets 797c478bd9Sstevel@tonic-gate */ 807c478bd9Sstevel@tonic-gate #define IPPORT_BIFFUDP 512 817c478bd9Sstevel@tonic-gate #define IPPORT_WHOSERVER 513 827c478bd9Sstevel@tonic-gate #define IPPORT_ROUTESERVER 520 /* 520+1 also used */ 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate /* 857c478bd9Sstevel@tonic-gate * Ports < IPPORT_RESERVED are reserved for 867c478bd9Sstevel@tonic-gate * privileged processes (e.g. root). 877c478bd9Sstevel@tonic-gate * Ports > IPPORT_USERRESERVED are reserved 887c478bd9Sstevel@tonic-gate * for servers, not necessarily privileged. 897c478bd9Sstevel@tonic-gate */ 907c478bd9Sstevel@tonic-gate #define IPPORT_RESERVED 1024 917c478bd9Sstevel@tonic-gate #define IPPORT_USERRESERVED 5000 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate /* 947c478bd9Sstevel@tonic-gate * Link numbers 957c478bd9Sstevel@tonic-gate */ 967c478bd9Sstevel@tonic-gate #define IMPLINK_IP 155 977c478bd9Sstevel@tonic-gate #define IMPLINK_LOWEXPER 156 987c478bd9Sstevel@tonic-gate #define IMPLINK_HIGHEXPER 158 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate /* 1017c478bd9Sstevel@tonic-gate * Internet address 1027c478bd9Sstevel@tonic-gate * This definition contains obsolete fields for compatibility 1037c478bd9Sstevel@tonic-gate * with SunOS 3.x and 4.2bsd. The presence of subnets renders 1047c478bd9Sstevel@tonic-gate * divisions into fixed fields misleading at best. New code 1057c478bd9Sstevel@tonic-gate * should use only the s_addr field. 1067c478bd9Sstevel@tonic-gate */ 1077c478bd9Sstevel@tonic-gate struct in_addr { 1087c478bd9Sstevel@tonic-gate union { 1097c478bd9Sstevel@tonic-gate struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b; 1107c478bd9Sstevel@tonic-gate struct { u_short s_w1,s_w2; } S_un_w; 1117c478bd9Sstevel@tonic-gate u_long S_addr; 1127c478bd9Sstevel@tonic-gate } S_un; 1137c478bd9Sstevel@tonic-gate #define s_addr S_un.S_addr /* should be used for all code */ 1147c478bd9Sstevel@tonic-gate #define s_host S_un.S_un_b.s_b2 /* OBSOLETE: host on imp */ 1157c478bd9Sstevel@tonic-gate #define s_net S_un.S_un_b.s_b1 /* OBSOLETE: network */ 1167c478bd9Sstevel@tonic-gate #define s_imp S_un.S_un_w.s_w2 /* OBSOLETE: imp */ 1177c478bd9Sstevel@tonic-gate #define s_impno S_un.S_un_b.s_b4 /* OBSOLETE: imp # */ 1187c478bd9Sstevel@tonic-gate #define s_lh S_un.S_un_b.s_b3 /* OBSOLETE: logical host */ 1197c478bd9Sstevel@tonic-gate }; 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate /* 1227c478bd9Sstevel@tonic-gate * Definitions of bits in internet address integers. 1237c478bd9Sstevel@tonic-gate * On subnets, the decomposition of addresses to host and net parts 1247c478bd9Sstevel@tonic-gate * is done according to subnet mask, not the masks here. 125*2a9459bdSsangeeta * 126*2a9459bdSsangeeta * Note that with the introduction of CIDR, IN_CLASSA, IN_CLASSB, 127*2a9459bdSsangeeta * IN_CLASSC, IN_CLASSD and IN_CLASSE macros have become "de-facto obsolete". 128*2a9459bdSsangeeta * IN_MULTICAST macro should be used to test if a address is a 129*2a9459bdSsangeeta * multicast address. 1307c478bd9Sstevel@tonic-gate */ 1317c478bd9Sstevel@tonic-gate #define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0) 1327c478bd9Sstevel@tonic-gate #define IN_CLASSA_NET 0xff000000 1337c478bd9Sstevel@tonic-gate #define IN_CLASSA_NSHIFT 24 1347c478bd9Sstevel@tonic-gate #define IN_CLASSA_HOST 0x00ffffff 1357c478bd9Sstevel@tonic-gate #define IN_CLASSA_MAX 128 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate #define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000) 1387c478bd9Sstevel@tonic-gate #define IN_CLASSB_NET 0xffff0000 1397c478bd9Sstevel@tonic-gate #define IN_CLASSB_NSHIFT 16 1407c478bd9Sstevel@tonic-gate #define IN_CLASSB_HOST 0x0000ffff 1417c478bd9Sstevel@tonic-gate #define IN_CLASSB_MAX 65536 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate #define IN_CLASSC(i) (((long)(i) & 0xe0000000) == 0xc0000000) 1447c478bd9Sstevel@tonic-gate #define IN_CLASSC_NET 0xffffff00 1457c478bd9Sstevel@tonic-gate #define IN_CLASSC_NSHIFT 8 1467c478bd9Sstevel@tonic-gate #define IN_CLASSC_HOST 0x000000ff 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate #define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000) 1497c478bd9Sstevel@tonic-gate #define IN_MULTICAST(i) IN_CLASSD(i) 1507c478bd9Sstevel@tonic-gate 151*2a9459bdSsangeeta #define IN_CLASSE(i) (((long)(i) & 0xf0000000) == 0xf0000000) 152*2a9459bdSsangeeta 153*2a9459bdSsangeeta #define IN_CLASSE_NET 0xffffffff 154*2a9459bdSsangeeta 155*2a9459bdSsangeeta /* 156*2a9459bdSsangeeta * We have removed CLASS E checks from the kernel 157*2a9459bdSsangeeta * But we preserve these defines for userland in order 158*2a9459bdSsangeeta * to avoid compile breakage of some 3rd party piece of software 159*2a9459bdSsangeeta */ 160*2a9459bdSsangeeta #ifndef KERNEL 1617c478bd9Sstevel@tonic-gate #define IN_EXPERIMENTAL(i) (((long)(i) & 0xe0000000) == 0xe0000000) 1627c478bd9Sstevel@tonic-gate #define IN_BADCLASS(i) (((long)(i) & 0xf0000000) == 0xf0000000) 163*2a9459bdSsangeeta #endif 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate #define INADDR_ANY (u_long)0x00000000 1667c478bd9Sstevel@tonic-gate #define INADDR_LOOPBACK (u_long)0x7F000001 1677c478bd9Sstevel@tonic-gate #define INADDR_BROADCAST (u_long)0xffffffff /* must be masked */ 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate #define IN_LOOPBACKNET 127 /* official! */ 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate /* 1727c478bd9Sstevel@tonic-gate * Define a macro to stuff the loopback address into an Internet address 1737c478bd9Sstevel@tonic-gate */ 1747c478bd9Sstevel@tonic-gate #define IN_SET_LOOPBACK_ADDR(a) {(a)->sin_addr.s_addr = htonl(INADDR_LOOPBACK); \ 1757c478bd9Sstevel@tonic-gate (a)->sin_family = AF_INET;} 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate /* 1787c478bd9Sstevel@tonic-gate * Socket address, internet style. 1797c478bd9Sstevel@tonic-gate */ 1807c478bd9Sstevel@tonic-gate struct sockaddr_in { 1817c478bd9Sstevel@tonic-gate short sin_family; 1827c478bd9Sstevel@tonic-gate u_short sin_port; 1837c478bd9Sstevel@tonic-gate struct in_addr sin_addr; 1847c478bd9Sstevel@tonic-gate char sin_zero[8]; 1857c478bd9Sstevel@tonic-gate }; 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate /* 1887c478bd9Sstevel@tonic-gate * Options for use with [gs]etsockopt at the IP level. 1897c478bd9Sstevel@tonic-gate */ 1907c478bd9Sstevel@tonic-gate #define IP_OPTIONS 1 /* set/get IP per-packet options */ 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate #if !defined(vax) && !defined(ntohl) && !defined(lint) && !defined(i386) 1937c478bd9Sstevel@tonic-gate /* 1947c478bd9Sstevel@tonic-gate * Macros for number representation conversion. 1957c478bd9Sstevel@tonic-gate */ 1967c478bd9Sstevel@tonic-gate #define ntohl(x) (x) 1977c478bd9Sstevel@tonic-gate #define ntohs(x) (x) 1987c478bd9Sstevel@tonic-gate #define htonl(x) (x) 1997c478bd9Sstevel@tonic-gate #define htons(x) (x) 2007c478bd9Sstevel@tonic-gate #endif 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate #if !defined(ntohl) && (defined(vax) || defined(lint) || defined(i386)) 2037c478bd9Sstevel@tonic-gate u_short ntohs(), htons(); 2047c478bd9Sstevel@tonic-gate u_long ntohl(), htonl(); 2057c478bd9Sstevel@tonic-gate #endif 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate #ifdef KERNEL 2087c478bd9Sstevel@tonic-gate extern struct domain inetdomain; 2097c478bd9Sstevel@tonic-gate extern struct protosw inetsw[]; 2107c478bd9Sstevel@tonic-gate struct in_addr in_makeaddr(); 2117c478bd9Sstevel@tonic-gate u_long in_netof(), in_lnaof(); 2127c478bd9Sstevel@tonic-gate #endif 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate #endif /* !_netinet_in_h */ 215