Imported upstream version 1.5
[manpages-zh.git] / raw / man7 / netdevice.7
blob792e768de3e1c8376a0387e14dc1182f6a7ea39b
1 '\" t
2 .\" Don't change the first line, it tells man that tbl is needed.
3 .\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
4 .\" Permission is granted to distribute possibly modified copies
5 .\" of this page provided the header is included verbatim,
6 .\" and in case of nontrivial modification author and date
7 .\" of the modification is added to the header.
8 .\" $Id: netdevice.7,v 1.1 2003/12/20 03:31:53 bbbush Exp $
9 .TH NETDEVICE  7 1999-05-02 "Linux Man Page" "Linux Programmer's Manual" 
10 .SH NAME
11 netdevice \- Low level access to Linux network devices.
12 .SH SYNOPSIS
13 .B "#include <sys/ioctl.h>"
14 .br
15 .B "#include <net/if.h>"
16 .SH DESCRIPTION
17 This man page describes the sockets interface which is used to configure
18 network devices.
20 Linux supports some standard ioctls to configure network devices. They 
21 can be used on any socket's file descriptor regardless of the family or type. 
22 They pass an 
23 .B ifreq 
24 structure:
26 .nf
27 .ta 4 12 20
28 struct ifreq {
29         char    ifr_name[IFNAMSIZ];     /* Interface name */
30         union {
31                 struct sockaddr ifr_addr;
32                 struct sockaddr ifr_dstaddr;
33                 struct sockaddr ifr_broadaddr;
34                 struct sockaddr ifr_netmask;
35                 struct sockaddr ifr_hwaddr;
36                 short   ifr_flags;
37                 int     ifr_ifindex;
38                 int     ifr_metric;
39                 int     ifr_mtu;
40                 struct ifmap    ifr_map;
41                 char    ifr_slave[IFNAMSIZ];
42                 char    ifr_newname[IFNAMSIZ];
43                 char *  ifr_data;
44         };
47 struct ifconf { 
48         int ifc_len;            /* size of buffer */
49         union {            
50                 char *  ifc_buf; /* buffer address */ 
51                 struct ifreq *ifc_req; /* array of structures */
52         };  
53 };         
54 .ta
55 .fi
57 Normally, the user specifies which device to affect by setting
58 .B ifr_name
59 to the name of the interface. All other members of the structure may 
60 share memory. 
62 .SH IOCTLS
63 If an ioctl is marked as privileged then using it requires an effective
64 user id of 0 or the
65 .B CAP_NET_ADMIN
66 capability. If this is not the case 
67 .B EPERM
68 will be returned.
70 .TP
71 .B SIOCGIFNAME
72 Given the
73 .BR ifr_ifindex ,
74 return the name of the interface in
75 .BR ifr_name .
76 This is the only ioctl which returns its result in
77 .BR ifr_name .
79 .TP
80 .B SIOCGIFINDEX
81 Retrieve the interface index of the interface into
82 .BR ifr_ifindex .
84 .TP
85 .BR SIOCGIFFLAGS ", " SIOCSIFFLAGS
86 Get or set the active flag word of the device.
87 .B ifr_flags
88 contains a bitmask of the following values:
90 .TS
91 tab(:);
92 c s
93 l l.
94 Device flags
95 IFF_UP:Interface is running.
96 IFF_BROADCAST:Valid broadcast address set.
97 IFF_DEBUG:Internal debugging flag.
98 IFF_LOOPBACK:Interface is a loopback interface.
99 IFF_POINTOPOINT:Interface is a point-to-point link.
100 IFF_RUNNING:Resources allocated.
101 IFF_NOARP:No arp protocol, L2 destination address not set.
102 IFF_PROMISC:Interface is in promiscuous mode.
103 IFF_NOTRAILERS:Avoid use of trailers.
104 IFF_ALLMULTI:Receive all multicast packets.
105 IFF_MASTER:Master of a load balancing bundle.
106 IFF_SLAVE:Slave of a load balancing bundle.
107 IFF_MULTICAST:Supports multicast
108 IFF_PORTSEL:Is able to select media type via ifmap.
109 IFF_AUTOMEDIA:Auto media selection active.
110 IFF_DYNAMIC:T{
111 The addresses are lost when the interface goes down.
113 .TE 
115 Setting the active flag word is a privileged operation, but any
116 process may read it.
118 .BR SIOCGIFMETRIC ", " SIOCSIFMETRIC
119 Get or set the metric of the device using
120 .BR ifr_metric .
121 This is currently not implemented; it sets
122 .B ifr_metric
123 to 0 if you attempt to read it and returns
124 .B EOPNOTSUPP
125 if you attempt to set it.
127 .BR SIOCGIFMTU ", " SIOCSIFMTU
128 Get or set the MTU (Maximum Transfer Unit) of a device using
129 .BR ifr_mtu .
130 Setting the MTU is a privileged operation. Setting the MTU to
131 too small values may cause kernel crashes.
133 .BR SIOCGIFHWADDR ", " SIOCSIFHWADDR
134 Get or set the hardware address of a device using
135 .BR ifr_hwaddr .
136 The hardware address is specified in a struct
137 .IR sockaddr .
138 .I sa_family 
139 contains the ARPHRD_* device type, 
140 .I sa_data
141 the L2 hardware address starting from byte 0. 
142 Setting the hardware address is a privileged operation.
144 .B SIOCSIFHWBROADCAST
145 Set the hardware broadcast address of a device from
146 .BR ifr_hwaddr .
147 This is a privileged operation.
149 .BR SIOCGIFMAP ", " SIOCSIFMAP
150 Get or set the interface's hardware parameters using
151 .BR ifr_map .
152 Setting the parameters is a privileged operation.
155 .ta 4 20 42
156 struct ifmap 
158         unsigned long   mem_start;
159         unsigned long   mem_end;
160         unsigned short  base_addr; 
161         unsigned char   irq;    
162         unsigned char   dma; 
163         unsigned char   port; 
168 The interpretation of the ifmap structure depends on the device driver
169 and the architecture.
171 .BR SIOCADDMULTI ", " SIOCDELMULTI
172 Add an address to or delete an address from the device's link layer
173 multicast filters using
174 .BR ifr_hwaddr .
175 These are privileged operations.
176 See also
177 .BR packet (7)
178 for an alternative.
180 .BR SIOCGIFTXQLEN ", " SIOCSIFTXQLEN
181 Get or set the transmit queue length of a device using
182 .BR ifr_qlen .
183 Setting the transmit queue length is a privileged operation.
185 .B SIOCSIFNAME
186 Changes the name of the interface specified in 
187 .BR ifr_name
189 .BR ifr_newname .
190 This is a privileged operation. It is only allowed when the interface
191 is not up.
193 .B SIOCGIFCONF
194 Return a list of interface (transport layer) addresses. This currently
195 means only addresses of the AF_INET (IPv4) family for compatibility. 
196 The user passes a 
197 .B ifconf
198 structure as argument to the ioctl. It contains a pointer to an array of
199 .I ifreq
200 structures in 
201 .B ifc_req
202 and its length in bytes in 
203 .B ifc_len.
204 The kernel fills the ifreqs with all current L3 interface addresses that
205 are running: 
206 .I ifr_name 
207 contains the interface name (eth0:1 etc.),  
208 .I ifr_addr
209 the address.
210 The kernel returns with the actual length in 
211 .IR ifc_len .
212 If 
213 .I ifc_len
214 is equal to the original length the buffer probably has overflowed
215 and you should retry with a bigger buffer to get all addresses.
216 When no error occurs the ioctl returns 0;
217 otherwise \-1. Overflow is no error.
218 \" XXX Slaving isn't supported in 2.2
219 .\" .TP
220 .\" .BR SIOCGIFSLAVE ", " SIOCSIFSLAVE
221 .\" Get or set the slave device using
222 .\" .BR ifr_slave .
223 .\" Setting the slave device is a privileged operation.
224 .\" .PP
225 .\" XXX add amateur radio stuff.
227 Most protocols support their own ioctls to configure protocol specific 
228 interface options. See the protocol man pages for a description.
229 For configuring IP addresses see 
230 .BR ip (7).
232 In addition some devices support private ioctls. These are not described here.
233 .SH NOTES
234 Strictly seen,
235 .B SIOCGIFCONF 
236 is IP specific and belongs in 
237 .BR ip (7).
239 The names of interfaces with no addresses or that don't have the
240 .B IFF_RUNNING 
241 flag set can be found via
242 .IR /proc/net/dev .
244 Local IPv6 IP addresses can be found via /proc/net or via 
245 .BR rtnetlink (7).
246 .SH BUGS
247 glibc 2.1 is missing the 
248 .I ifr_newname 
249 macro in net/if.h. Add the following to your program as workaround:
253 .ta 4 20 42
254 #ifndef ifr_newname
255 #define ifr_newname     ifr_ifru.ifru_slave
256 #endif
260 .SH "SEE ALSO"
261 .BR ip (7),
262 .BR proc (7),
263 .BR rtnetlink (7)