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