# netdevice - low-level access to Linux network devices - man(7) - [phpMan]

[_netdevice_(7)](https://www.chedong.com/phpMan.php/man/netdevice/7/markdown)                      Miscellaneous Information Manual                      [_netdevice_(7)](https://www.chedong.com/phpMan.php/man/netdevice/7/markdown)

## NAME
       netdevice - low-level access to Linux network devices

## SYNOPSIS
### #include <sys/ioctl.h>
### #include <net/if.h>

## DESCRIPTION
       This man page describes the sockets interface which is used to configure network devices.

       Linux  supports  some  standard ioctls to configure network devices.  They can be used on any
       socket's file descriptor regardless of the family or type.  Most of them pass an _ifreq_ struc‐
       ture:

           struct ifreq {
               char ifr_name[IFNAMSIZ]; /* Interface name */
               union {
                   struct sockaddr ifr_addr;
                   struct sockaddr ifr_dstaddr;
                   struct sockaddr ifr_broadaddr;
                   struct sockaddr ifr_netmask;
                   struct sockaddr ifr_hwaddr;
                   short           ifr_flags;
                   int             ifr_ifindex;
                   int             ifr_metric;
                   int             ifr_mtu;
                   struct ifmap    ifr_map;
                   char            ifr_slave[IFNAMSIZ];
                   char            ifr_newname[IFNAMSIZ];
                   char           *ifr_data;
               };
           };

       **AF_INET6 **is an exception.  It passes an _in6_ifreq_ structure:

           struct in6_ifreq {
               struct in6_addr     ifr6_addr;
               u32                 ifr6_prefixlen;
               int                 ifr6_ifindex; /* Interface index */
           };

       Normally, the user specifies which device to affect by setting _ifr_name_ to the  name  of  the
       interface  or _ifr6_ifindex_ to the index of the interface.  All other members of the structure
       may share memory.

### Ioctls
       If an ioctl is marked as privileged, then using it requires an effective user ID of 0 or  the
       **CAP_NET_ADMIN **capability.  If this is not the case, **EPERM **will be returned.

       **SIOCGIFNAME**
              Given the _ifr_ifindex_, return the name of the interface in _ifr_name_.  This is the only
              ioctl which returns its result in _ifr_name_.

       **SIOCGIFINDEX**
              Retrieve the interface index of the interface into _ifr_ifindex_.

       **SIOCGIFFLAGS**
       **SIOCSIFFLAGS**
              Get  or  set the active flag word of the device.  _ifr_flags_ contains a bit mask of the
              following values:
                                      Device flags
              IFF_UP            Interface is running.
              IFF_BROADCAST     Valid broadcast address set.
              IFF_DEBUG         Internal debugging flag.
              IFF_LOOPBACK      Interface is a loopback interface.
              IFF_POINTOPOINT   Interface is a point-to-point link.
              IFF_RUNNING       Resources allocated.
              IFF_NOARP         No arp protocol, L2 destination address not
                                set.
              IFF_PROMISC       Interface is in promiscuous mode.
              IFF_NOTRAILERS    Avoid use of trailers.
              IFF_ALLMULTI      Receive all multicast packets.
              IFF_MASTER        Master of a load balancing bundle.
              IFF_SLAVE         Slave of a load balancing bundle.
              IFF_MULTICAST     Supports multicast
              IFF_PORTSEL       Is able to select media type via ifmap.
              IFF_AUTOMEDIA     Auto media selection active.
              IFF_DYNAMIC       The addresses are lost when the interface
                                goes down.
              IFF_LOWER_UP      Driver signals L1 up (since Linux 2.6.17)
              IFF_DORMANT       Driver signals dormant (since Linux 2.6.17)
              IFF_ECHO          Echo sent packets (since Linux 2.6.25)

       Setting the active flag word is a privileged operation, but any process may read it.

       **SIOCGIFPFLAGS**
       **SIOCSIFPFLAGS**
              Get or set extended (private) flags for the device.  _ifr_flags_ contains a bit mask  of
              the following values:
                                      Private flags
              IFF_802_1Q_VLAN      Interface is 802.1Q VLAN device.
              IFF_EBRIDGE          Interface is Ethernet bridging device.
              IFF_SLAVE_INACTIVE   Interface is inactive bonding slave.
              IFF_MASTER_8023AD    Interface is 802.3ad bonding master.
              IFF_MASTER_ALB       Interface is balanced-alb bonding master.
              IFF_BONDING          Interface is a bonding master or slave.
              IFF_SLAVE_NEEDARP    Interface needs ARPs for validation.
              IFF_ISATAP           Interface is RFC4214 ISATAP interface.

       Setting the extended (private) interface flags is a privileged operation.

       **SIOCGIFADDR**
       **SIOCSIFADDR**
       **SIOCDIFADDR**
              Get,  set,  or  delete  the  address  of  the device using _ifr_addr_, or _ifr6_addr_ with
              _ifr6_prefixlen_.  Setting or deleting the interface address is a privileged  operation.
              For  compatibility,  **SIOCGIFADDR  **returns  only **AF_INET **addresses, **SIOCSIFADDR **accepts
              **AF_INET **and **AF_INET6 **addresses, and **SIOCDIFADDR **deletes only  **AF_INET6  **addresses.   A
              **AF_INET **address can be deleted by setting it to zero via **SIOCSIFADDR**.

       **SIOCGIFDSTADDR**
       **SIOCSIFDSTADDR**
              Get  or set the destination address of a point-to-point device using _ifr_dstaddr_.  For
              compatibility, only **AF_INET **addresses are accepted or returned.  Setting the  destina‐
              tion address is a privileged operation.

       **SIOCGIFBRDADDR**
       **SIOCSIFBRDADDR**
              Get  or  set the broadcast address for a device using _ifr_brdaddr_.  For compatibility,
              only **AF_INET **addresses are accepted or returned.  Setting the broadcast address  is  a
              privileged operation.

       **SIOCGIFNETMASK**
       **SIOCSIFNETMASK**
              Get  or  set the network mask for a device using _ifr_netmask_.  For compatibility, only
              **AF_INET **addresses are accepted or returned.  Setting the network mask is a  privileged
              operation.

       **SIOCGIFMETRIC**
       **SIOCSIFMETRIC**
              Get  or  set  the metric of the device using _ifr_metric_.  This is currently not imple‐
              mented; it sets _ifr_metric_ to 0 if you attempt to read it and  returns  **EOPNOTSUPP  **if
              you attempt to set it.

       **SIOCGIFMTU**
       **SIOCSIFMTU**
              Get or set the MTU (Maximum Transfer Unit) of a device using _ifr_mtu_.  Setting the MTU
              is  a  privileged  operation.   Setting  the  MTU to too small values may cause kernel
              crashes.

       **SIOCGIFHWADDR**
       **SIOCSIFHWADDR**
              Get or set the hardware address of a device using _ifr_hwaddr_.  The hardware address is
              specified in a struct _sockaddr_.  _sa_family_ contains the ARPHRD_* device type,  _sa_data_
              the L2 hardware address starting from byte 0.  Setting the hardware address is a priv‐
              ileged operation.

       **SIOCSIFHWBROADCAST**
              Set  the hardware broadcast address of a device from _ifr_hwaddr_.  This is a privileged
              operation.

       **SIOCGIFMAP**
       **SIOCSIFMAP**
              Get or set the interface's hardware parameters using _ifr_map_.  Setting the  parameters
              is a privileged operation.

                  struct ifmap {
                      unsigned long   mem_start;
                      unsigned long   mem_end;
                      unsigned short  base_addr;
                      unsigned char   irq;
                      unsigned char   dma;
                      unsigned char   port;
                  };

              The  interpretation of the ifmap structure depends on the device driver and the archi‐
              tecture.

       **SIOCADDMULTI**
       **SIOCDELMULTI**
              Add an address to or delete an address from the device's link layer multicast  filters
              using  _ifr_hwaddr_.  These are privileged operations.  See also [**packet**(7)](https://www.chedong.com/phpMan.php/man/packet/7/markdown) for an alter‐
              native.

       **SIOCGIFTXQLEN**
       **SIOCSIFTXQLEN**
              Get or set the transmit queue length of a device using _ifr_qlen_.  Setting the transmit
              queue length is a privileged operation.

       **SIOCSIFNAME**
              Changes the name of the interface specified in _ifr_name_ to  _ifr_newname_.   This  is  a
              privileged operation.  It is allowed only when the interface is not up.

       **SIOCGIFCONF**
              Return  a  list of interface (network layer) addresses.  This currently means only ad‐
              dresses of the **AF_INET **(IPv4) family for compatibility.  Unlike the others, this ioctl
              passes an _ifconf_ structure:

                  struct ifconf {
                      int               ifc_len; /* size of buffer */
                      union {
                          char         *ifc_buf; /* buffer address */
                          struct ifreq *ifc_req; /* array of structures */
                      };
                  };

              If _ifc_req_ is NULL, **SIOCGIFCONF **returns the necessary buffer size in bytes for receiv‐
              ing all available addresses in _ifc_len_.  Otherwise, _ifc_req_ contains a pointer  to  an
              array  of  _ifreq_  structures  to  be filled with all currently active L3 interface ad‐
              dresses.  _ifc_len_ contains the size of the array in bytes.  Within each  _ifreq_  struc‐
              ture,  _ifr_name_ will receive the interface name, and _ifr_addr_ the address.  The actual
              number of bytes transferred is returned in _ifc_len_.

              If the size specified by _ifc_len_ is insufficient to store all the addresses, the  ker‐
              nel  will skip the exceeding ones and return success.  There is no reliable way of de‐
              tecting this condition once it has occurred.  It is therefore  recommended  to  either
              determine the necessary buffer size beforehand by calling **SIOCGIFCONF **with _ifc_req_ set
              to  NULL,  or to retry the call with a bigger buffer whenever _ifc_len_ upon return dif‐
              fers by less than _sizeof(struct_ _ifreq)_ from its original value.

              If an error occurs accessing the _ifconf_ or _ifreq_ structures, **EFAULT **will be returned.

       Most protocols support their own ioctls to  configure  protocol-specific  interface  options.
       See the protocol man pages for a description.  For configuring IP addresses, see [**ip**(7)](https://www.chedong.com/phpMan.php/man/ip/7/markdown).

       In addition, some devices support private ioctls.  These are not described here.

## NOTES
       **SIOCGIFCONF  **and the other ioctls that accept or return only **AF_INET **socket addresses are IP-
       specific and perhaps should rather be documented in [**ip**(7)](https://www.chedong.com/phpMan.php/man/ip/7/markdown).

       The names of interfaces with no addresses or that don't have the **IFF_RUNNING **flag set can  be
       found via _/proc/net/dev_.

       **AF_INET6  **IPv6  addresses  can be read from _/proc/net/if_inet6_ or via [**rtnetlink**(7)](https://www.chedong.com/phpMan.php/man/rtnetlink/7/markdown).  Adding a
       new IPv6 address and deleting an existing IPv6 address can be done via **SIOCSIFADDR **and **SIOCD‐**
       **IFADDR **or via [**rtnetlink**(7)](https://www.chedong.com/phpMan.php/man/rtnetlink/7/markdown).  Retrieving or changing destination IPv6 addresses of a point-to-
       point interface is possible only via [**rtnetlink**(7)](https://www.chedong.com/phpMan.php/man/rtnetlink/7/markdown).

## BUGS
       glibc 2.1 is missing the _ifr_newname_ macro in _<net/if.h>_.  Add the following to your  program
       as a workaround:

           #ifndef ifr_newname
           #define ifr_newname     ifr_ifru.ifru_slave
           #endif

## SEE ALSO
       [**proc**(5)](https://www.chedong.com/phpMan.php/man/proc/5/markdown), [**capabilities**(7)](https://www.chedong.com/phpMan.php/man/capabilities/7/markdown), [**ip**(7)](https://www.chedong.com/phpMan.php/man/ip/7/markdown), [**rtnetlink**(7)](https://www.chedong.com/phpMan.php/man/rtnetlink/7/markdown)

Linux man-pages 6.7                          2023-10-31                                 [_netdevice_(7)](https://www.chedong.com/phpMan.php/man/netdevice/7/markdown)
