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. Neither the name of the University nor the names of its contributors 13.\" may be used to endorse or promote products derived from this software 14.\" without specific prior written permission. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.\" @(#)netintro.4 8.2 (Berkeley) 11/30/93 29.\" $FreeBSD: src/share/man/man4/netintro.4,v 1.10.2.6 2002/08/30 14:23:38 sobomax Exp $ 30.\" 31.Dd March 3, 2020 32.Dt NETINTRO 4 33.Os 34.Sh NAME 35.Nm networking 36.Nd introduction to networking facilities 37.Sh SYNOPSIS 38.In sys/types.h 39.In sys/time.h 40.In sys/socket.h 41.In net/if.h 42.In net/route.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 57implementation to allow it to function within a specific 58network environment. These services may include 59packet fragmentation and reassembly, routing, addressing, and 60basic transport. A protocol family may support multiple 61methods of addressing, though the current protocol implementations 62do not. A protocol family is normally comprised of a number 63of protocols, one per 64.Xr socket 2 65type. It is not required that a protocol family support 66all socket types. A protocol family may contain multiple 67protocols supporting the same 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. All protocols are expected to support 79the basic model for their particular socket type, but may, 80in addition, provide non-standard facilities or extensions 81to a mechanism. For example, a protocol supporting the 82.Dv SOCK_STREAM 83abstraction may allow more than one byte of out-of-band 84data to be transmitted per out-of-band message. 85.Pp 86A network interface is similar to a device interface. 87Network interfaces comprise the lowest layer of the 88networking subsystem, interacting with the actual transport 89hardware. An interface may support one or more protocol 90families and/or address formats. 91The SYNOPSIS section of each network interface 92entry gives a sample specification 93of the related drivers for use in the kernel configuration file. 94The DIAGNOSTICS section lists messages which may appear on the console 95and/or in the system error log, 96.Pa /var/log/messages 97(see 98.Xr syslogd 8 ) , 99due to errors in device operation. 100.Sh PROTOCOLS 101The system currently supports the 102Internet 103protocols, the Xerox Network Systems(tm) protocols, 104and some of the 105.Tn ISO OSI 106protocols. 107Raw socket interfaces are provided to the 108.Tn IP 109protocol 110layer of the 111Internet, and to the 112.Tn IDP 113protocol of Xerox 114.Tn NS . 115Consult the appropriate manual pages in this section for more 116information regarding the support for each protocol family. 117.Sh ADDRESSING 118Associated with each protocol family is an address 119format. All network address adhere to a general structure, 120called a sockaddr, described below. 121However, each protocol 122imposes finer and more specific structure, generally renaming 123the variant, which is discussed in the protocol family manual 124page alluded to above. 125.Bd -literal -offset indent 126 struct sockaddr { 127 u_char sa_len; 128 u_char sa_family; 129 char sa_data[14]; 130}; 131.Ed 132.Pp 133The field 134.Va sa_len 135contains the total length of the structure, 136which may exceed 16 bytes. 137The following address values for 138.Va sa_family 139are known to the system 140(and additional formats are defined for possible future implementation): 141.Bd -literal 142#define AF_UNIX 1 /* local to host (pipes, portals) */ 143#define AF_INET 2 /* internetwork: UDP, TCP, etc. */ 144#define AF_CCITT 10 /* CCITT protocols, X.25 etc */ 145#define AF_HYLINK 15 /* NSC Hyperchannel */ 146.Ed 147.Sh ROUTING 148.Ux 149provides some packet routing facilities. 150The kernel maintains a routing information database, which 151is used in selecting the appropriate network interface when 152transmitting packets. 153.Pp 154A user process (or possibly multiple co-operating processes) 155maintains this database by sending messages over a special kind 156of socket. 157This supplants fixed size 158.Xr ioctl 2 159used in earlier releases. 160.Pp 161This facility is described in 162.Xr route 4 . 163.Sh INTERFACES 164Each network interface in a system corresponds to a 165path through which messages may be sent and received. A network 166interface usually has a hardware device associated with it, though 167certain interfaces such as the loopback interface, 168.Xr lo 4 , 169do not. 170.Pp 171The following 172.Xr ioctl 2 173calls may be used to manipulate network interfaces. 174The 175.Fn ioctl 176is made on a socket (typically of type 177.Dv SOCK_DGRAM ) 178in the desired domain. 179Most of the requests supported in earlier releases 180take an 181.Vt ifreq 182structure as its parameter. This structure has the form 183.Bd -literal 184struct ifreq { 185#define IFNAMSIZ 16 186 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 187 union { 188 struct sockaddr ifru_addr; 189 struct sockaddr ifru_dstaddr; 190 struct sockaddr ifru_broadaddr; 191 short ifru_flags[2]; 192 int ifru_metric; 193 int ifru_mtu; 194 int ifru_phys; 195 caddr_t 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_flags ifr_ifru.ifru_flags[0] /* flags (low 16 bits) */ 201#define ifr_flagshigh ifr_ifru.ifru_flags[1] /* flags (high 16 bits) */ 202#define ifr_metric ifr_ifru.ifru_metric /* metric */ 203#define ifr_mtu ifr_ifru.ifru_mtu /* mtu */ 204#define ifr_phys ifr_ifru.ifru_phys /* physical wire */ 205#define ifr_data ifr_ifru.ifru_data /* for use by interface */ 206}; 207.Ed 208.Pp 209Calls which are now deprecated are: 210.Bl -tag -width ".Dv SIOCGIFBRDADDR" 211.It Dv SIOCSIFADDR 212Set interface address for protocol family. Following the address 213assignment, 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.Fn Ioctl 222requests to obtain addresses and requests both to set and 223retrieve other data are still fully supported 224and use the 225.Vt ifreq 226structure: 227.Bl -tag -width ".Dv 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. If the interface is marked down, 236any processes currently routing packets through the interface 237are notified; 238some interfaces may be reset 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 SIOCIFCREATE 248Attempt to create the specified interface. 249If the interface name is given without a unit number the system 250will attempt to create a new interface with an arbitrary unit number. 251On successful return the 252.Va ifr_name 253field will contain the new interface name. 254.It Dv SIOCIFDESTROY 255Attempt to destroy the specified interface. 256.El 257.Pp 258There are two requests that make use of a new structure: 259.Bl -tag -width ".Dv SIOCGIFBRDADDR" 260.It Dv SIOCAIFADDR 261An interface may have more than one address associated with it 262in some protocols. This request provides a means to 263add additional addresses (or modify characteristics of the 264primary address if the default address for the address family 265is specified). Rather than making separate calls to 266set destination or broadcast addresses, or network masks 267(now an integral feature of multiple protocols) 268a separate structure is used to specify all three facets simultaneously 269(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.Fn ioctl 276identifier itself to include the total size, as described in 277.Fn ioctl . 278.It Dv SIOCDIFADDR 279This requests deletes the specified address from the list 280associated with an interface. It also uses the 281.Vt ifaliasreq 282structure to allow for the possibility of protocols allowing 283multiple masks or destination addresses, and also adopts the 284convention that specification of the default address means 285to delete the first address for the interface belonging to 286the address family in which the original socket was opened. 287.It Dv SIOCGIFALIAS 288This request provides means to get additional addresses 289together with netmask and broadcast/destination from an 290interface. 291It also uses the 292.Vt ifaliasreq 293structure. 294.It Dv SIOCGIFCONF 295Get interface configuration list. This request takes an 296.Vt ifconf 297structure (see below) as a value-result parameter. The 298.Va ifc_len 299field should be initially set to the size of the buffer 300pointed to by 301.Va ifc_buf . 302On return it will contain the length, in bytes, of the 303configuration list. 304.It Dv SIOCIFGCLONERS 305Get list of clonable interfaces. 306This request takes an 307.Vt if_clonereq 308structure (see below) as a value-result parameter. 309The 310.Va ifcr_count 311field should be set to the number of 312.Dv IFNAMSIZ 313sized strings that can be fit in the buffer pointed to by 314.Va ifcr_buffer . 315On return, 316.Va ifcr_total 317will be set to the number of clonable interfaces and the buffer pointed 318to by 319.Va ifcr_buffer 320will be filled with the names of clonable interfaces aligned on 321.Dv IFNAMSIZ 322boundaries. 323.El 324.Bd -literal 325/* 326* Structure used in SIOCAIFCONF request. 327*/ 328struct ifaliasreq { 329 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 330 struct sockaddr ifra_addr; 331 struct sockaddr ifra_broadaddr; 332 struct sockaddr ifra_mask; 333}; 334.Ed 335.Bd -literal 336/* 337* Structure used in SIOCGIFCONF request. 338* Used to retrieve interface configuration 339* for machine (useful for programs which 340* must know all networks accessible). 341*/ 342struct ifconf { 343 int ifc_len; /* size of associated buffer */ 344 union { 345 caddr_t ifcu_buf; 346 struct ifreq *ifcu_req; 347 } ifc_ifcu; 348#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ 349#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ 350}; 351.Ed 352.Bd -literal 353/* Structure used in SIOCIFGCLONERS request. */ 354struct if_clonereq { 355 int ifcr_total; /* total cloners (out) */ 356 int ifcr_count; /* room for this many in user buffer */ 357 char *ifcr_buffer; /* buffer for cloner names */ 358}; 359.Ed 360.Sh SEE ALSO 361.Xr ioctl 2 , 362.Xr socket 2 , 363.Xr intro 4 , 364.Xr routed 8 365.Sh HISTORY 366The 367.Nm netintro 368manual appeared in 369.Bx 4.3 tahoe . 370