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