xref: /freebsd/share/man/man4/netintro.4 (revision 380a989b3223d455375b4fae70fd0b9bdd43bafb)
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.\"	$Id: netintro.4,v 1.7 1997/02/22 13:24:38 peter Exp $
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. However, each protocol
128imposes finer and more specific structure, generally renaming
129the variant, which is discussed in the protocol family manual
130page alluded to above.
131.Bd -literal -offset indent
132    struct sockaddr {
133	u_char	sa_len;
134    	u_char	sa_family;
135    	char	sa_data[14];
136};
137.Ed
138.Pp
139The field
140.Ar sa_len
141contains the total length of the of the structure,
142which may exceed 16 bytes.
143The following address values for
144.Ar sa_family
145are known to the system
146(and additional formats are defined for possible future implementation):
147.Bd -literal
148#define    AF_UNIX      1    /* local to host (pipes, portals) */
149#define    AF_INET      2    /* internetwork: UDP, TCP, etc. */
150#define    AF_NS        6    /* Xerox NS protocols */
151#define    AF_CCITT     10   /* CCITT protocols, X.25 etc */
152#define    AF_HYLINK    15   /* NSC Hyperchannel */
153#define    AF_ISO       18   /* ISO protocols */
154.Ed
155.Sh ROUTING
156.Tn UNIX
157provides some packet routing facilities.
158The kernel maintains a routing information database, which
159is used in selecting the appropriate network interface when
160transmitting packets.
161.Pp
162A user process (or possibly multiple co-operating processes)
163maintains this database by sending messages over a special kind
164of socket.
165This supplants fixed size
166.Xr ioctl 2
167used in earlier releases.
168.Pp
169This facility is described in
170.Xr route 4 .
171.Sh INTERFACES
172Each network interface in a system corresponds to a
173path through which messages may be sent and received.  A network
174interface usually has a hardware device associated with it, though
175certain interfaces such as the loopback interface,
176.Xr lo 4 ,
177do not.
178.Pp
179The following
180.Xr ioctl 2
181calls may be used to manipulate network interfaces.
182The
183.Fn ioctl
184is made on a socket (typically of type
185.Dv SOCK_DGRAM )
186in the desired domain.
187Most of the requests supported in earlier releases
188take an
189.Ar ifreq
190structure as its parameter.  This structure has the form
191.Bd -literal
192struct	ifreq {
193#define    IFNAMSIZ    16
194    char    ifr_name[IFNAMSIZ];        /* if name, e.g. "en0" */
195    union {
196        struct    sockaddr ifru_addr;
197        struct    sockaddr ifru_dstaddr;
198        struct    sockaddr ifru_broadaddr;
199        short     ifru_flags;
200        int       ifru_metric;
201        int       ifru_mtu;
202        int       ifru_phys;
203        caddr_t   ifru_data;
204    } ifr_ifru;
205#define ifr_addr      ifr_ifru.ifru_addr    /* address */
206#define ifr_dstaddr   ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
207#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
208#define ifr_flags     ifr_ifru.ifru_flags   /* flags */
209#define ifr_metric    ifr_ifru.ifru_metric  /* metric */
210#define ifr_mtu       ifr_ifru.ifru_mtu     /* mtu */
211#define ifr_phys      ifr_ifru.ifru_phys    /* physical wire */
212#define ifr_data      ifr_ifru.ifru_data    /* for use by interface */
213};
214.Ed
215.Pp
216Calls which are now deprecated are:
217.Bl -tag -width SIOCGIFBRDADDR
218.It Dv SIOCSIFADDR
219Set interface address for protocol family.  Following the address
220assignment, the ``initialization'' routine for
221the interface is called.
222.It Dv SIOCSIFDSTADDR
223Set point to point address for protocol family and interface.
224.It Dv SIOCSIFBRDADDR
225Set broadcast address for protocol family and interface.
226.El
227.Pp
228.Fn Ioctl
229requests to obtain addresses and requests both to set and
230retrieve other data are still fully supported
231and use the
232.Ar ifreq
233structure:
234.Bl -tag -width SIOCGIFBRDADDR
235.It Dv SIOCGIFADDR
236Get interface address for protocol family.
237.It Dv SIOCGIFDSTADDR
238Get point to point address for protocol family and interface.
239.It Dv SIOCGIFBRDADDR
240Get broadcast address for protocol family and interface.
241.It Dv SIOCSIFFLAGS
242Set interface flags field.  If the interface is marked down,
243any processes currently routing packets through the interface
244are notified;
245some interfaces may be reset so that incoming packets are no longer received.
246When marked up again, the interface is reinitialized.
247.It Dv SIOCGIFFLAGS
248Get interface flags.
249.It Dv SIOCSIFMETRIC
250Set interface routing metric.
251The metric is used only by user-level routers.
252.It Dv SIOCGIFMETRIC
253Get interface metric.
254.El
255.Pp
256There are two requests that make use of a new structure:
257.Bl -tag -width SIOCGIFBRDADDR
258.It Dv SIOCAIFADDR
259An interface may have more than one address associated with it
260in some protocols.  This request provides a means to
261add additional addresses (or modify characteristics of the
262primary address if the default address for the address family
263is specified).  Rather than making separate calls to
264set destination or broadcast addresses, or network masks
265(now an integral feature of multiple protocols)
266a separate structure is used to specify all three facets simultaneously
267(see below).
268One would use a slightly tailored version of this struct specific
269to each family (replacing each sockaddr by one
270of the family-specific type).
271Where the sockaddr itself is larger than the
272default size, one needs to modify the
273.Fn ioctl
274identifier itself to include the total size, as described in
275.Fn ioctl .
276.It Dv SIOCDIFADDR
277This requests deletes the specified address from the list
278associated with an interface.  It also uses the
279.Ar if_aliasreq
280structure to allow for the possibility of protocols allowing
281multiple masks or destination addresses, and also adopts the
282convention that specification of the default address means
283to delete the first address for the interface belonging to
284the address family in which the original socket was opened.
285.It Dv SIOCGIFCONF
286Get interface configuration list.  This request takes an
287.Ar ifconf
288structure (see below) as a value-result parameter.  The
289.Ar ifc_len
290field should be initially set to the size of the buffer
291pointed to by
292.Ar ifc_buf .
293On return it will contain the length, in bytes, of the
294configuration list.
295.El
296.Bd -literal
297/*
298* Structure used in SIOCAIFCONF request.
299*/
300struct ifaliasreq {
301        char    ifra_name[IFNAMSIZ];   /* if name, e.g. "en0" */
302        struct  sockaddr        ifra_addr;
303        struct  sockaddr        ifra_broadaddr;
304        struct  sockaddr        ifra_mask;
305};
306.Ed
307.Pp
308.Bd -literal
309/*
310* Structure used in SIOCGIFCONF request.
311* Used to retrieve interface configuration
312* for machine (useful for programs which
313* must know all networks accessible).
314*/
315struct ifconf {
316    int   ifc_len;		/* size of associated buffer */
317    union {
318        caddr_t    ifcu_buf;
319        struct     ifreq *ifcu_req;
320    } ifc_ifcu;
321#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
322#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
323};
324.Ed
325.Sh SEE ALSO
326.Xr ioctl 2 ,
327.Xr socket 2 ,
328.Xr intro 4 ,
329.Xr config 8 ,
330.Xr routed 8
331.Sh HISTORY
332The
333.Nm netintro
334manual appeared in
335.Bx 4.3 tahoe .
336