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

53       If an ioctl is marked as privileged then using it requires an effective
54       user  ID  of 0 or the CAP_NET_ADMIN capability. If this is not the case
55       EPERM will be returned.
56
57
58       SIOCGIFNAME
59              Given the ifr_ifindex, return  the  name  of  the  interface  in
60              ifr_name.   This  is  the only ioctl which returns its result in
61              ifr_name.
62
63
64       SIOCGIFINDEX
65              Retrieve the interface index of the interface into ifr_ifindex.
66
67
68       SIOCGIFFLAGS, SIOCSIFFLAGS
69              Get or set the active flag word of the device.   ifr_flags  con‐
70              tains a bitmask of the following values:
71
72
73                                         Device flags
74              IFF_UP            Interface is running.
75              IFF_BROADCAST     Valid broadcast address set.
76              IFF_DEBUG         Internal debugging flag.
77              IFF_LOOPBACK      Interface is a loopback interface.
78              IFF_POINTOPOINT   Interface is a point-to-point link.
79              IFF_RUNNING       Resources allocated.
80              IFF_NOARP         No arp protocol, L2 destination address not set.
81              IFF_PROMISC       Interface is in promiscuous mode.
82              IFF_NOTRAILERS    Avoid use of trailers.
83              IFF_ALLMULTI      Receive all multicast packets.
84              IFF_MASTER        Master of a load balancing bundle.
85              IFF_SLAVE         Slave of a load balancing bundle.
86              IFF_MULTICAST     Supports multicast
87              IFF_PORTSEL       Is able to select media type via ifmap.
88              IFF_AUTOMEDIA     Auto media selection active.
89              IFF_DYNAMIC       The  addresses  are lost when the interface goes
90                                down.
91
92              Setting the active flag word is a privileged operation, but  any
93              process may read it.
94
95       SIOCGIFMETRIC, SIOCSIFMETRIC
96              Get  or  set the metric of the device using ifr_metric.  This is
97              currently not implemented;  it  sets  ifr_metric  to  0  if  you
98              attempt  to read it and returns EOPNOTSUPP if you attempt to set
99              it.
100
101       SIOCGIFMTU, SIOCSIFMTU
102              Get or set the MTU (Maximum Transfer Unit)  of  a  device  using
103              ifr_mtu.  Setting the MTU is a privileged operation. Setting the
104              MTU to too small values may cause kernel crashes.
105
106       SIOCGIFHWADDR, SIOCSIFHWADDR
107              Get or set the hardware address of a  device  using  ifr_hwaddr.
108              The hardware address is specified in a struct sockaddr.  sa_fam‐
109              ily contains the ARPHRD_* device type, sa_data the  L2  hardware
110              address starting from byte 0.  Setting the hardware address is a
111              privileged operation.
112
113       SIOCSIFHWBROADCAST
114              Set the hardware broadcast address of a device from  ifr_hwaddr.
115              This is a privileged operation.
116
117       SIOCGIFMAP, SIOCSIFMAP
118              Get  or  set  the interface's hardware parameters using ifr_map.
119              Setting the parameters is a privileged operation.
120
121              struct ifmap {
122                  unsigned long   mem_start;
123                  unsigned long   mem_end;
124                  unsigned short  base_addr;
125                  unsigned char   irq;
126                  unsigned char   dma;
127                  unsigned char   port;
128              };
129
130              The interpretation of the ifmap structure depends on the  device
131              driver and the architecture.
132
133       SIOCADDMULTI, SIOCDELMULTI
134              Add  an  address  to or delete an address from the device's link
135              layer multicast filters using ifr_hwaddr.  These are  privileged
136              operations.  See also packet(7) for an alternative.
137
138       SIOCGIFTXQLEN, SIOCSIFTXQLEN
139              Get or set the transmit queue length of a device using ifr_qlen.
140              Setting the transmit queue length is a privileged operation.
141
142       SIOCSIFNAME
143              Changes the name of  the  interface  specified  in  ifr_name  to
144              ifr_newname.  This is a privileged operation. It is only allowed
145              when the interface is not up.
146
147       SIOCGIFCONF
148              Return a list of interface  (transport  layer)  addresses.  This
149              currently  means only addresses of the AF_INET (IPv4) family for
150              compatibility.  The user passes a ifconf structure  as  argument
151              to  the ioctl. It contains a pointer to an array of ifreq struc‐
152              tures in ifc_req and its length in bytes in ifc_len.  The kernel
153              fills  the  ifreqs  with all current L3 interface addresses that
154              are running: ifr_name contains the interface name (eth0:1 etc.),
155              ifr_addr the address.  The kernel returns with the actual length
156              in ifc_len.  If ifc_len is equal to the original length the buf‐
157              fer  probably  has overflowed and you should retry with a bigger
158              buffer to get all addresses.  When no  error  occurs  the  ioctl
159              returns 0; otherwise -1. Overflow is not an error.
160
161       Most  protocols support their own ioctls to configure protocol specific
162       interface options. See the protocol man pages for a  description.   For
163       configuring IP addresses see ip(7).
164
165       In  addition  some  devices  support  private  ioctls.   These  are not
166       described here.
167

NOTES

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

BUGS

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

SEE ALSO

185       capabilities(7), ip(7), proc(7), rtnetlink(7)
186
187
188
189Linux Man Page                    1999-05-02                      NETDEVICE(7)
Impressum