Structural prototypes:
struct IFREQ
{
#define Ifhwaddrlen 6
Union
{
Char Ifrn_name[ifnamsiz];
} IFR_IFRN;
Union {
struct SOCKADDR ifru_addr;
struct SOCKADDR ifru_dstaddr;
struct SOCKADDR ifru_broadaddr;
struct SOCKADDR ifru_netmask;
struct SOCKADDR ifru_hwaddr;
Short ifru_flags;
int ifru_ivalue;
int IFRU_MTU;
struct Ifmap ifru_map;
Char Ifru_slave[ifnamsiz];
Char Ifru_newname[ifnamsiz];
void __user * IFRU_DATA;
struct If_settings ifru_settings;
} Ifr_ifru;
};
#define IFR_NAME Ifr_ifrn.ifrn_name
#define IFR_HWADDR IFR_IFRU.IFRU_HWADDR
#define IFR_ADDR IFR_IFRU.IFRU_ADDR
#define IFR_DSTADDR IFR_IFRU.IFRU_DSTADDR
#define IFR_BROADADDR IFR_IFRU.IFRU_BROADADDR
#define Ifr_netmask Ifr_ifru.ifru_netmask
#define IFR_FLAGS Ifr_ifru.ifru_flags
#define Ifr_metric Ifr_ifru.ifru_ivalue
#define IFR_MTU IFR_IFRU.IFRU_MTU
#define IFR_MAP Ifr_ifru.ifru_map
#define Ifr_slave Ifr_ifru.ifru_slave
#define Ifr_data Ifr_ifru.ifru_data
#define IFR_IFINDEX Ifr_ifru.ifru_ivalue
#define Ifr_bandwidth Ifr_ifru.ifru_ivalue
#define Ifr_qlen Ifr_ifru.ifru_ivalue
#define IFR_NEWNAME Ifr_ifru.ifru_newname
#define Ifr_settings Ifr_ifru.ifru_settings
Basic Introduction:
The IFREQ structure is defined in the/usr/include/net/if.h, which is used to configure the IP address, activate the interface, configure the MTU and other interface information. It contains the name and specific content of an interface-(it is a common body, possibly an IP address, broadcast address, subnet mask, mac number, MTU, or other content). The ifreq is included in the ifconf structure. The ifconf structure is usually used to hold information about all interfaces.
To illustrate:
In a Linux system, the Ifconfig command communicates with the kernel via the IOCTL interface, for example, when the system administrator enters the following command to change the MTU size of the interface eth0:
Ifconfig eth0 MTU 1250
The Ifconfig command first opens a socket and then initializes a data structure with the parameters entered by the system administrator and transmits the data to the kernel via an IOCTL call. SIOCSIFMTU is the command identifier.
struct IFREQ data;
FD = socket (pf_inet, SOCK_DGRAM, 0);
< initialize "Data" ...>
Err = IOCTL (FD, SIOCSIFMTU, &data);
Source: http://blog.csdn.net/zhu114wei/article/details/6927513
Analysis and use of ifreq structure in Linux