xref: /csrg-svn/share/man/man4/netintro.4 (revision 47675)
1*47675Scael.\" Copyright (c) 1983, 1990, 1991 The Regents of the University of California.
236752Sbostic.\" All rights reserved.
320726Smckusick.\"
442486Ssklower.\" %sccs.include.redist.man%
520726Smckusick.\"
6*47675Scael.\"     @(#)netintro.4	6.10 (Berkeley) 03/28/91
736752Sbostic.\"
8*47675Scael.Dd
9*47675Scael.Dt NETINTRO 4
10*47675Scael.Os BSD 4.2
11*47675Scael.Sh NAME
12*47675Scael.Nm networking
13*47675Scael.Nd introduction to networking facilities
14*47675Scael.Sh SYNOPSIS
15*47675Scael.Fd #include <sys/socket.h>
16*47675Scael.Fd #include <net/route.h>
17*47675Scael.Fd #include <net/if.h>
18*47675Scael.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:
23*47675Scael.Em protocol families
2442486Ssklower(domains),
25*47675Scael.Em protocols ,
2642486Ssklowerand
27*47675Scael.Em network interfaces .
28*47675Scael.Pp
2920726SmckusickAll network protocols are associated with a specific
30*47675Scael.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
39*47675Scael.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.
43*47675Scael.Pp
4420726SmckusickA protocol supports one of the socket abstractions detailed
4520726Smckusickin
46*47675Scael.Xr socket 2 .
4720726SmckusickA specific protocol may be accessed either by creating a
4828257Skarelssocket of the appropriate type and protocol family, or
4920726Smckusickby requesting the protocol explicitly when creating a socket.
5020726SmckusickProtocols normally accept only one type of address format,
5120726Smckusickusually determined by the addressing structure inherent in
5228257Skarelsthe design of the protocol family/network architecture.
5320726SmckusickCertain semantics of the basic socket abstractions are
5420726Smckusickprotocol specific.  All protocols are expected to support
5520726Smckusickthe basic model for their particular socket type, but may,
5620726Smckusickin addition, provide non-standard facilities or extensions
5720726Smckusickto a mechanism.  For example, a protocol supporting the
58*47675Scael.Dv SOCK_STREAM
5920726Smckusickabstraction may allow more than one byte of out-of-band
6020726Smckusickdata to be transmitted per out-of-band message.
61*47675Scael.Pp
6220726SmckusickA network interface is similar to a device interface.
6320726SmckusickNetwork interfaces comprise the lowest layer of the
6420726Smckusicknetworking subsystem, interacting with the actual transport
6520726Smckusickhardware.  An interface may support one or more protocol
6628257Skarelsfamilies and/or address formats.
6720726SmckusickThe SYNOPSIS section of each network interface
6820726Smckusickentry gives a sample specification
6920726Smckusickof the related drivers for use in providing
7020726Smckusicka system description to the
71*47675Scael.Xr config 8
7220726Smckusickprogram.
7320726SmckusickThe DIAGNOSTICS section lists messages which may appear on the console
7428257Skarelsand/or in the system error log,
75*47675Scael.Pa /var/log/messages
7628257Skarels(see
77*47675Scael.Xr syslogd 8 ) ,
7820726Smckusickdue to errors in device operation.
79*47675Scael.Sh PROTOCOLS
80*47675ScaelThe system currently supports the
81*47675Scael.Tn DARPA
82*47675ScaelInternet
8342486Ssklowerprotocols, the Xerox Network Systems(tm) protocols,
84*47675Scaeland some of the
85*47675Scael.Tn ISO OSI
86*47675Scaelprotocols.
87*47675ScaelRaw socket interfaces are provided to the
88*47675Scael.Tn IP
89*47675Scaelprotocol
90*47675Scaellayer of the
91*47675Scael.Tn DARPA
92*47675ScaelInternet, to the
93*47675Scael.Tn IMP
94*47675Scaellink layer (1822), and to
95*47675Scaelthe
96*47675Scael.Tn IDP
97*47675Scaelprotocol of Xerox
98*47675Scael.Tn NS .
9920726SmckusickConsult the appropriate manual pages in this section for more
10020726Smckusickinformation regarding the support for each protocol family.
101*47675Scael.Sh ADDRESSING
10220726SmckusickAssociated with each protocol family is an address
10342486Ssklowerformat.  All network address adhere to a general structure,
10442486Ssklowercalled a sockaddr, described below. However, each protocol
10542486Ssklowerimposes finer and more specific structure, generally renaming
10642486Ssklowerthe variant, which is discussed in the protocol family manual
10742486Ssklowerpage alluded to above.
108*47675Scael.Bd -literal -offset indent
109*47675Scael    struct sockaddr {
11042486Ssklower	u_char	sa_len;
111*47675Scael    	u_char	sa_family;
112*47675Scael    	char	sa_data[14];
11342486Ssklower};
114*47675Scael.Ed
115*47675Scael.Pp
116*47675ScaelThe field
117*47675Scael.Ar sa_len
118*47675Scaelcontains the total length of the of the structure,
11942486Ssklowerwhich may exceed 16 bytes.
12042486SsklowerThe following address values for
121*47675Scael.Ar sa_family
12242486Ssklowerare known to the system
12342486Ssklower(and additional formats are defined for possible future implementation):
124*47675Scael.Bd -literal
125*47675Scael#define    AF_UNIX      1    /* local to host (pipes, portals) */
126*47675Scael#define    AF_INET      2    /* internetwork: UDP, TCP, etc. */
127*47675Scael#define    AF_IMPLINK   3    /* arpanet imp addresses */
128*47675Scael#define    AF_NS        6    /* Xerox NS protocols */
129*47675Scael#define    AF_CCITT     10   /* CCITT protocols, X.25 etc */
130*47675Scael#define    AF_HYLINK    15   /* NSC Hyperchannel */
131*47675Scael#define    AF_ISO       18   /* ISO protocols */
132*47675Scael.Ed
133*47675Scael.Sh ROUTING
134*47675Scael.Tn UNIX
13542486Ssklowerprovides some packet routing facilities.
13642486SsklowerThe kernel maintains a routing information database, which
13742486Sskloweris used in selecting the appropriate network interface when
13842486Ssklowertransmitting packets.
139*47675Scael.Pp
14042486SsklowerA user process (or possibly multiple co-operating processes)
14142486Ssklowermaintains this database by sending messages over a special kind
14242486Ssklowerof socket.
14342486SsklowerThis supplants fixed size
144*47675Scael.Xr ioctl 2
14542486Ssklowerused in earlier releases.
146*47675Scael.Pp
14742486SsklowerThis facility is described in
148*47675Scael.Xr route 4 .
149*47675Scael.Sh INTERFACES
15020726SmckusickEach network interface in a system corresponds to a
15120726Smckusickpath through which messages may be sent and received.  A network
15220726Smckusickinterface usually has a hardware device associated with it, though
15320726Smckusickcertain interfaces such as the loopback interface,
154*47675Scael.Xr lo 4 ,
15520726Smckusickdo not.
156*47675Scael.Pp
15720726SmckusickThe following
158*47675Scael.Xr ioctl
15928257Skarelscalls may be used to manipulate network interfaces.
16028257SkarelsThe
161*47675Scael.Xr ioctl
162*47675Scaelis made on a socket (typically of type
163*47675Scael.Dv SOCK_DGRAM )
16428257Skarelsin the desired domain.
16542486SsklowerMost of the requests supported in earlier releases
16642486Ssklowertake an
167*47675Scael.Ar ifreq
16820726Smckusickstructure as its parameter.  This structure has the form
169*47675Scael.Bd -literal
17020726Smckusickstruct	ifreq {
171*47675Scael#define    IFNAMSIZ    16
172*47675Scael    char    ifr_name[IFNAMSIZE];        /* if name, e.g. "en0" */
173*47675Scael    union {
174*47675Scael        struct    sockaddr ifru_addr;
175*47675Scael        struct    sockaddr ifru_dstaddr;
176*47675Scael        struct    sockaddr ifru_broadaddr;
177*47675Scael        short     ifru_flags;
178*47675Scael        int       ifru_metric;
179*47675Scael        caddr_t   ifru_data;
180*47675Scael    } ifr_ifru;
181*47675Scael#define ifr_addr      ifr_ifru.ifru_addr    /* address */
182*47675Scael#define ifr_dstaddr   ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
183*47675Scael#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
184*47675Scael#define ifr_flags     ifr_ifru.ifru_flags   /* flags */
185*47675Scael#define ifr_metric    ifr_ifru.ifru_metric  /* metric */
186*47675Scael#define ifr_data      ifr_ifru.ifru_data    /* for use by interface */
18720726Smckusick};
188*47675Scael.Ed
189*47675Scael.Pp
19042486SsklowerCalls which are now deprecated are:
191*47675Scael.Bl -tag -width SIOCGIFBRDADDR
192*47675Scael.It Dv SIOCSIFADDR
19328257SkarelsSet interface address for protocol family.  Following the address
19420726Smckusickassignment, the ``initialization'' routine for
19520726Smckusickthe interface is called.
196*47675Scael.It Dv SIOCSIFDSTADDR
19742486SsklowerSet point to point address for protocol family and interface.
198*47675Scael.It Dv SIOCSIFBRDADDR
19942486SsklowerSet broadcast address for protocol family and interface.
200*47675Scael.El
201*47675Scael.Pp
202*47675Scael.Xr Ioctl
20342486Ssklowerrequests to obtain addresses and requests both to set and
20442486Ssklowerretreive other data are still fully supported
20542486Ssklowerand use the
206*47675Scael.Ar ifreq
20742486Ssklowerstructure:
208*47675Scael.Bl -tag -width SIOCGIFBRDADDR
209*47675Scael.It Dv SIOCGIFADDR
21028257SkarelsGet interface address for protocol family.
211*47675Scael.It Dv SIOCGIFDSTADDR
21228257SkarelsGet point to point address for protocol family and interface.
213*47675Scael.It Dv SIOCGIFBRDADDR
21428257SkarelsGet broadcast address for protocol family and interface.
215*47675Scael.It Dv SIOCSIFFLAGS
21620726SmckusickSet interface flags field.  If the interface is marked down,
21720726Smckusickany processes currently routing packets through the interface
21828257Skarelsare notified;
21928257Skarelssome interfaces may be reset so that incoming packets are no longer received.
22028257SkarelsWhen marked up again, the interface is reinitialized.
221*47675Scael.It Dv SIOCGIFFLAGS
22220726SmckusickGet interface flags.
223*47675Scael.It Dv SIOCSIFMETRIC
22428257SkarelsSet interface routing metric.
22528257SkarelsThe metric is used only by user-level routers.
226*47675Scael.It Dv SIOCGIFMETRIC
22728257SkarelsGet interface metric.
228*47675Scael.El
229*47675Scael.Pp
23042486SsklowerThere are two requests that make use of a new structure:
231*47675Scael.Bl -tag -width SIOCGIFBRDADDR
232*47675Scael.It Dv SIOCAIFADDR
23342486SsklowerAn interface may have more than one address associated with it
23442486Ssklowerin some protocols.  This request provides a means to
23542486Sskloweradd additional addresses (or modify characteristics of the
23642486Ssklowerprimary address if the default address for the address family
23742486Sskloweris specified).  Rather than making separate calls to
23842486Ssklowerset destination or broadcast addresses, or network masks
23942486Ssklower(now an integral feature of multiple protocols)
240*47675Scaela separate structure is used to specify all three facets simultaneously
241*47675Scael(see below).
24242486SsklowerOne would use a slightly tailored version of this struct specific
24342486Ssklowerto each family (replacing each sockaddr by one
24442486Ssklowerof the family-specific type).
24542486SsklowerWhere the sockaddr itself is larger than the
24642486Ssklowerdefault size, one needs to modify the
247*47675Scael.Xr ioctl
24842486Sskloweridentifier itself to include the total size, as described in
249*47675Scael.Xr ioctl .
250*47675Scael.It Dv SIOCDIFADDR
25142486SsklowerThis requests deletes the specified address from the list
252*47675Scaelassociated with an interface.  It also uses the
253*47675Scael.Ar if_aliasreq
25442486Ssklowerstructure to allow for the possibility of protocols allowing
25542486Ssklowermultiple masks or destination addresses, and also adopts the
25642486Ssklowerconvention that specification of the default address means
25742486Ssklowerto delete the first address for the interface belonging to
25842486Ssklowerthe address family in which the original socket was opened.
259*47675Scael.It Dv SIOCGIFCONF
26020726SmckusickGet interface configuration list.  This request takes an
261*47675Scael.Ar ifconf
26220726Smckusickstructure (see below) as a value-result parameter.  The
263*47675Scael.Ar ifc_len
26420726Smckusickfield should be initially set to the size of the buffer
26520726Smckusickpointed to by
266*47675Scael.Ar ifc_buf .
26720726SmckusickOn return it will contain the length, in bytes, of the
26820726Smckusickconfiguration list.
269*47675Scael.El
270*47675Scael.Bd -literal
27120726Smckusick/*
272*47675Scael* Structure used in SIOCAIFCONF request.
273*47675Scael*/
274*47675Scaelstruct ifaliasreq {
275*47675Scael        char    ifra_name[IFNAMSIZ];   /* if name, e.g. "en0" */
276*47675Scael        struct  sockaddr        ifra_addr;
277*47675Scael        struct  sockaddr        ifra_broadaddr;
278*47675Scael        struct  sockaddr        ifra_mask;
27920726Smckusick};
280*47675Scael.Ed
281*47675Scael.Pp
282*47675Scael.Bd -literal
283*47675Scael/*
284*47675Scael* Structure used in SIOCGIFCONF request.
285*47675Scael* Used to retrieve interface configuration
286*47675Scael* for machine (useful for programs which
287*47675Scael* must know all networks accessible).
288*47675Scael*/
289*47675Scaelstruct ifconf {
290*47675Scael    int   ifc_len;		/* size of associated buffer */
291*47675Scael    union {
292*47675Scael        caddr_t    ifcu_buf;
293*47675Scael        struct     ifreq *ifcu_req;
294*47675Scael    } ifc_ifcu;
295*47675Scael#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
296*47675Scael#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
297*47675Scael};
298*47675Scael.Ed
299*47675Scael.Sh SEE ALSO
300*47675Scael.Xr socket 2 ,
301*47675Scael.Xr ioctl 2 ,
302*47675Scael.Xr intro 4 ,
303*47675Scael.Xr config 8 ,
304*47675Scael.Xr routed 8
305*47675Scael.Sh HISTORY
306*47675ScaelThe
307*47675Scael.Nm netintro
308*47675Scaelmanual appeared in
309*47675Scael.Bx 4.3 tahoe .
310