1.\" $NetBSD: netintro.4,v 1.28 2014/07/13 12:47:13 mbalmer Exp $ 2.\" 3.\" Copyright (c) 1983, 1990, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. Neither the name of the University nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.\" @(#)netintro.4 8.2 (Berkeley) 11/30/93 31.\" 32.Dd July 13, 2014 33.Dt NETINTRO 4 34.Os 35.Sh NAME 36.Nm netintro 37.Nd introduction to networking facilities 38.Sh SYNOPSIS 39.In sys/types.h 40.In sys/socket.h 41.In net/route.h 42.In net/if.h 43.Sh DESCRIPTION 44This section is a general introduction to the networking facilities 45available in the system. 46Documentation in this part of section 474 is broken up into three areas: 48.Em protocol families 49(domains), 50.Em protocols , 51and 52.Em network interfaces . 53.Pp 54All network protocols are associated with a specific 55.Em protocol family . 56A protocol family provides basic services to the protocol implementation 57to allow it to function within a specific network environment. 58These services may include packet fragmentation and reassembly, 59routing, addressing, and basic transport. 60A protocol family may support multiple methods of addressing, though 61the current protocol implementations do not. 62A protocol family normally comprises a number of protocols, one per 63.Xr socket 2 64type. 65It is not required that a protocol family support all socket types. 66A protocol family may contain multiple protocols supporting the 67same socket abstraction. 68.Pp 69A protocol supports one of the socket abstractions detailed in 70.Xr socket 2 . 71A specific protocol may be accessed either by creating a 72socket of the appropriate type and protocol family, or 73by requesting the protocol explicitly when creating a socket. 74Protocols normally accept only one type of address format, 75usually determined by the addressing structure inherent in 76the design of the protocol family/network architecture. 77Certain semantics of the basic socket abstractions are 78protocol specific. 79All protocols are expected to support the basic model for their 80particular socket type, but may, in addition, provide non-standard 81facilities or extensions to a mechanism. 82For example, a protocol supporting the 83.Dv SOCK_STREAM 84abstraction may allow more than one byte of out-of-band 85data to be transmitted per out-of-band message. 86.Pp 87A network interface is similar to a device interface. 88Network interfaces comprise the lowest layer of the networking 89subsystem, interacting with the actual transport hardware. 90An interface may support one or more protocol families and/or address formats. 91The 92.Em SYNOPSIS 93section of each network interface entry gives a sample specification 94of the related drivers for use in providing a system description to the 95.Xr config 1 96program. 97.Pp 98The 99.Em DIAGNOSTICS 100section lists messages which may appear on the console 101and/or in the system error log, 102.Pa /var/log/messages 103(see 104.Xr syslogd 8 ) , 105due to errors in device operation. 106.Sh PROTOCOLS 107The system currently supports the Internet protocols and some of the 108.Tn ISO OSI 109protocols. 110Raw socket interfaces are provided to the 111.Tn IP 112protocol layer of the Internet, and to the 113.Tn IDP 114protocol of Xerox 115.Tn NS . 116Consult the appropriate manual pages in this section for more 117information regarding the support for each protocol family. 118.Sh ADDRESSING 119Associated with each protocol family is an address format. 120All network address adhere to a general structure, called a sockaddr, 121described below. 122However, each protocol imposes finer and more specific structure, 123generally renaming the variant, which is discussed in the protocol 124family manual page alluded to above. 125.Bd -literal -offset indent 126struct sockaddr { 127 u_char sa_len; 128 u_char sa_family; 129 char sa_data[14]; 130}; 131.Ed 132.Pp 133The field 134.Ar sa_len 135contains the total length of the of the structure, which may exceed 16 bytes. 136The following address values for 137.Ar sa_family 138are known to the system 139(and additional formats are defined for possible future implementation): 140.Bd -literal 141#define AF_LOCAL 1 /* local to host */ 142#define AF_INET 2 /* internetwork: UDP, TCP, etc. */ 143#define AF_NS 6 /* Xerox NS protocols */ 144#define AF_CCITT 10 /* CCITT protocols, X.25 etc */ 145#define AF_HYLINK 15 /* NSC Hyperchannel */ 146#define AF_INET6 24 /* internetwork, v6: UDP, TCP, etc. */ 147.Ed 148.Sh ROUTING 149.Ux 150provides some packet routing facilities. 151The kernel maintains a routing information database, which 152is used in selecting the appropriate network interface when 153transmitting packets. 154.Pp 155A user process (or possibly multiple co-operating processes) 156maintains this database by sending messages over a special kind 157of socket. 158This supplants fixed size 159.Xr ioctl 2 160used in earlier releases. 161.Pp 162This facility is described in 163.Xr route 4 . 164.Sh INTERFACES 165Each network interface in a system corresponds to a 166path through which messages may be sent and received. 167A network interface usually has a hardware device associated with it, 168though certain interfaces such as the loopback interface, 169.Xr lo 4 , 170do not. 171.Pp 172The following 173.Xr ioctl 2 174calls may be used to manipulate network interfaces. 175The 176.Xr ioctl 2 177is made on a socket (typically of type 178.Dv SOCK_DGRAM ) 179in the desired domain. 180Most of the requests supported in earlier releases 181take an 182.Ar ifreq 183structure as its parameter. 184This structure has the form 185.Bd -literal 186struct ifreq { 187#define IFNAMSIZ 16 188 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 189 union { 190 struct sockaddr ifru_addr; 191 struct sockaddr ifru_dstaddr; 192 struct sockaddr ifru_broadaddr; 193 short ifru_flags; 194 int ifru_metric; 195 void *ifru_data; 196 } ifr_ifru; 197#define ifr_addr ifr_ifru.ifru_addr /* address */ 198#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ 199#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ 200#define ifr_space ifr_ifru.ifru_space /* sockaddr_storage */ 201#define ifr_flags ifr_ifru.ifru_flags /* flags */ 202#define ifr_metric ifr_ifru.ifru_metric /* metric */ 203#define ifr_mtu ifr_ifru.ifru_mtu /* mtu */ 204#define ifr_dlt ifr_ifru.ifru_dlt /* data link type (DLT_*) */ 205#define ifr_value ifr_ifru.ifru_value /* generic value */ 206#define ifr_media ifr_ifru.ifru_metric /* media options (overload) */ 207#define ifr_data ifr_ifru.ifru_data /* for use by interface */ 208#define ifr_buf ifr_ifru.ifru_b.b_buf /* new interface ioctls */ 209#define ifr_buflen ifr_ifru.ifru_b.b_buflen 210#define ifr_index ifr_ifru.ifru_value /* interface index */ 211}; 212.Ed 213.Pp 214Calls which are now deprecated are: 215.Bl -tag -width SIOCGIFBRDADDR 216.It Dv SIOCSIFADDR 217Set interface address for protocol family. 218Following the address assignment, the ``initialization'' routine for 219the interface is called. 220.It Dv SIOCSIFDSTADDR 221Set point to point address for protocol family and interface. 222.It Dv SIOCSIFBRDADDR 223Set broadcast address for protocol family and interface. 224.El 225.Pp 226.Xr ioctl 2 227requests to obtain addresses and requests both to set and 228retrieve other data are still fully supported 229and use the 230.Ar ifreq 231structure: 232.Bl -tag -width SIOCGIFBRDADDR 233.It Dv SIOCGIFADDR 234Get interface address for protocol family. 235.It Dv SIOCGIFDSTADDR 236Get point to point address for protocol family and interface. 237.It Dv SIOCGIFBRDADDR 238Get broadcast address for protocol family and interface. 239.It Dv SIOCSIFFLAGS 240Set interface flags field. 241If the interface is marked down, any processes currently routing 242packets through the interface are notified; some interfaces may be 243reset so that incoming packets are no longer received. 244When marked up again, the interface is reinitialized. 245.It Dv SIOCGIFFLAGS 246Get interface flags. 247.It Dv SIOCSIFMETRIC 248Set interface routing metric. 249The metric is used only by user-level routers. 250.It Dv SIOCGIFMETRIC 251Get interface metric. 252.It Dv SIOCGIFINDEX 253Get the interface index and populate ifr_index. 254.El 255.Pp 256There are two requests that make use of a new structure: 257.Bl -tag -width SIOCGIFBRDADDR 258.It Dv SIOCAIFADDR 259An interface may have more than one address associated with it 260in some protocols. 261This request provides a means to add additional addresses (or modify 262characteristics of the primary address if the default address for 263the address family is specified). 264Rather than making separate calls to set destination or broadcast 265addresses, or network masks (now an integral feature of multiple 266protocols) a separate structure, 267.Ar ifaliasreq , 268is used to specify all three facets 269simultaneously (see below). 270One would use a slightly tailored version of this struct specific 271to each family (replacing each sockaddr by one 272of the family-specific type). 273Where the sockaddr itself is larger than the 274default size, one needs to modify the 275.Xr ioctl 2 276identifier itself to include the total size, as described in 277.Xr ioctl 2 . 278.It Dv SIOCDIFADDR 279This requests deletes the specified address from the list 280associated with an interface. 281It also uses the 282.Ar ifaliasreq 283structure to allow for the possibility of protocols allowing 284multiple masks or destination addresses, and also adopts the 285convention that specification of the default address means 286to delete the first address for the interface belonging to 287the address family in which the original socket was opened. 288.It Dv SIOCGIFALIAS 289This request provides means to get additional addresses together 290with netmask and broadcast/destination from an interface. 291It also uses the 292.Ar ifaliasreq 293structure. 294.El 295.Pp 296Request making use of the 297.Ar ifconf 298structure: 299.Bl -tag -width SIOCGIFBRDADDR 300.It Dv SIOCGIFCONF 301Get interface configuration list. 302This request takes an 303.Ar ifconf 304structure (see below) as a value-result parameter. 305The 306.Ar ifc_len 307field should be initially set to the size of the buffer 308pointed to by 309.Ar ifc_buf . 310On return it will contain the length, in bytes, of the 311configuration list. 312.El 313.Bd -literal 314/* 315* Structure used in SIOC[AD]IFADDR request. 316*/ 317struct ifaliasreq { 318 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 319 struct sockaddr ifra_addr; 320 struct sockaddr ifra_dstaddr; 321#define ifra_broadaddr ifra_dstaddr 322 struct sockaddr ifra_mask; 323}; 324.Ed 325.Pp 326.Bd -literal 327/* 328* Structure used in SIOCGIFCONF request. 329* Used to retrieve interface configuration 330* for machine (useful for programs which 331* must know all networks accessible). 332*/ 333struct ifconf { 334 int ifc_len; /* size of associated buffer */ 335 union { 336 void *ifcu_buf; 337 struct ifreq *ifcu_req; 338 } ifc_ifcu; 339#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ 340#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ 341}; 342.Ed 343.Sh SEE ALSO 344.Xr config 1 , 345.Xr ioctl 2 , 346.Xr socket 2 , 347.Xr intro 4 , 348.Xr routed 8 349.Sh HISTORY 350The 351.Nm netintro 352manual appeared in 353.Bx 4.3 Tahoe . 354