xref: /freebsd/share/man/man4/netintro.4 (revision e627b39baccd1ec9129690167cf5e6d860509655)
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.\"
34.Dd November 30, 1993
35.Dt NETINTRO 4
36.Os BSD 4.2
37.Sh NAME
38.Nm networking
39.Nd introduction to networking facilities
40.Sh SYNOPSIS
41.Fd #include <sys/socket.h>
42.Fd #include <net/route.h>
43.Fd #include <net/if.h>
44.Sh DESCRIPTION
45This section is a general introduction to the networking facilities
46available in the system.
47Documentation in this part of section
484 is broken up into three areas:
49.Em protocol families
50(domains),
51.Em protocols ,
52and
53.Em network interfaces .
54.Pp
55All network protocols are associated with a specific
56.Em protocol family .
57A protocol family provides basic services to the protocol
58implementation to allow it to function within a specific
59network environment.  These services may include
60packet fragmentation and reassembly, routing, addressing, and
61basic transport.  A protocol family may support multiple
62methods of addressing, though the current protocol implementations
63do not.  A protocol family is normally comprised of a number
64of protocols, one per
65.Xr socket 2
66type.  It is not required that a protocol family support
67all socket types.  A protocol family may contain multiple
68protocols supporting the same socket abstraction.
69.Pp
70A protocol supports one of the socket abstractions detailed in
71.Xr socket 2 .
72A specific protocol may be accessed either by creating a
73socket of the appropriate type and protocol family, or
74by requesting the protocol explicitly when creating a socket.
75Protocols normally accept only one type of address format,
76usually determined by the addressing structure inherent in
77the design of the protocol family/network architecture.
78Certain semantics of the basic socket abstractions are
79protocol specific.  All protocols are expected to support
80the basic model for their particular socket type, but may,
81in addition, provide non-standard facilities or extensions
82to a mechanism.  For example, a protocol supporting the
83.Dv SOCK_STREAM
84abstraction may allow more than one byte of out-of-band
85data to be transmitted per out-of-band message.
86.Pp
87A network interface is similar to a device interface.
88Network interfaces comprise the lowest layer of the
89networking subsystem, interacting with the actual transport
90hardware.  An interface may support one or more protocol
91families and/or address formats.
92The SYNOPSIS section of each network interface
93entry gives a sample specification
94of the related drivers for use in providing
95a system description to the
96.Xr config 8
97program.
98The DIAGNOSTICS section lists messages which may appear on the console
99and/or in the system error log,
100.Pa /var/log/messages
101(see
102.Xr syslogd 8 ) ,
103due to errors in device operation.
104.Sh PROTOCOLS
105The system currently supports the
106Internet
107protocols, the Xerox Network Systems(tm) protocols,
108and some of the
109.Tn ISO OSI
110protocols.
111Raw socket interfaces are provided to the
112.Tn IP
113protocol
114layer of the
115Internet, and to the
116.Tn IDP
117protocol of Xerox
118.Tn NS .
119Consult the appropriate manual pages in this section for more
120information regarding the support for each protocol family.
121.Sh ADDRESSING
122Associated with each protocol family is an address
123format.  All network address adhere to a general structure,
124called a sockaddr, described below. However, each protocol
125imposes finer and more specific structure, generally renaming
126the variant, which is discussed in the protocol family manual
127page alluded to above.
128.Bd -literal -offset indent
129    struct sockaddr {
130	u_char	sa_len;
131    	u_char	sa_family;
132    	char	sa_data[14];
133};
134.Ed
135.Pp
136The field
137.Ar sa_len
138contains the total length of the of the structure,
139which may exceed 16 bytes.
140The following address values for
141.Ar sa_family
142are known to the system
143(and additional formats are defined for possible future implementation):
144.Bd -literal
145#define    AF_UNIX      1    /* local to host (pipes, portals) */
146#define    AF_INET      2    /* internetwork: UDP, TCP, etc. */
147#define    AF_NS        6    /* Xerox NS protocols */
148#define    AF_CCITT     10   /* CCITT protocols, X.25 etc */
149#define    AF_HYLINK    15   /* NSC Hyperchannel */
150#define    AF_ISO       18   /* ISO protocols */
151.Ed
152.Sh ROUTING
153.Tn UNIX
154provides some packet routing facilities.
155The kernel maintains a routing information database, which
156is used in selecting the appropriate network interface when
157transmitting packets.
158.Pp
159A user process (or possibly multiple co-operating processes)
160maintains this database by sending messages over a special kind
161of socket.
162This supplants fixed size
163.Xr ioctl 2
164used in earlier releases.
165.Pp
166This facility is described in
167.Xr route 4 .
168.Sh INTERFACES
169Each network interface in a system corresponds to a
170path through which messages may be sent and received.  A network
171interface usually has a hardware device associated with it, though
172certain interfaces such as the loopback interface,
173.Xr lo 4 ,
174do not.
175.Pp
176The following
177.Xr ioctl 2
178calls may be used to manipulate network interfaces.
179The
180.Fn ioctl
181is made on a socket (typically of type
182.Dv SOCK_DGRAM )
183in the desired domain.
184Most of the requests supported in earlier releases
185take an
186.Ar ifreq
187structure as its parameter.  This structure has the form
188.Bd -literal
189struct	ifreq {
190#define    IFNAMSIZ    16
191    char    ifr_name[IFNAMSIZ];        /* if name, e.g. "en0" */
192    union {
193        struct    sockaddr ifru_addr;
194        struct    sockaddr ifru_dstaddr;
195        struct    sockaddr ifru_broadaddr;
196        short     ifru_flags;
197        int       ifru_metric;
198        caddr_t   ifru_data;
199    } ifr_ifru;
200#define ifr_addr      ifr_ifru.ifru_addr    /* address */
201#define ifr_dstaddr   ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
202#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
203#define ifr_flags     ifr_ifru.ifru_flags   /* flags */
204#define ifr_metric    ifr_ifru.ifru_metric  /* metric */
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 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.Ar ifreq
226structure:
227.Bl -tag -width 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.El
248.Pp
249There are two requests that make use of a new structure:
250.Bl -tag -width SIOCGIFBRDADDR
251.It Dv SIOCAIFADDR
252An interface may have more than one address associated with it
253in some protocols.  This request provides a means to
254add additional addresses (or modify characteristics of the
255primary address if the default address for the address family
256is specified).  Rather than making separate calls to
257set destination or broadcast addresses, or network masks
258(now an integral feature of multiple protocols)
259a separate structure is used to specify all three facets simultaneously
260(see below).
261One would use a slightly tailored version of this struct specific
262to each family (replacing each sockaddr by one
263of the family-specific type).
264Where the sockaddr itself is larger than the
265default size, one needs to modify the
266.Fn ioctl
267identifier itself to include the total size, as described in
268.Fn ioctl .
269.It Dv SIOCDIFADDR
270This requests deletes the specified address from the list
271associated with an interface.  It also uses the
272.Ar if_aliasreq
273structure to allow for the possibility of protocols allowing
274multiple masks or destination addresses, and also adopts the
275convention that specification of the default address means
276to delete the first address for the interface belonging to
277the address family in which the original socket was opened.
278.It Dv SIOCGIFCONF
279Get interface configuration list.  This request takes an
280.Ar ifconf
281structure (see below) as a value-result parameter.  The
282.Ar ifc_len
283field should be initially set to the size of the buffer
284pointed to by
285.Ar ifc_buf .
286On return it will contain the length, in bytes, of the
287configuration list.
288.El
289.Bd -literal
290/*
291* Structure used in SIOCAIFCONF request.
292*/
293struct ifaliasreq {
294        char    ifra_name[IFNAMSIZ];   /* if name, e.g. "en0" */
295        struct  sockaddr        ifra_addr;
296        struct  sockaddr        ifra_broadaddr;
297        struct  sockaddr        ifra_mask;
298};
299.Ed
300.Pp
301.Bd -literal
302/*
303* Structure used in SIOCGIFCONF request.
304* Used to retrieve interface configuration
305* for machine (useful for programs which
306* must know all networks accessible).
307*/
308struct ifconf {
309    int   ifc_len;		/* size of associated buffer */
310    union {
311        caddr_t    ifcu_buf;
312        struct     ifreq *ifcu_req;
313    } ifc_ifcu;
314#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
315#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
316};
317.Ed
318.Sh SEE ALSO
319.Xr socket 2 ,
320.Xr ioctl 2 ,
321.Xr intro 4 ,
322.Xr config 8 ,
323.Xr routed 8
324.Sh HISTORY
325The
326.Nm netintro
327manual appeared in
328.Bx 4.3 tahoe .
329