163900Sbostic.\" Copyright (c) 1983, 1990, 1991, 1993 263900Sbostic.\" The Regents of the University of California. All rights reserved. 320726Smckusick.\" 442486Ssklower.\" %sccs.include.redist.man% 520726Smckusick.\" 6*64994Smckusick.\" @(#)netintro.4 8.2 (Berkeley) 11/30/93 736752Sbostic.\" 847675Scael.Dd 947675Scael.Dt NETINTRO 4 1047675Scael.Os BSD 4.2 1147675Scael.Sh NAME 1247675Scael.Nm networking 1347675Scael.Nd introduction to networking facilities 1447675Scael.Sh SYNOPSIS 1547675Scael.Fd #include <sys/socket.h> 1647675Scael.Fd #include <net/route.h> 1747675Scael.Fd #include <net/if.h> 1847675Scael.Sh DESCRIPTION 1942486SsklowerThis section is a general introduction to the networking facilities 2020726Smckusickavailable in the system. 2142486SsklowerDocumentation in this part of section 2242486Ssklower4 is broken up into three areas: 2347675Scael.Em protocol families 2442486Ssklower(domains), 2547675Scael.Em protocols , 2642486Ssklowerand 2747675Scael.Em network interfaces . 2847675Scael.Pp 2920726SmckusickAll network protocols are associated with a specific 3047675Scael.Em protocol family . 3128257SkarelsA protocol family provides basic services to the protocol 3220726Smckusickimplementation to allow it to function within a specific 3320726Smckusicknetwork environment. These services may include 3420726Smckusickpacket fragmentation and reassembly, routing, addressing, and 3528257Skarelsbasic transport. A protocol family may support multiple 3620726Smckusickmethods of addressing, though the current protocol implementations 3728257Skarelsdo not. A protocol family is normally comprised of a number 3820726Smckusickof protocols, one per 3947675Scael.Xr socket 2 4028257Skarelstype. It is not required that a protocol family support 4128257Skarelsall socket types. A protocol family may contain multiple 4220726Smckusickprotocols supporting the same socket abstraction. 4347675Scael.Pp 4463899SmckusickA protocol supports one of the socket abstractions detailed in 4547675Scael.Xr socket 2 . 4620726SmckusickA specific protocol may be accessed either by creating a 4728257Skarelssocket of the appropriate type and protocol family, or 4820726Smckusickby requesting the protocol explicitly when creating a socket. 4920726SmckusickProtocols normally accept only one type of address format, 5020726Smckusickusually determined by the addressing structure inherent in 5128257Skarelsthe design of the protocol family/network architecture. 5220726SmckusickCertain semantics of the basic socket abstractions are 5320726Smckusickprotocol specific. All protocols are expected to support 5420726Smckusickthe basic model for their particular socket type, but may, 5520726Smckusickin addition, provide non-standard facilities or extensions 5620726Smckusickto a mechanism. For example, a protocol supporting the 5747675Scael.Dv SOCK_STREAM 5820726Smckusickabstraction may allow more than one byte of out-of-band 5920726Smckusickdata to be transmitted per out-of-band message. 6047675Scael.Pp 6120726SmckusickA network interface is similar to a device interface. 6220726SmckusickNetwork interfaces comprise the lowest layer of the 6320726Smckusicknetworking subsystem, interacting with the actual transport 6420726Smckusickhardware. An interface may support one or more protocol 6528257Skarelsfamilies and/or address formats. 6620726SmckusickThe SYNOPSIS section of each network interface 6720726Smckusickentry gives a sample specification 6820726Smckusickof the related drivers for use in providing 6920726Smckusicka system description to the 7047675Scael.Xr config 8 7120726Smckusickprogram. 7220726SmckusickThe DIAGNOSTICS section lists messages which may appear on the console 7328257Skarelsand/or in the system error log, 7447675Scael.Pa /var/log/messages 7528257Skarels(see 7647675Scael.Xr syslogd 8 ) , 7720726Smckusickdue to errors in device operation. 7847675Scael.Sh PROTOCOLS 7947675ScaelThe system currently supports the 8047675ScaelInternet 8142486Ssklowerprotocols, the Xerox Network Systems(tm) protocols, 8247675Scaeland some of the 8347675Scael.Tn ISO OSI 8447675Scaelprotocols. 8547675ScaelRaw socket interfaces are provided to the 8647675Scael.Tn IP 8747675Scaelprotocol 8847675Scaellayer of the 8963899SmckusickInternet, and to the 9047675Scael.Tn IDP 9147675Scaelprotocol of Xerox 9247675Scael.Tn NS . 9320726SmckusickConsult the appropriate manual pages in this section for more 9420726Smckusickinformation regarding the support for each protocol family. 9547675Scael.Sh ADDRESSING 9620726SmckusickAssociated with each protocol family is an address 9742486Ssklowerformat. All network address adhere to a general structure, 9842486Ssklowercalled a sockaddr, described below. However, each protocol 9942486Ssklowerimposes finer and more specific structure, generally renaming 10042486Ssklowerthe variant, which is discussed in the protocol family manual 10142486Ssklowerpage alluded to above. 10247675Scael.Bd -literal -offset indent 10347675Scael struct sockaddr { 10442486Ssklower u_char sa_len; 10547675Scael u_char sa_family; 10647675Scael char sa_data[14]; 10742486Ssklower}; 10847675Scael.Ed 10947675Scael.Pp 11047675ScaelThe field 11147675Scael.Ar sa_len 11247675Scaelcontains the total length of the of the structure, 11342486Ssklowerwhich may exceed 16 bytes. 11442486SsklowerThe following address values for 11547675Scael.Ar sa_family 11642486Ssklowerare known to the system 11742486Ssklower(and additional formats are defined for possible future implementation): 11847675Scael.Bd -literal 11947675Scael#define AF_UNIX 1 /* local to host (pipes, portals) */ 12047675Scael#define AF_INET 2 /* internetwork: UDP, TCP, etc. */ 12147675Scael#define AF_NS 6 /* Xerox NS protocols */ 12247675Scael#define AF_CCITT 10 /* CCITT protocols, X.25 etc */ 12347675Scael#define AF_HYLINK 15 /* NSC Hyperchannel */ 12447675Scael#define AF_ISO 18 /* ISO protocols */ 12547675Scael.Ed 12647675Scael.Sh ROUTING 12747675Scael.Tn UNIX 12842486Ssklowerprovides some packet routing facilities. 12942486SsklowerThe kernel maintains a routing information database, which 13042486Sskloweris used in selecting the appropriate network interface when 13142486Ssklowertransmitting packets. 13247675Scael.Pp 13342486SsklowerA user process (or possibly multiple co-operating processes) 13442486Ssklowermaintains this database by sending messages over a special kind 13542486Ssklowerof socket. 13642486SsklowerThis supplants fixed size 13747675Scael.Xr ioctl 2 13842486Ssklowerused in earlier releases. 13947675Scael.Pp 14042486SsklowerThis facility is described in 14147675Scael.Xr route 4 . 14247675Scael.Sh INTERFACES 14320726SmckusickEach network interface in a system corresponds to a 14420726Smckusickpath through which messages may be sent and received. A network 14520726Smckusickinterface usually has a hardware device associated with it, though 14620726Smckusickcertain interfaces such as the loopback interface, 14747675Scael.Xr lo 4 , 14820726Smckusickdo not. 14947675Scael.Pp 15020726SmckusickThe following 15147675Scael.Xr ioctl 15228257Skarelscalls may be used to manipulate network interfaces. 15328257SkarelsThe 15447675Scael.Xr ioctl 15547675Scaelis made on a socket (typically of type 15647675Scael.Dv SOCK_DGRAM ) 15728257Skarelsin the desired domain. 15842486SsklowerMost of the requests supported in earlier releases 15942486Ssklowertake an 16047675Scael.Ar ifreq 16120726Smckusickstructure as its parameter. This structure has the form 16247675Scael.Bd -literal 16320726Smckusickstruct ifreq { 16447675Scael#define IFNAMSIZ 16 16547675Scael char ifr_name[IFNAMSIZE]; /* if name, e.g. "en0" */ 16647675Scael union { 16747675Scael struct sockaddr ifru_addr; 16847675Scael struct sockaddr ifru_dstaddr; 16947675Scael struct sockaddr ifru_broadaddr; 17047675Scael short ifru_flags; 17147675Scael int ifru_metric; 17247675Scael caddr_t ifru_data; 17347675Scael } ifr_ifru; 17447675Scael#define ifr_addr ifr_ifru.ifru_addr /* address */ 17547675Scael#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ 17647675Scael#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ 17747675Scael#define ifr_flags ifr_ifru.ifru_flags /* flags */ 17847675Scael#define ifr_metric ifr_ifru.ifru_metric /* metric */ 17947675Scael#define ifr_data ifr_ifru.ifru_data /* for use by interface */ 18020726Smckusick}; 18147675Scael.Ed 18247675Scael.Pp 18342486SsklowerCalls which are now deprecated are: 18447675Scael.Bl -tag -width SIOCGIFBRDADDR 18547675Scael.It Dv SIOCSIFADDR 18628257SkarelsSet interface address for protocol family. Following the address 18720726Smckusickassignment, the ``initialization'' routine for 18820726Smckusickthe interface is called. 18947675Scael.It Dv SIOCSIFDSTADDR 19042486SsklowerSet point to point address for protocol family and interface. 19147675Scael.It Dv SIOCSIFBRDADDR 19242486SsklowerSet broadcast address for protocol family and interface. 19347675Scael.El 19447675Scael.Pp 19547675Scael.Xr Ioctl 19642486Ssklowerrequests to obtain addresses and requests both to set and 197*64994Smckusickretrieve other data are still fully supported 19842486Ssklowerand use the 19947675Scael.Ar ifreq 20042486Ssklowerstructure: 20147675Scael.Bl -tag -width SIOCGIFBRDADDR 20247675Scael.It Dv SIOCGIFADDR 20328257SkarelsGet interface address for protocol family. 20447675Scael.It Dv SIOCGIFDSTADDR 20528257SkarelsGet point to point address for protocol family and interface. 20647675Scael.It Dv SIOCGIFBRDADDR 20728257SkarelsGet broadcast address for protocol family and interface. 20847675Scael.It Dv SIOCSIFFLAGS 20920726SmckusickSet interface flags field. If the interface is marked down, 21020726Smckusickany processes currently routing packets through the interface 21128257Skarelsare notified; 21228257Skarelssome interfaces may be reset so that incoming packets are no longer received. 21328257SkarelsWhen marked up again, the interface is reinitialized. 21447675Scael.It Dv SIOCGIFFLAGS 21520726SmckusickGet interface flags. 21647675Scael.It Dv SIOCSIFMETRIC 21728257SkarelsSet interface routing metric. 21828257SkarelsThe metric is used only by user-level routers. 21947675Scael.It Dv SIOCGIFMETRIC 22028257SkarelsGet interface metric. 22147675Scael.El 22247675Scael.Pp 22342486SsklowerThere are two requests that make use of a new structure: 22447675Scael.Bl -tag -width SIOCGIFBRDADDR 22547675Scael.It Dv SIOCAIFADDR 22642486SsklowerAn interface may have more than one address associated with it 22742486Ssklowerin some protocols. This request provides a means to 22842486Sskloweradd additional addresses (or modify characteristics of the 22942486Ssklowerprimary address if the default address for the address family 23042486Sskloweris specified). Rather than making separate calls to 23142486Ssklowerset destination or broadcast addresses, or network masks 23242486Ssklower(now an integral feature of multiple protocols) 23347675Scaela separate structure is used to specify all three facets simultaneously 23447675Scael(see below). 23542486SsklowerOne would use a slightly tailored version of this struct specific 23642486Ssklowerto each family (replacing each sockaddr by one 23742486Ssklowerof the family-specific type). 23842486SsklowerWhere the sockaddr itself is larger than the 23942486Ssklowerdefault size, one needs to modify the 24047675Scael.Xr ioctl 24142486Sskloweridentifier itself to include the total size, as described in 24247675Scael.Xr ioctl . 24347675Scael.It Dv SIOCDIFADDR 24442486SsklowerThis requests deletes the specified address from the list 24547675Scaelassociated with an interface. It also uses the 24647675Scael.Ar if_aliasreq 24742486Ssklowerstructure to allow for the possibility of protocols allowing 24842486Ssklowermultiple masks or destination addresses, and also adopts the 24942486Ssklowerconvention that specification of the default address means 25042486Ssklowerto delete the first address for the interface belonging to 25142486Ssklowerthe address family in which the original socket was opened. 25247675Scael.It Dv SIOCGIFCONF 25320726SmckusickGet interface configuration list. This request takes an 25447675Scael.Ar ifconf 25520726Smckusickstructure (see below) as a value-result parameter. The 25647675Scael.Ar ifc_len 25720726Smckusickfield should be initially set to the size of the buffer 25820726Smckusickpointed to by 25947675Scael.Ar ifc_buf . 26020726SmckusickOn return it will contain the length, in bytes, of the 26120726Smckusickconfiguration list. 26247675Scael.El 26347675Scael.Bd -literal 26420726Smckusick/* 26547675Scael* Structure used in SIOCAIFCONF request. 26647675Scael*/ 26747675Scaelstruct ifaliasreq { 26847675Scael char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 26947675Scael struct sockaddr ifra_addr; 27047675Scael struct sockaddr ifra_broadaddr; 27147675Scael struct sockaddr ifra_mask; 27220726Smckusick}; 27347675Scael.Ed 27447675Scael.Pp 27547675Scael.Bd -literal 27647675Scael/* 27747675Scael* Structure used in SIOCGIFCONF request. 27847675Scael* Used to retrieve interface configuration 27947675Scael* for machine (useful for programs which 28047675Scael* must know all networks accessible). 28147675Scael*/ 28247675Scaelstruct ifconf { 28347675Scael int ifc_len; /* size of associated buffer */ 28447675Scael union { 28547675Scael caddr_t ifcu_buf; 28647675Scael struct ifreq *ifcu_req; 28747675Scael } ifc_ifcu; 28847675Scael#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ 28947675Scael#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ 29047675Scael}; 29147675Scael.Ed 29247675Scael.Sh SEE ALSO 29347675Scael.Xr socket 2 , 29447675Scael.Xr ioctl 2 , 29547675Scael.Xr intro 4 , 29647675Scael.Xr config 8 , 29747675Scael.Xr routed 8 29847675Scael.Sh HISTORY 29947675ScaelThe 30047675Scael.Nm netintro 30147675Scaelmanual appeared in 30247675Scael.Bx 4.3 tahoe . 303