NETDEVICESection: Linux Programmer's Manual (7)Updated: 1999-05-02 |
NETDEVICESection: Linux Programmer's Manual (7)Updated: 1999-05-02 |
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. They pass an ifreq structure:
struct ifreq {
char ifr_name[IFNAMSIZ];/* Interface name */
union {
struct sockaddrifr_addr;
struct sockaddrifr_dstaddr;
struct sockaddrifr_broadaddr;
struct sockaddrifr_netmask;
struct sockaddrifr_hwaddr;
short ifr_flags;
int ifr_ifindex;
int ifr_metric;
int ifr_mtu;
struct ifmapifr_map;
char ifr_slave[IFNAMSIZ];
char ifr_newname[IFNAMSIZ];
char * ifr_data;
};
};
struct ifconf {
int ifc_len; /* size of buffer */
union {
char * ifc_buf; /* buffer address */
struct ifreq *ifc_req; /* array of structures */
};
};
Normally, the user specifies which device to affect by setting ifr_name to the name of the interface. All other members of the structure may share memory.
| 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.
|
Setting the active flag word is a privileged operation, but any process may read it.
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 architecture.
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).
In addition some devices support private ioctls. These are not described here.
The names of interfaces with no addresses or that don't have the IFF_RUNNING flag set can be found via /proc/net/dev.
Local IPv6 IP addresses can be found via /proc/net or via rtnetlink(7).
#ifndef ifr_newname #define ifr_newname ifr_ifru.ifru_slave #endif