1.\" $OpenBSD: inet.4,v 1.14 2007/05/31 19:19:50 jmc Exp $ 2.\" $NetBSD: inet.4,v 1.3 1994/11/30 16:22:18 jtc Exp $ 3.\" 4.\" Copyright (c) 1983, 1991, 1993 5.\" The Regents of the University of California. All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. Neither the name of the University nor the names of its contributors 16.\" may be used to endorse or promote products derived from this software 17.\" without specific prior written permission. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" SUCH DAMAGE. 30.\" 31.\" @(#)inet.4 8.1 (Berkeley) 6/5/93 32.\" 33.Dd $Mdocdate: May 31 2007 $ 34.Dt INET 4 35.Os 36.Sh NAME 37.Nm inet 38.Nd Internet protocol family 39.Sh SYNOPSIS 40.Fd #include <sys/types.h> 41.Fd #include <netinet/in.h> 42.Sh DESCRIPTION 43The Internet protocol family is a collection of protocols 44layered atop the 45.Em Internet Protocol 46.Pq Tn IP 47transport layer, and utilizing the Internet address format. 48The Internet family provides protocol support for the 49.Dv SOCK_STREAM , 50.Dv SOCK_DGRAM , 51and 52.Dv SOCK_RAW 53socket types; the 54.Dv SOCK_RAW 55interface provides access to the 56.Tn IP 57protocol. 58.Sh ADDRESSING 59Internet addresses are four byte quantities, stored in 60network standard format (on the 61.Tn VAX 62these are word and byte 63reversed). 64The include file 65.Aq Pa netinet/in.h 66defines this address as a discriminated union. 67.Pp 68Sockets bound to the Internet protocol family utilize 69the following addressing structure, 70.Bd -literal -offset indent 71struct sockaddr_in { 72 u_int8_t sin_len; 73 sa_family_t sin_family; 74 in_port_t sin_port; 75 struct in_addr sin_addr; 76 int8_t sin_zero[8]; 77}; 78.Ed 79.Pp 80Sockets may be created with the local address 81.Dv INADDR_ANY 82to effect 83.Dq wildcard 84matching on incoming messages. 85The address in a 86.Xr connect 2 87or 88.Xr sendto 2 89call may be given as 90.Dv INADDR_ANY 91to mean 92.Dq this host . 93The distinguished address 94.Dv INADDR_BROADCAST 95is allowed as a shorthand for the broadcast address on the primary 96network if the first network configured supports broadcast. 97.Sh PROTOCOLS 98The Internet protocol family is comprised of 99the 100.Tn IP 101transport protocol, Internet Control 102Message Protocol 103.Pq Tn ICMP , 104Transmission Control 105Protocol 106.Pq Tn TCP , 107and User Datagram Protocol 108.Pq Tn UDP . 109.Tn TCP 110is used to support the 111.Dv SOCK_STREAM 112abstraction while 113.Tn UDP 114is used to support the 115.Dv SOCK_DGRAM 116abstraction. 117A raw interface to 118.Tn IP 119is available 120by creating an Internet socket of type 121.Dv SOCK_RAW . 122The 123.Tn ICMP 124message protocol is accessible from a raw socket. 125.Pp 126The 32-bit Internet address contains both network and host parts. 127It is frequency-encoded; the most-significant bit is clear 128in Class A addresses, in which the high-order 8 bits are the network 129number. 130Class B addresses use the high-order 16 bits as the network field, 131and Class C addresses have a 24-bit network part. 132Sites with a cluster of local networks and a connection to the 133Internet may choose to use a single network number for the cluster; 134this is done by using subnet addressing. 135The local (host) portion of the address is further subdivided 136into subnet and host parts. 137Within a subnet, each subnet appears to be an individual network; 138externally, the entire cluster appears to be a single, uniform 139network requiring only a single routing entry. 140Subnet addressing is enabled and examined by the following 141.Xr ioctl 2 142commands on a datagram socket in the Internet domain; 143they have the same form as the 144.Dv SIOCIFADDR 145command (see 146.Xr netintro 4 ) . 147.Bl -tag -width SIOCSIFNETMASK 148.It Dv SIOCSIFNETMASK 149Set interface network mask. 150The network mask defines the network part of the address; 151if it contains more of the address than the address type would indicate, 152then subnets are in use. 153.It Dv SIOCGIFNETMASK 154Get interface network mask. 155.El 156.Sh SEE ALSO 157.Xr ioctl 2 , 158.Xr socket 2 , 159.Xr icmp 4 , 160.Xr ip 4 , 161.Xr netintro 4 , 162.Xr tcp 4 , 163.Xr udp 4 164.Rs 165.%T "An Introductory 4.3 BSD Interprocess Communication Tutorial" 166.%B PS1 167.%N 7 168.Re 169.Rs 170.%T "An Advanced 4.3 BSD Interprocess Communication Tutorial" 171.%B PS1 172.%N 8 173.Re 174.Sh HISTORY 175The 176.Nm 177protocol interface appeared in 178.Bx 4.2 . 179.Sh CAVEATS 180The Internet protocol support is subject to change as 181the Internet protocols develop. 182Users should not depend on details of the current implementation, but rather 183the services exported. 184