概述:
知识点梳理
关键字缩写
SIOC:socket i/o controls,套接字I/O控制
SIOCSIFFLAGS等ioctl()函数的请求
见glibc源码:
glibc\sysdeps\mach\hurd\bits\ioctls.h
/* socket i/o controls */
#define SIOCADDRT _IOW('r', 10, struct ortentry) /* add route */
#define SIOCDELRT _IOW('r', 11, struct ortentry) /* delete route */
#define SIOCSIFADDR _IOW('i', 12, struct ifreq) /* set ifnet address */
#define OSIOCGIFADDR _IOWR('i',13, struct ifreq) /* get ifnet address */
#define SIOCGIFADDR _IOWR('i',33, struct ifreq) /* get ifnet address */
#define SIOCGIFHWADDR _IOWR('i',39, struct ifreq) /* get hwaddress */
#define SIOCSIFFLAGS _IOW('i', 16, struct ifreq_short)/* set ifnet flags */
#define SIOCGIFFLAGS _IOWR('i',17, struct ifreq_short)/* get ifnet flags */
struct ifreq结构
见:glibc\sysdeps\gnu\net\if.h
/* Interface request structure used for socket ioctl's. All interface
ioctl's must have parameter definitions which begin with ifr_name.
The remainder may be interface specific. */
struct ifreq
{
# define IFHWADDRLEN 6
# define IFNAMSIZ IF_NAMESIZE
union
{
char ifrn_name[IFNAMSIZ]; /* Interface name, e.g. "en0". */
} ifr_ifrn;
union
{
struct sockaddr ifru_addr;
struct sockaddr ifru_dstaddr;
struct sockaddr ifru_broadaddr;
struct sockaddr ifru_netmask;
struct sockaddr ifru_hwaddr;
short int ifru_flags;
int ifru_ivalue;
int ifru_mtu;
struct ifmap ifru_map;
char ifru_slave[IFNAMSIZ]; /* Just fits the size */
char ifru_newname[IFNAMSIZ];
__caddr_t ifru_data;
} ifr_ifru;
};
short int ifru_flags;接口标志
见:glibc\sysdeps\gnu\net\if.h
/* Standard interface flags. */
enum
{
IFF_UP = 0x1, /* Interface is up. */
# define IFF_UP IFF_UP
IFF_BROADCAST = 0x2, /* Broadcast address valid. */
# define IFF_BROADCAST IFF_BROADCAST
IFF_DEBUG = 0x4, /* Turn on debugging. */
# define IFF_DEBUG IFF_DEBUG
IFF_LOOPBACK = 0x8, /* Is a loopback net. */
# define IFF_LOOPBACK IFF_LOOPBACK
IFF_POINTOPOINT = 0x10, /* Interface is point-to-point link. */
# define IFF_POINTOPOINT IFF_POINTOPOINT
IFF_NOTRAILERS = 0x20, /* Avoid use of trailers. */
# define IFF_NOTRAILERS IFF_NOTRAILERS
IFF_RUNNING = 0x40, /* Resources allocated. */
# define IFF_RUNNING IFF_RUNNING
IFF_NOARP = 0x80, /* No address resolution protocol. */
# define IFF_NOARP IFF_NOARP
IFF_PROMISC = 0x100, /* Receive all packets. */
# define IFF_PROMISC IFF_PROMISC
/* Not supported */
IFF_ALLMULTI = 0x200, /* Receive all multicast packets. */
# define IFF_ALLMULTI IFF_ALLMULTI
IFF_MASTER = 0x400, /* Master of a load balancer. */
# define IFF_MASTER IFF_MASTER
IFF_SLAVE = 0x800, /* Slave of a load balancer. */
# define IFF_SLAVE IFF_SLAVE
IFF_MULTICAST = 0x1000, /* Supports multicast. */
# define IFF_MULTICAST IFF_MULTICAST
IFF_PORTSEL = 0x2000, /* Can set media type. */
# define IFF_PORTSEL IFF_PORTSEL
IFF_AUTOMEDIA = 0x4000, /* Auto media select active. */
# define IFF_AUTOMEDIA IFF_AUTOMEDIA
IFF_DYNAMIC = 0x8000 /* Dialup device with changing addresses. */
# define IFF_DYNAMIC IFF_DYNAMIC
};