xref: /netbsd-src/share/man/man4/netintro.4 (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1.\"	$NetBSD: netintro.4,v 1.18 2003/08/07 10:31:03 agc Exp $
2.\"
3.\" Copyright (c) 1983, 1990, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"     @(#)netintro.4	8.2 (Berkeley) 11/30/93
31.\"
32.Dd August 29, 2000
33.Dt NETINTRO 4
34.Os
35.Sh NAME
36.Nm netintro
37.Nd introduction to networking facilities
38.Sh SYNOPSIS
39.In sys/types.h
40.In sys/socket.h
41.In net/route.h
42.In net/if.h
43.Sh DESCRIPTION
44This section is a general introduction to the networking facilities
45available in the system.
46Documentation in this part of section
474 is broken up into three areas:
48.Em protocol families
49(domains),
50.Em protocols ,
51and
52.Em network interfaces .
53.Pp
54All network protocols are associated with a specific
55.Em protocol family .
56A protocol family provides basic services to the protocol implementation
57to allow it to function within a specific network environment.
58These services may include packet fragmentation and reassembly,
59routing, addressing, and basic transport.
60A protocol family may support multiple methods of addressing, though
61the current protocol implementations do not.
62A protocol family normally comprises a number of protocols, one per
63.Xr socket 2
64type.
65It is not required that a protocol family support all socket types.
66A protocol family may contain multiple protocols supporting the
67same socket abstraction.
68.Pp
69A protocol supports one of the socket abstractions detailed in
70.Xr socket 2 .
71A specific protocol may be accessed either by creating a
72socket of the appropriate type and protocol family, or
73by requesting the protocol explicitly when creating a socket.
74Protocols normally accept only one type of address format,
75usually determined by the addressing structure inherent in
76the design of the protocol family/network architecture.
77Certain semantics of the basic socket abstractions are
78protocol specific.
79All protocols are expected to support the basic model for their
80particular socket type, but may, in addition, provide non-standard
81facilities or extensions to a mechanism.
82For 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 networking
89subsystem, interacting with the actual transport hardware.
90An interface may support one or more protocol families and/or address formats.
91The
92.Em SYNOPSIS
93section of each network interface entry gives a sample specification
94of the related drivers for use in providing a system description to the
95.Xr config 8
96program.
97.Pp
98The
99.Em DIAGNOSTICS
100section lists messages which may appear on the console
101and/or in the system error log,
102.Pa /var/log/messages
103(see
104.Xr syslogd 8 ) ,
105due to errors in device operation.
106.Sh PROTOCOLS
107The system currently supports the Internet protocols,
108the Xerox Network Systems (XNS)(tm) protocols, and some of the
109.Tn ISO OSI
110protocols.
111Raw socket interfaces are provided to the
112.Tn IP
113protocol layer of the Internet, and to the
114.Tn IDP
115protocol of Xerox
116.Tn NS .
117Consult the appropriate manual pages in this section for more
118information regarding the support for each protocol family.
119.Sh ADDRESSING
120Associated with each protocol family is an address format.
121All network address adhere to a general structure, called a sockaddr,
122described below.
123However, each protocol imposes finer and more specific structure,
124generally renaming the variant, which is discussed in the protocol
125family manual page alluded to above.
126.Bd -literal -offset indent
127struct sockaddr {
128	u_char	sa_len;
129    	u_char	sa_family;
130    	char	sa_data[14];
131};
132.Ed
133.Pp
134The field
135.Ar sa_len
136contains the total length of the of the structure, which may exceed 16 bytes.
137The following address values for
138.Ar sa_family
139are known to the system
140(and additional formats are defined for possible future implementation):
141.Bd -literal
142#define    AF_LOCAL     1    /* local to host (pipes, portals) */
143#define    AF_INET      2    /* internetwork: UDP, TCP, etc. */
144#define    AF_NS        6    /* Xerox NS protocols */
145#define    AF_CCITT     10   /* CCITT protocols, X.25 etc */
146#define    AF_HYLINK    15   /* NSC Hyperchannel */
147#define    AF_ISO       18   /* ISO protocols */
148.Ed
149.Sh ROUTING
150.Ux
151provides some packet routing facilities.
152The kernel maintains a routing information database, which
153is used in selecting the appropriate network interface when
154transmitting packets.
155.Pp
156A user process (or possibly multiple co-operating processes)
157maintains this database by sending messages over a special kind
158of socket.
159This supplants fixed size
160.Xr ioctl 2
161used in earlier releases.
162.Pp
163This facility is described in
164.Xr route 4 .
165.Sh INTERFACES
166Each network interface in a system corresponds to a
167path through which messages may be sent and received.
168A network interface usually has a hardware device associated with it,
169though certain interfaces such as the loopback interface,
170.Xr lo 4 ,
171do not.
172.Pp
173The following
174.Xr ioctl 2
175calls may be used to manipulate network interfaces.
176The
177.Xr ioctl 2
178is made on a socket (typically of type
179.Dv SOCK_DGRAM )
180in the desired domain.
181Most of the requests supported in earlier releases
182take an
183.Ar ifreq
184structure as its parameter.
185This structure has the form
186.Bd -literal
187struct	ifreq {
188#define    IFNAMSIZ    16
189    char    ifr_name[IFNAMSIZ];         /* if name, e.g. "en0" */
190    union {
191        struct    sockaddr ifru_addr;
192        struct    sockaddr ifru_dstaddr;
193        struct    sockaddr ifru_broadaddr;
194        short     ifru_flags;
195        int       ifru_metric;
196        caddr_t   ifru_data;
197    } ifr_ifru;
198#define ifr_addr      ifr_ifru.ifru_addr    /* address */
199#define ifr_dstaddr   ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
200#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
201#define ifr_flags     ifr_ifru.ifru_flags   /* flags */
202#define ifr_metric    ifr_ifru.ifru_metric  /* metric */
203#define ifr_data      ifr_ifru.ifru_data    /* for use by interface */
204};
205.Ed
206.Pp
207Calls which are now deprecated are:
208.Bl -tag -width SIOCGIFBRDADDR
209.It Dv SIOCSIFADDR
210Set interface address for protocol family.
211Following the address assignment, the ``initialization'' routine for
212the interface is called.
213.It Dv SIOCSIFDSTADDR
214Set point to point address for protocol family and interface.
215.It Dv SIOCSIFBRDADDR
216Set broadcast address for protocol family and interface.
217.El
218.Pp
219.Xr ioctl 2
220requests to obtain addresses and requests both to set and
221retrieve other data are still fully supported
222and use the
223.Ar ifreq
224structure:
225.Bl -tag -width SIOCGIFBRDADDR
226.It Dv SIOCGIFADDR
227Get interface address for protocol family.
228.It Dv SIOCGIFDSTADDR
229Get point to point address for protocol family and interface.
230.It Dv SIOCGIFBRDADDR
231Get broadcast address for protocol family and interface.
232.It Dv SIOCSIFFLAGS
233Set interface flags field.
234If the interface is marked down, any processes currently routing
235packets through the interface are notified; some interfaces may be
236reset so that incoming packets are no longer received.
237When marked up again, the interface is reinitialized.
238.It Dv SIOCGIFFLAGS
239Get interface flags.
240.It Dv SIOCSIFMETRIC
241Set interface routing metric.
242The metric is used only by user-level routers.
243.It Dv SIOCGIFMETRIC
244Get interface metric.
245.El
246.Pp
247There are two requests that make use of a new structure:
248.Bl -tag -width SIOCGIFBRDADDR
249.It Dv SIOCAIFADDR
250An interface may have more than one address associated with it
251in some protocols.
252This request provides a means to add additional addresses (or modify
253characteristics of the primary address if the default address for
254the address family is specified).
255Rather than making separate calls to set destination or broadcast
256addresses, or network masks (now an integral feature of multiple
257protocols) a separate structure,
258.Ar ifaliasreq ,
259is used to specify all three facets
260simultaneously (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.Xr ioctl 2
267identifier itself to include the total size, as described in
268.Xr ioctl 2 .
269.It Dv SIOCDIFADDR
270This requests deletes the specified address from the list
271associated with an interface.
272It also uses the
273.Ar ifaliasreq
274structure to allow for the possibility of protocols allowing
275multiple masks or destination addresses, and also adopts the
276convention that specification of the default address means
277to delete the first address for the interface belonging to
278the address family in which the original socket was opened.
279.El
280.Pp
281Request making use of the
282.Ar ifconf
283structure:
284.Bl -tag -width SIOCGIFBRDADDR
285.It Dv SIOCGIFCONF
286Get interface configuration list.
287This request takes an
288.Ar ifconf
289structure (see below) as a value-result parameter.
290The
291.Ar ifc_len
292field should be initially set to the size of the buffer
293pointed to by
294.Ar ifc_buf .
295On return it will contain the length, in bytes, of the
296configuration list.
297.El
298.Bd -literal
299/*
300* Structure used in SIOC[AD]IFADDR request.
301*/
302struct ifaliasreq {
303        char    ifra_name[IFNAMSIZ];   /* if name, e.g. "en0" */
304        struct  sockaddr        ifra_addr;
305        struct  sockaddr        ifra_dstaddr;
306#define	ifra_broadaddr  ifra_dstaddr
307        struct  sockaddr        ifra_mask;
308};
309.Ed
310.Pp
311.Bd -literal
312/*
313* Structure used in SIOCGIFCONF request.
314* Used to retrieve interface configuration
315* for machine (useful for programs which
316* must know all networks accessible).
317*/
318struct ifconf {
319    int   ifc_len;		/* size of associated buffer */
320    union {
321        caddr_t    ifcu_buf;
322        struct     ifreq *ifcu_req;
323    } ifc_ifcu;
324#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
325#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
326};
327.Ed
328.Sh SEE ALSO
329.Xr ioctl 2 ,
330.Xr socket 2 ,
331.Xr intro 4 ,
332.Xr config 8 ,
333.Xr routed 8
334.Sh HISTORY
335The
336.Nm netintro
337manual appeared in
338.Bx 4.3 Tahoe .
339