{"id":4020,"date":"2022-12-20T17:28:43","date_gmt":"2022-12-20T20:28:43","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/netdevice-man7\/"},"modified":"2022-12-20T17:28:43","modified_gmt":"2022-12-20T20:28:43","slug":"netdevice-man7","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/netdevice-man7\/","title":{"rendered":"NETDEVICE (man7)"},"content":{"rendered":"<h1 align=\"center\">NETDEVICE<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#NOTES\">NOTES<\/a><br \/> <a href=\"#BUGS\">BUGS<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COLOPHON\">COLOPHON<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">netdevice \u2212 low-level access to Linux network devices<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>#include <sys\/ioctl.h> <br \/> #include <net\/if.h><\/b><\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This man page describes the sockets interface which is used to configure network devices.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Linux supports some standard ioctls to configure network devices. They can be used on any socket\u2019s file descriptor regardless of the family or type. Most of them pass an <i>ifreq<\/i> structure:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">struct ifreq { <br \/> char ifr_name[IFNAMSIZ]; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var Interface name bodies\/ usr\/ <br \/> union { <br \/> struct sockaddr ifr_addr; <br \/> struct sockaddr ifr_dstaddr; <br \/> struct sockaddr ifr_broadaddr; <br \/> struct sockaddr ifr_netmask; <br \/> struct sockaddr ifr_hwaddr; <br \/> short ifr_flags; <br \/> int ifr_ifindex; <br \/> int ifr_metric; <br \/> int ifr_mtu; <br \/> struct ifmap ifr_map; <br \/> char ifr_slave[IFNAMSIZ]; <br \/> char ifr_newname[IFNAMSIZ]; <br \/> char *ifr_data; <br \/> }; <br \/> };<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Normally, the user specifies which device to affect by setting <i>ifr_name<\/i> to the name of the interface. All other members of the structure may share memory.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Ioctls<\/b> <br \/> If an ioctl is marked as privileged, then using it requires an effective user ID of 0 or the <b>CAP_NET_ADMIN<\/b> capability. If this is not the case, <b>EPERM<\/b> will be returned. <b><br \/> SIOCGIFNAME<\/b><\/p>\n<p style=\"margin-left:22%;\">Given the <i>ifr_ifindex<\/i>, return the name of the interface in <i>ifr_name<\/i>. This is the only ioctl which returns its result in <i>ifr_name<\/i>.<\/p>\n<p style=\"margin-left:11%;\"><b>SIOCGIFINDEX<\/b><\/p>\n<p style=\"margin-left:22%;\">Retrieve the interface index of the interface into <i>ifr_ifindex<\/i>.<\/p>\n<p style=\"margin-left:11%;\"><b>SIOCGIFFLAGS<\/b>, <b>SIOCSIFFLAGS<\/b><\/p>\n<p style=\"margin-left:22%;\">Get or set the active flag word of the device. <i>ifr_flags<\/i> contains a bit mask of the following values:<\/p>\n<p align=\"center\" style=\"margin-top: 1em\"><img decoding=\"async\" src=\"grohtml-942911.png\" alt=\"Image grohtml-942911.png\"><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Setting the active flag word is a privileged operation, but any process may read it. <b><br \/> SIOCGIFPFLAGS<\/b>, <b>SIOCSIFPFLAGS<\/b><\/p>\n<p style=\"margin-left:22%;\">Get or set extended (private) flags for the device. <i>ifr_flags<\/i> contains a bit mask of the following values:<\/p>\n<p align=\"center\" style=\"margin-top: 1em\"><img decoding=\"async\" src=\"grohtml-942912.png\" alt=\"Image grohtml-942912.png\"><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Setting the extended (private) interface flags is a privileged operation. <b><br \/> SIOCGIFADDR<\/b>, <b>SIOCSIFADDR<\/b><\/p>\n<p style=\"margin-left:22%;\">Get or set the address of the device using <i>ifr_addr<\/i>. Setting the interface address is a privileged operation. For compatibility, only <b>AF_INET<\/b> addresses are accepted or returned.<\/p>\n<p style=\"margin-left:11%;\"><b>SIOCGIFDSTADDR<\/b>, <b>SIOCSIFDSTADDR<\/b><\/p>\n<p style=\"margin-left:22%;\">Get or set the destination address of a point-to-point device using <i>ifr_dstaddr<\/i>. For compatibility, only <b>AF_INET<\/b> addresses are accepted or returned. Setting the destination address is a privileged operation.<\/p>\n<p style=\"margin-left:11%;\"><b>SIOCGIFBRDADDR<\/b>, <b>SIOCSIFBRDADDR<\/b><\/p>\n<p style=\"margin-left:22%;\">Get or set the broadcast address for a device using <i>ifr_brdaddr<\/i>. For compatibility, only <b>AF_INET<\/b> addresses are accepted or returned. Setting the broadcast address is a privileged operation.<\/p>\n<p style=\"margin-left:11%;\"><b>SIOCGIFNETMASK<\/b>, <b>SIOCSIFNETMASK<\/b><\/p>\n<p style=\"margin-left:22%;\">Get or set the network mask for a device using <i>ifr_netmask<\/i>. For compatibility, only <b>AF_INET<\/b> addresses are accepted or returned. Setting the network mask is a privileged operation.<\/p>\n<p style=\"margin-left:11%;\"><b>SIOCGIFMETRIC<\/b>, <b>SIOCSIFMETRIC<\/b><\/p>\n<p style=\"margin-left:22%;\">Get or set the metric of the device using <i>ifr_metric<\/i>. This is currently not implemented; it sets <i>ifr_metric<\/i> to 0 if you attempt to read it and returns <b>EOPNOTSUPP<\/b> if you attempt to set it.<\/p>\n<p style=\"margin-left:11%;\"><b>SIOCGIFMTU<\/b>, <b>SIOCSIFMTU<\/b><\/p>\n<p style=\"margin-left:22%;\">Get or set the MTU (Maximum Transfer Unit) of a device using <i>ifr_mtu<\/i>. Setting the MTU is a privileged operation. Setting the MTU to too small values may cause kernel crashes.<\/p>\n<p style=\"margin-left:11%;\"><b>SIOCGIFHWADDR<\/b>, <b>SIOCSIFHWADDR<\/b><\/p>\n<p style=\"margin-left:22%;\">Get or set the hardware address of a device using <i>ifr_hwaddr<\/i>. The hardware address is specified in a struct <i>sockaddr<\/i>. <i>sa_family<\/i> contains the ARPHRD_* device type, <i>sa_data<\/i> the L2 hardware address starting from byte 0. Setting the hardware address is a privileged operation.<\/p>\n<p style=\"margin-left:11%;\"><b>SIOCSIFHWBROADCAST<\/b><\/p>\n<p style=\"margin-left:22%;\">Set the hardware broadcast address of a device from <i>ifr_hwaddr<\/i>. This is a privileged operation.<\/p>\n<p style=\"margin-left:11%;\"><b>SIOCGIFMAP<\/b>, <b>SIOCSIFMAP<\/b><\/p>\n<p style=\"margin-left:22%;\">Get or set the interface\u2019s hardware parameters using <i>ifr_map<\/i>. Setting the parameters is a privileged operation.<\/p>\n<p style=\"margin-left:28%; margin-top: 1em\">struct ifmap { <br \/> unsigned long mem_start; <br \/> unsigned long mem_end; <br \/> unsigned short base_addr; <br \/> unsigned char irq; <br \/> unsigned char dma; <br \/> unsigned char port; <br \/> };<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">The interpretation of the ifmap structure depends on the device driver and the architecture.<\/p>\n<p style=\"margin-left:11%;\"><b>SIOCADDMULTI<\/b>, <b>SIOCDELMULTI<\/b><\/p>\n<p style=\"margin-left:22%;\">Add an address to or delete an address from the device\u2019s link layer multicast filters using <i>ifr_hwaddr<\/i>. These are privileged operations. See also <b>packet<\/b>(7) for an alternative.<\/p>\n<p style=\"margin-left:11%;\"><b>SIOCGIFTXQLEN<\/b>, <b>SIOCSIFTXQLEN<\/b><\/p>\n<p style=\"margin-left:22%;\">Get or set the transmit queue length of a device using <i>ifr_qlen<\/i>. Setting the transmit queue length is a privileged operation.<\/p>\n<p style=\"margin-left:11%;\"><b>SIOCSIFNAME<\/b><\/p>\n<p style=\"margin-left:22%;\">Changes the name of the interface specified in <i>ifr_name<\/i> to <i>ifr_newname<\/i>. This is a privileged operation. It is allowed only when the interface is not up.<\/p>\n<p style=\"margin-left:11%;\"><b>SIOCGIFCONF<\/b><\/p>\n<p style=\"margin-left:22%;\">Return a list of interface (network layer) addresses. This currently means only addresses of the <b>AF_INET<\/b> (IPv4) family for compatibility. Unlike the others, this ioctl passes an <i>ifconf<\/i> structure:<\/p>\n<p style=\"margin-left:28%; margin-top: 1em\">struct ifconf { <br \/> int ifc_len; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var size of buffer bodies\/ usr\/ <br \/> union { <br \/> char *ifc_buf; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var buffer address bodies\/ usr\/ <br \/> struct ifreq *ifc_req; \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var array of structures bodies\/ usr\/ <br \/> }; <br \/> };<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">If <i>ifc_req<\/i> is NULL, <b>SIOCGIFCONF<\/b> returns the necessary buffer size in bytes for receiving all available addresses in <i>ifc_len<\/i>. Otherwise, <i>ifc_req<\/i> contains a pointer to an array of <i>ifreq<\/i> structures to be filled with all currently active L3 interface addresses. <i>ifc_len<\/i> contains the size of the array in bytes. Within each <i>ifreq<\/i> structure, <i>ifr_name<\/i> will receive the interface name, and <i>ifr_addr<\/i> the address. The actual number of bytes transferred is returned in <i>ifc_len<\/i>.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">If the size specified by <i>ifc_len<\/i> is insufficient to store all the addresses, the kernel will skip the exceeding ones and return success. There is no reliable way of detecting this condition once it has occurred. It is therefore recommended to either determine the necessary buffer size beforehand by calling <b>SIOCGIFCONF<\/b> with <i>ifc_req<\/i> set to NULL, or to retry the call with a bigger buffer whenever <i>ifc_len<\/i> upon return differs by less than <i>sizeof(struct ifreq)<\/i> from its original value.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">If an error occurs accessing the <i>ifconf<\/i> or <i>ifreq<\/i> structures, <b>EFAULT<\/b> will be returned.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">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 <b>ip<\/b>(7).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">In addition, some devices support private ioctls. These are not described here.<\/p>\n<h2>NOTES <a name=\"NOTES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>SIOCGIFCONF<\/b> and the other ioctls that accept or return only <b>AF_INET<\/b> socket addresses are IP-specific and perhaps should rather be documented in <b>ip<\/b>(7).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The names of interfaces with no addresses or that don\u2019t have the <b>IFF_RUNNING<\/b> flag set can be found via <i>\/proc\/net\/dev<\/i>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Local IPv6 IP addresses can be found via <i>\/proc\/net<\/i> or via <b>rtnetlink<\/b>(7).<\/p>\n<h2>BUGS <a name=\"BUGS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">glibc 2.1 is missing the <i>ifr_newname<\/i> macro in <i><net\/if.h><\/i>. Add the following to your program as a workaround:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">#ifndef ifr_newname <br \/> #define ifr_newname ifr_ifru.ifru_slave <br \/> #endif<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>proc<\/b>(5), <b>capabilities<\/b>(7), <b>ip<\/b>(7), <b>rtnetlink<\/b>(7)<\/p>\n<h2>COLOPHON <a name=\"COLOPHON\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This page is part of release 5.10 of the Linux <i>man-pages<\/i> project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https:\/\/www.kernel.org\/doc\/man\u2212pages\/.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  netdevice \u2212 low-level access to Linux network devices <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[971],"tags":[973,972,1105],"class_list":["post-4020","post","type-post","status-publish","format-standard","hentry","category-7-miscelanea","tag-973","tag-man7","tag-netdevice"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4020","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=4020"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4020\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=4020"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=4020"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=4020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}