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. They 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 struct ifconf {
40 int ifc_len; /* size of buffer */
41 union {
42 char *ifc_buf; /* buffer address */
43 struct ifreq *ifc_req; /* array of structures */
44 };
45 };
46
47 Normally, the user specifies which device to affect by setting ifr_name
48 to the name of the interface. All other members of the structure may
49 share memory.
50
51 Ioctls
52 If an ioctl is marked as privileged then using it requires an effective
53 user ID of 0 or the CAP_NET_ADMIN capability. If this is not the case
54 EPERM will be returned.
55
56 SIOCGIFNAME
57 Given the ifr_ifindex, return the name of the interface in
58 ifr_name. This is the only ioctl which returns its result in
59 ifr_name.
60
61 SIOCGIFINDEX
62 Retrieve the interface index of the interface into ifr_ifindex.
63
64 SIOCGIFFLAGS, SIOCSIFFLAGS
65 Get or set the active flag word of the device. ifr_flags con‐
66 tains a bit mask of the following values:
67
68 Device flags
69 IFF_UP Interface is running.
70 IFF_BROADCAST Valid broadcast address set.
71 IFF_DEBUG Internal debugging flag.
72 IFF_LOOPBACK Interface is a loopback interface.
73 IFF_POINTOPOINT Interface is a point-to-point link.
74 IFF_RUNNING Resources allocated.
75 IFF_NOARP No arp protocol, L2 destination address not
76 set.
77 IFF_PROMISC Interface is in promiscuous mode.
78 IFF_NOTRAILERS Avoid use of trailers.
79 IFF_ALLMULTI Receive all multicast packets.
80 IFF_MASTER Master of a load balancing bundle.
81 IFF_SLAVE Slave of a load balancing bundle.
82 IFF_MULTICAST Supports multicast
83 IFF_PORTSEL Is able to select media type via ifmap.
84 IFF_AUTOMEDIA Auto media selection active.
85 IFF_DYNAMIC The addresses are lost when the interface
86 goes down.
87 IFF_LOWER_UP Driver signals L1 up (since Linux 2.6.17)
88 IFF_DORMANT Driver signals dormant (since Linux 2.6.17)
89 IFF_ECHO Echo sent packets (since Linux 2.6.25)
90
91 Setting the active flag word is a privileged operation, but any
92 process may read it.
93
94 SIOCGIFPFLAGS, SIOCSIFPFLAGS
95 Get or set extended (private) flags for the device. ifr_flags
96 contains a bit mask of the following values:
97
98 Private flags
99 IFF_802_1Q_VLAN Interface is 802.1Q VLAN device.
100 IFF_EBRIDGE Interface is Ethernet bridging device.
101 IFF_SLAVE_INACTIVE Interface is inactive bonding slave.
102 IFF_MASTER_8023AD Interface is 802.3ad bonding master.
103 IFF_MASTER_ALB Interface is balanced-alb bonding master.
104 IFF_BONDING Interface is a bonding master or slave.
105 IFF_SLAVE_NEEDARP Interface needs ARPs for validation.
106 IFF_ISATAP Interface is RFC4214 ISATAP interface.
107
108 Setting the extended (private) interface flags is a privileged
109 operation.
110
111 SIOCGIFADDR, SIOCSIFADDR
112 Get or set the address of the device using ifr_addr. Setting
113 the interface address is a privileged operation. For compati‐
114 bility, only AF_INET addresses are accepted or returned.
115
116 SIOCGIFDSTADDR, SIOCSIFDSTADDR
117 Get or set the destination address of a point-to-point device
118 using ifr_dstaddr. For compatibility, only AF_INET addresses
119 are accepted or returned. Setting the destination address is a
120 privileged operation.
121
122 SIOCGIFBRDADDR, SIOCSIFBRDADDR
123 Get or set the broadcast address for a device using ifr_brdaddr.
124 For compatibility, only AF_INET addresses are accepted or
125 returned. Setting the broadcast address is a privileged opera‐
126 tion.
127
128 SIOCGIFNETMASK, SIOCSIFNETMASK
129 Get or set the network mask for a device using ifr_netmask. For
130 compatibility, only AF_INET addresses are accepted or returned.
131 Setting the network mask is a privileged operation.
132
133 SIOCGIFMETRIC, SIOCSIFMETRIC
134 Get or set the metric of the device using ifr_metric. This is
135 currently not implemented; it sets ifr_metric to 0 if you
136 attempt to read it and returns EOPNOTSUPP if you attempt to set
137 it.
138
139 SIOCGIFMTU, SIOCSIFMTU
140 Get or set the MTU (Maximum Transfer Unit) of a device using
141 ifr_mtu. Setting the MTU is a privileged operation. Setting
142 the MTU to too small values may cause kernel crashes.
143
144 SIOCGIFHWADDR, SIOCSIFHWADDR
145 Get or set the hardware address of a device using ifr_hwaddr.
146 The hardware address is specified in a struct sockaddr. sa_fam‐
147 ily contains the ARPHRD_* device type, sa_data the L2 hardware
148 address starting from byte 0. Setting the hardware address is a
149 privileged operation.
150
151 SIOCSIFHWBROADCAST
152 Set the hardware broadcast address of a device from ifr_hwaddr.
153 This is a privileged operation.
154
155 SIOCGIFMAP, SIOCSIFMAP
156 Get or set the interface's hardware parameters using ifr_map.
157 Setting the parameters is a privileged operation.
158
159 struct ifmap {
160 unsigned long mem_start;
161 unsigned long mem_end;
162 unsigned short base_addr;
163 unsigned char irq;
164 unsigned char dma;
165 unsigned char port;
166 };
167
168 The interpretation of the ifmap structure depends on the device
169 driver and the architecture.
170
171 SIOCADDMULTI, SIOCDELMULTI
172 Add an address to or delete an address from the device's link
173 layer multicast filters using ifr_hwaddr. These are privileged
174 operations. See also packet(7) for an alternative.
175
176 SIOCGIFTXQLEN, SIOCSIFTXQLEN
177 Get or set the transmit queue length of a device using ifr_qlen.
178 Setting the transmit queue length is a privileged operation.
179
180 SIOCSIFNAME
181 Changes the name of the interface specified in ifr_name to
182 ifr_newname. This is a privileged operation. It is allowed
183 only when the interface is not up.
184
185 SIOCGIFCONF
186 Return a list of interface (transport layer) addresses. This
187 currently means only addresses of the AF_INET (IPv4) family for
188 compatibility. The user passes a ifconf structure as argument
189 to the ioctl. It contains a pointer to an array of ifreq struc‐
190 tures in ifc_req and its length in bytes in ifc_len. The kernel
191 fills the ifreqs with all current L3 interface addresses that
192 are running: ifr_name contains the interface name (eth0:1 etc.),
193 ifr_addr the address. The kernel returns with the actual length
194 in ifc_len. If ifc_len is equal to the original length the buf‐
195 fer probably has overflowed and you should retry with a bigger
196 buffer to get all addresses. When no error occurs the ioctl
197 returns 0; otherwise -1. Overflow is not an error.
198
199 Most protocols support their own ioctls to configure protocol-specific
200 interface options. See the protocol man pages for a description. For
201 configuring IP addresses see ip(7).
202
203 In addition some devices support private ioctls. These are not
204 described here.
205
207 Strictly speaking, SIOCGIFCONF and the other ioctls that accept or
208 return only AF_INET socket addresses, are IP specific and belong in
209 ip(7).
210
211 The names of interfaces with no addresses or that don't have the
212 IFF_RUNNING flag set can be found via /proc/net/dev.
213
214 Local IPv6 IP addresses can be found via /proc/net or via rtnetlink(7).
215
217 glibc 2.1 is missing the ifr_newname macro in <net/if.h>. Add the fol‐
218 lowing to your program as a workaround:
219
220 #ifndef ifr_newname
221 #define ifr_newname ifr_ifru.ifru_slave
222 #endif
223
225 proc(5), capabilities(7), ip(7), rtnetlink(7)
226
228 This page is part of release 3.53 of the Linux man-pages project. A
229 description of the project, and information about reporting bugs, can
230 be found at http://www.kernel.org/doc/man-pages/.
231
232
233
234Linux 2012-04-26 NETDEVICE(7)