1.\" $NetBSD: netintro.4,v 1.30 2018/08/13 05:41:54 wiz 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 August 2, 2018 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. 108Raw socket interfaces are provided to the 109.Tn IP 110protocol layer of the Internet. 111Consult the appropriate manual pages in this section for more 112information regarding the support for a protocol. 113.Sh ADDRESSING 114Associated with each protocol family is an address format. 115All network address adhere to a general structure, called a sockaddr, 116described below. 117However, each protocol imposes finer and more specific structure, 118generally renaming the variant, which is discussed in the protocol 119family manual page alluded to above. 120.Bd -literal -offset indent 121struct sockaddr { 122 u_char sa_len; 123 u_char sa_family; 124 char sa_data[14]; 125}; 126.Ed 127.Pp 128The field 129.Ar sa_len 130contains the total length of the of the structure, which may exceed 16 bytes. 131The following address values for 132.Ar sa_family 133are known to the system 134(and additional formats are defined for possible future implementation): 135.Bd -literal 136#define AF_LOCAL 1 /* local to host */ 137#define AF_INET 2 /* internetwork: UDP, TCP, etc. */ 138#define AF_NS 6 /* Xerox NS protocols */ 139#define AF_CCITT 10 /* CCITT protocols, X.25 etc */ 140#define AF_HYLINK 15 /* NSC Hyperchannel */ 141#define AF_INET6 24 /* internetwork, v6: UDP, TCP, etc. */ 142.Ed 143.Sh ROUTING 144.Ux 145provides some packet routing facilities. 146The kernel maintains a routing information database, which 147is used in selecting the appropriate network interface when 148transmitting packets. 149.Pp 150A user process (or possibly multiple co-operating processes) 151maintains this database by sending messages over a special kind 152of socket. 153This supplants fixed size 154.Xr ioctl 2 155used in earlier releases. 156.Pp 157This facility is described in 158.Xr route 4 . 159.Sh INTERFACES 160Each network interface in a system corresponds to a 161path through which messages may be sent and received. 162A network interface usually has a hardware device associated with it, 163though certain interfaces such as the loopback interface, 164.Xr lo 4 , 165do not. 166.Pp 167The following 168.Xr ioctl 2 169calls may be used to manipulate network interfaces. 170The 171.Xr ioctl 2 172is made on a socket (typically of type 173.Dv SOCK_DGRAM ) 174in the desired domain. 175Most of the requests supported in earlier releases 176take an 177.Ar ifreq 178structure as its parameter. 179This structure has the form 180.Bd -literal 181struct ifreq { 182#define IFNAMSIZ 16 183 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 184 union { 185 struct sockaddr ifru_addr; 186 struct sockaddr ifru_dstaddr; 187 struct sockaddr ifru_broadaddr; 188 short ifru_flags; 189 int ifru_metric; 190 void *ifru_data; 191 } ifr_ifru; 192#define ifr_addr ifr_ifru.ifru_addr /* address */ 193#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ 194#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ 195#define ifr_space ifr_ifru.ifru_space /* sockaddr_storage */ 196#define ifr_flags ifr_ifru.ifru_flags /* flags */ 197#define ifr_metric ifr_ifru.ifru_metric /* metric */ 198#define ifr_mtu ifr_ifru.ifru_mtu /* mtu */ 199#define ifr_dlt ifr_ifru.ifru_dlt /* data link type (DLT_*) */ 200#define ifr_value ifr_ifru.ifru_value /* generic value */ 201#define ifr_media ifr_ifru.ifru_metric /* media options (overload) */ 202#define ifr_data ifr_ifru.ifru_data /* for use by interface */ 203#define ifr_buf ifr_ifru.ifru_b.b_buf /* new interface ioctls */ 204#define ifr_buflen ifr_ifru.ifru_b.b_buflen 205#define ifr_index ifr_ifru.ifru_value /* interface index */ 206}; 207.Ed 208.Pp 209Calls which are now deprecated are: 210.Bl -tag -width SIOCGIFBRDADDR 211.It Dv SIOCSIFADDR 212Set interface address for protocol family. 213Following the address assignment, the ``initialization'' routine for 214the interface is called. 215.It Dv SIOCSIFDSTADDR 216Set point to point address for protocol family and interface. 217.It Dv SIOCSIFBRDADDR 218Set broadcast address for protocol family and interface. 219.El 220.Pp 221.Xr ioctl 2 222requests to obtain addresses and requests both to set and 223retrieve other data are still fully supported 224and use the 225.Ar ifreq 226structure: 227.Bl -tag -width SIOCGIFBRDADDR 228.It Dv SIOCGIFADDR 229Get interface address for protocol family. 230.It Dv SIOCGIFDSTADDR 231Get point to point address for protocol family and interface. 232.It Dv SIOCGIFBRDADDR 233Get broadcast address for protocol family and interface. 234.It Dv SIOCSIFFLAGS 235Set interface flags field. 236If the interface is marked down, any processes currently routing 237packets through the interface are notified; some interfaces may be 238reset so that incoming packets are no longer received. 239When marked up again, the interface is reinitialized. 240.It Dv SIOCGIFFLAGS 241Get interface flags. 242.It Dv SIOCSIFMETRIC 243Set interface routing metric. 244The metric is used only by user-level routers. 245.It Dv SIOCGIFMETRIC 246Get interface metric. 247.It Dv SIOCGIFINDEX 248Get the interface index and populate ifr_index. 249.El 250.Pp 251There are two requests that make use of a new structure: 252.Bl -tag -width SIOCGIFBRDADDR 253.It Dv SIOCAIFADDR 254An interface may have more than one address associated with it 255in some protocols. 256This request provides a means to add additional addresses (or modify 257characteristics of the primary address if the default address for 258the address family is specified). 259Rather than making separate calls to set destination or broadcast 260addresses, or network masks (now an integral feature of multiple 261protocols) a separate structure, 262.Ar ifaliasreq , 263is used to specify all three facets 264simultaneously (see below). 265One would use a slightly tailored version of this struct specific 266to each family (replacing each sockaddr by one 267of the family-specific type). 268Where the sockaddr itself is larger than the 269default size, one needs to modify the 270.Xr ioctl 2 271identifier itself to include the total size, as described in 272.Xr ioctl 2 . 273.It Dv SIOCDIFADDR 274This requests deletes the specified address from the list 275associated with an interface. 276It also uses the 277.Ar ifaliasreq 278structure to allow for the possibility of protocols allowing 279multiple masks or destination addresses, and also adopts the 280convention that specification of the default address means 281to delete the first address for the interface belonging to 282the address family in which the original socket was opened. 283.It Dv SIOCGIFALIAS 284This request provides means to get additional addresses together 285with netmask and broadcast/destination from an interface. 286It also uses the 287.Ar ifaliasreq 288structure. 289.El 290.Pp 291Request making use of the 292.Ar ifconf 293structure: 294.Bl -tag -width SIOCGIFBRDADDR 295.It Dv SIOCGIFCONF 296Get interface configuration list. 297This request takes an 298.Ar ifconf 299structure (see below) as a value-result parameter. 300The 301.Ar ifc_len 302field should be initially set to the size of the buffer 303pointed to by 304.Ar ifc_buf . 305On return it will contain the length, in bytes, of the 306configuration list. 307.El 308.Bd -literal 309/* 310* Structure used in SIOC[AD]IFADDR request. 311*/ 312struct ifaliasreq { 313 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 314 struct sockaddr ifra_addr; 315 struct sockaddr ifra_dstaddr; 316#define ifra_broadaddr ifra_dstaddr 317 struct sockaddr ifra_mask; 318}; 319.Ed 320.Pp 321.Bd -literal 322/* 323* Structure used in SIOCGIFCONF request. 324* Used to retrieve interface configuration 325* for machine (useful for programs which 326* must know all networks accessible). 327*/ 328struct ifconf { 329 int ifc_len; /* size of associated buffer */ 330 union { 331 void *ifcu_buf; 332 struct ifreq *ifcu_req; 333 } ifc_ifcu; 334#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ 335#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ 336}; 337.Ed 338.Sh SEE ALSO 339.Xr config 1 , 340.Xr ioctl 2 , 341.Xr socket 2 , 342.Xr intro 4 , 343.Xr routed 8 344.Sh HISTORY 345The 346.Nm netintro 347manual appeared in 348.Bx 4.3 Tahoe . 349