1NETDEVICE(7) Linux Programmer's Manual NETDEVICE(7)
2
3
4
6 netdevice - low-level access to Linux network devices
7
9 #include <sys/ioctl.h>
10 #include <net/if.h>
11
13 This man page describes the sockets interface which is used to config‐
14 ure network devices.
15
16 Linux supports some standard ioctls to configure network devices. They
17 can be used on any socket's file descriptor regardless of the family or
18 type. Most of them pass an ifreq structure:
19
20 struct ifreq {
21 char ifr_name[IFNAMSIZ]; /* Interface name */
22 union {
23 struct sockaddr ifr_addr;
24 struct sockaddr ifr_dstaddr;
25 struct sockaddr ifr_broadaddr;
26 struct sockaddr ifr_netmask;
27 struct sockaddr ifr_hwaddr;
28 short ifr_flags;
29 int ifr_ifindex;
30 int ifr_metric;
31 int ifr_mtu;
32 struct ifmap ifr_map;
33 char ifr_slave[IFNAMSIZ];
34 char ifr_newname[IFNAMSIZ];
35 char *ifr_data;
36 };
37 };
38
39 Normally, the user specifies which device to affect by setting ifr_name
40 to the name of the interface. All other members of the structure may
41 share memory.
42
43 Ioctls
44 If an ioctl is marked as privileged, then using it requires an effec‐
45 tive user ID of 0 or the CAP_NET_ADMIN capability. If this is not the
46 case, EPERM will be returned.
47
48 SIOCGIFNAME
49 Given the ifr_ifindex, return the name of the interface in
50 ifr_name. This is the only ioctl which returns its result in
51 ifr_name.
52
53 SIOCGIFINDEX
54 Retrieve the interface index of the interface into ifr_ifindex.
55
56 SIOCGIFFLAGS, SIOCSIFFLAGS
57 Get or set the active flag word of the device. ifr_flags con‐
58 tains a bit mask of the following values:
59
60 Device flags
61 IFF_UP Interface is running.
62 IFF_BROADCAST Valid broadcast address set.
63 IFF_DEBUG Internal debugging flag.
64 IFF_LOOPBACK Interface is a loopback interface.
65 IFF_POINTOPOINT Interface is a point-to-point link.
66
67 IFF_RUNNING Resources allocated.
68 IFF_NOARP No arp protocol, L2 destination address not
69 set.
70 IFF_PROMISC Interface is in promiscuous mode.
71 IFF_NOTRAILERS Avoid use of trailers.
72 IFF_ALLMULTI Receive all multicast packets.
73 IFF_MASTER Master of a load balancing bundle.
74 IFF_SLAVE Slave of a load balancing bundle.
75 IFF_MULTICAST Supports multicast
76 IFF_PORTSEL Is able to select media type via ifmap.
77 IFF_AUTOMEDIA Auto media selection active.
78 IFF_DYNAMIC The addresses are lost when the interface
79 goes down.
80 IFF_LOWER_UP Driver signals L1 up (since Linux 2.6.17)
81 IFF_DORMANT Driver signals dormant (since Linux 2.6.17)
82 IFF_ECHO Echo sent packets (since Linux 2.6.25)
83
84 Setting the active flag word is a privileged operation, but any process
85 may read it.
86
87 SIOCGIFPFLAGS, SIOCSIFPFLAGS
88 Get or set extended (private) flags for the device. ifr_flags
89 contains a bit mask of the following values:
90
91 Private flags
92 IFF_802_1Q_VLAN Interface is 802.1Q VLAN device.
93 IFF_EBRIDGE Interface is Ethernet bridging device.
94 IFF_SLAVE_INACTIVE Interface is inactive bonding slave.
95 IFF_MASTER_8023AD Interface is 802.3ad bonding master.
96 IFF_MASTER_ALB Interface is balanced-alb bonding master.
97 IFF_BONDING Interface is a bonding master or slave.
98 IFF_SLAVE_NEEDARP Interface needs ARPs for validation.
99 IFF_ISATAP Interface is RFC4214 ISATAP interface.
100
101 Setting the extended (private) interface flags is a privileged opera‐
102 tion.
103
104 SIOCGIFADDR, SIOCSIFADDR
105 Get or set the address of the device using ifr_addr. Setting
106 the interface address is a privileged operation. For compati‐
107 bility, only AF_INET addresses are accepted or returned.
108
109 SIOCGIFDSTADDR, SIOCSIFDSTADDR
110 Get or set the destination address of a point-to-point device
111 using ifr_dstaddr. For compatibility, only AF_INET addresses
112 are accepted or returned. Setting the destination address is a
113 privileged operation.
114
115 SIOCGIFBRDADDR, SIOCSIFBRDADDR
116 Get or set the broadcast address for a device using ifr_brdaddr.
117 For compatibility, only AF_INET addresses are accepted or
118 returned. Setting the broadcast address is a privileged opera‐
119 tion.
120
121 SIOCGIFNETMASK, SIOCSIFNETMASK
122 Get or set the network mask for a device using ifr_netmask. For
123 compatibility, only AF_INET addresses are accepted or returned.
124 Setting the network mask is a privileged operation.
125
126 SIOCGIFMETRIC, SIOCSIFMETRIC
127 Get or set the metric of the device using ifr_metric. This is
128 currently not implemented; it sets ifr_metric to 0 if you
129 attempt to read it and returns EOPNOTSUPP if you attempt to set
130 it.
131
132 SIOCGIFMTU, SIOCSIFMTU
133 Get or set the MTU (Maximum Transfer Unit) of a device using
134 ifr_mtu. Setting the MTU is a privileged operation. Setting
135 the MTU to too small values may cause kernel crashes.
136
137 SIOCGIFHWADDR, SIOCSIFHWADDR
138 Get or set the hardware address of a device using ifr_hwaddr.
139 The hardware address is specified in a struct sockaddr. sa_fam‐
140 ily contains the ARPHRD_* device type, sa_data the L2 hardware
141 address starting from byte 0. Setting the hardware address is a
142 privileged operation.
143
144 SIOCSIFHWBROADCAST
145 Set the hardware broadcast address of a device from ifr_hwaddr.
146 This is a privileged operation.
147
148 SIOCGIFMAP, SIOCSIFMAP
149 Get or set the interface's hardware parameters using ifr_map.
150 Setting the parameters is a privileged operation.
151
152 struct ifmap {
153 unsigned long mem_start;
154 unsigned long mem_end;
155 unsigned short base_addr;
156 unsigned char irq;
157 unsigned char dma;
158 unsigned char port;
159 };
160
161 The interpretation of the ifmap structure depends on the device
162 driver and the architecture.
163
164 SIOCADDMULTI, SIOCDELMULTI
165 Add an address to or delete an address from the device's link
166 layer multicast filters using ifr_hwaddr. These are privileged
167 operations. See also packet(7) for an alternative.
168
169 SIOCGIFTXQLEN, SIOCSIFTXQLEN
170 Get or set the transmit queue length of a device using ifr_qlen.
171 Setting the transmit queue length is a privileged operation.
172
173 SIOCSIFNAME
174 Changes the name of the interface specified in ifr_name to
175 ifr_newname. This is a privileged operation. It is allowed
176 only when the interface is not up.
177
178 SIOCGIFCONF
179 Return a list of interface (transport layer) addresses. This
180 currently means only addresses of the AF_INET (IPv4) family for
181 compatibility. Unlike the others, this ioctl passes an ifconf
182 structure:
183
184 struct ifconf {
185 int ifc_len; /* size of buffer */
186 union {
187 char *ifc_buf; /* buffer address */
188 struct ifreq *ifc_req; /* array of structures */
189 };
190 };
191
192 If ifc_req is NULL, SIOCGIFCONF returns the necessary buffer
193 size in bytes for receiving all available addresses in ifc_len.
194 Otherwise, ifc_req contains a pointer to an array of ifreq
195 structures to be filled with all currently active L3 interface
196 addresses. ifc_len contains the size of the array in bytes.
197 Within each ifreq structure, ifr_name will receive the interface
198 name, and ifr_addr the address. The actual number of bytes
199 transferred is returned in ifc_len.
200
201 If the size specified by ifc_len is insufficient to store all
202 the addresses, the kernel will skip the exceeding ones and
203 return success. There is no reliable way of detecting this con‐
204 dition once it has occurred. It is therefore recommended to
205 either determine the necessary buffer size beforehand by calling
206 SIOCGIFCONF with ifc_req set to NULL, or to retry the call with
207 a bigger buffer whenever ifc_len upon return differs by less
208 than sizeof(struct ifreq) from its original value.
209
210 If an error occurs accessing the ifconf or ifreq structures,
211 EFAULT will be returned.
212
213 Most protocols support their own ioctls to configure protocol-specific
214 interface options. See the protocol man pages for a description. For
215 configuring IP addresses, see ip(7).
216
217 In addition, some devices support private ioctls. These are not
218 described here.
219
221 Strictly speaking, SIOCGIFCONF and the other ioctls that accept or
222 return only AF_INET socket addresses, are IP-specific and belong in
223 ip(7).
224
225 The names of interfaces with no addresses or that don't have the
226 IFF_RUNNING flag set can be found via /proc/net/dev.
227
228 Local IPv6 IP addresses can be found via /proc/net or via rtnetlink(7).
229
231 glibc 2.1 is missing the ifr_newname macro in <net/if.h>. Add the fol‐
232 lowing to your program as a workaround:
233
234 #ifndef ifr_newname
235 #define ifr_newname ifr_ifru.ifru_slave
236 #endif
237
239 proc(5), capabilities(7), ip(7), rtnetlink(7)
240
242 This page is part of release 4.15 of the Linux man-pages project. A
243 description of the project, information about reporting bugs, and the
244 latest version of this page, can be found at
245 https://www.kernel.org/doc/man-pages/.
246
247
248
249Linux 2017-09-15 NETDEVICE(7)