1NETDEVICE(7)               Linux Programmer's Manual              NETDEVICE(7)
2
3
4

NAME

6       netdevice - Low level access to Linux network devices
7

SYNOPSIS

9       #include <sys/ioctl.h>
10       #include <net/if.h>
11

DESCRIPTION

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 set.
76              IFF_PROMISC       Interface is in promiscuous mode.
77              IFF_NOTRAILERS    Avoid use of trailers.
78              IFF_ALLMULTI      Receive all multicast packets.
79              IFF_MASTER        Master of a load balancing bundle.
80              IFF_SLAVE         Slave of a load balancing bundle.
81              IFF_MULTICAST     Supports multicast
82              IFF_PORTSEL       Is able to select media type via ifmap.
83              IFF_AUTOMEDIA     Auto media selection active.
84              IFF_DYNAMIC       The  addresses  are lost when the interface goes
85                                down.
86              IFF_LOWER_UP      Driver signals L1 up (since Linux 2.6.17)
87              IFF_DORMANT       Driver signals dormant (since Linux 2.6.17)
88              IFF_ECHO          Echo sent packets (since Linux 2.6.25)
89
90
91              Setting the active flag word is a privileged operation, but  any
92              process may read it.
93
94       SIOCGIFMETRIC, SIOCSIFMETRIC
95              Get  or  set the metric of the device using ifr_metric.  This is
96              currently not implemented;  it  sets  ifr_metric  to  0  if  you
97              attempt  to read it and returns EOPNOTSUPP if you attempt to set
98              it.
99
100       SIOCGIFMTU, SIOCSIFMTU
101              Get or set the MTU (Maximum Transfer Unit)  of  a  device  using
102              ifr_mtu.   Setting  the  MTU is a privileged operation.  Setting
103              the MTU to too small values may cause kernel crashes.
104
105       SIOCGIFHWADDR, SIOCSIFHWADDR
106              Get or set the hardware address of a  device  using  ifr_hwaddr.
107              The hardware address is specified in a struct sockaddr.  sa_fam‐
108              ily contains the ARPHRD_* device type, sa_data the  L2  hardware
109              address starting from byte 0.  Setting the hardware address is a
110              privileged operation.
111
112       SIOCSIFHWBROADCAST
113              Set the hardware broadcast address of a device from  ifr_hwaddr.
114              This is a privileged operation.
115
116       SIOCGIFMAP, SIOCSIFMAP
117              Get  or  set  the interface's hardware parameters using ifr_map.
118              Setting the parameters is a privileged operation.
119
120                  struct ifmap {
121                      unsigned long   mem_start;
122                      unsigned long   mem_end;
123                      unsigned short  base_addr;
124                      unsigned char   irq;
125                      unsigned char   dma;
126                      unsigned char   port;
127                  };
128
129              The interpretation of the ifmap structure depends on the  device
130              driver and the architecture.
131
132       SIOCADDMULTI, SIOCDELMULTI
133              Add  an  address  to or delete an address from the device's link
134              layer multicast filters using ifr_hwaddr.  These are  privileged
135              operations.  See also packet(7) for an alternative.
136
137       SIOCGIFTXQLEN, SIOCSIFTXQLEN
138              Get or set the transmit queue length of a device using ifr_qlen.
139              Setting the transmit queue length is a privileged operation.
140
141       SIOCSIFNAME
142              Changes the name of  the  interface  specified  in  ifr_name  to
143              ifr_newname.   This  is  a  privileged  operation.   It  is only
144              allowed when the interface is not up.
145
146       SIOCGIFCONF
147              Return a list of interface (transport  layer)  addresses.   This
148              currently  means only addresses of the AF_INET (IPv4) family for
149              compatibility.  The user passes a ifconf structure  as  argument
150              to the ioctl.  It contains a pointer to an array of ifreq struc‐
151              tures in ifc_req and its length in bytes in ifc_len.  The kernel
152              fills  the  ifreqs  with all current L3 interface addresses that
153              are running: ifr_name contains the interface name (eth0:1 etc.),
154              ifr_addr the address.  The kernel returns with the actual length
155              in ifc_len.  If ifc_len is equal to the original length the buf‐
156              fer  probably  has overflowed and you should retry with a bigger
157              buffer to get all addresses.  When no  error  occurs  the  ioctl
158              returns 0; otherwise -1.  Overflow is not an error.
159
160       Most  protocols support their own ioctls to configure protocol-specific
161       interface options.  See the protocol man pages for a description.   For
162       configuring IP addresses see ip(7).
163
164       In  addition  some  devices  support  private  ioctls.   These  are not
165       described here.
166

NOTES

168       Strictly speaking, SIOCGIFCONF is IP specific and belongs in ip(7).
169
170       The names of interfaces with  no  addresses  or  that  don't  have  the
171       IFF_RUNNING flag set can be found via /proc/net/dev.
172
173       Local IPv6 IP addresses can be found via /proc/net or via rtnetlink(7).
174

BUGS

176       glibc 2.1 is missing the ifr_newname macro in <net/if.h>.  Add the fol‐
177       lowing to your program as a workaround:
178
179           #ifndef ifr_newname
180           #define ifr_newname     ifr_ifru.ifru_slave
181           #endif
182

SEE ALSO

184       proc(5), capabilities(7), ip(7), rtnetlink(7)
185

COLOPHON

187       This page is part of release 3.25 of the Linux  man-pages  project.   A
188       description  of  the project, and information about reporting bugs, can
189       be found at http://www.kernel.org/doc/man-pages/.
190
191
192
193Linux                             2009-01-14                      NETDEVICE(7)
Impressum