ifconf, ifreq,sockaddr,caddr_t
//提示:结构体设计的非常规范,强烈推荐
/* 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 { #ifndef IFNAMSIZ #define IFNAMSIZ 16 #endif char ifr_name[IFNAMSIZ]; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; __ulong32_t ifru_flags; int ifru_metric; CADdr_t ifru_data; u_short ifru_site6; __ulong32_t ifru_mtu; int ifru_baudrate; } ifr_ifru;
//Following Macros are provided for convenIEnce #define ifr_addr ifr_ifru.ifru_addr /* address */ #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ #define ifr_flags ifr_ifru.ifru_flags /* flags */ #define ifr_metric ifr_ifru.ifru_metric /* metric */ #define ifr_data ifr_ifru.ifru_data /* for use by interface */ #define ifr_site6 ifr_ifru.ifru_site6 /* IPv6 site index */ #define ifr_mtu ifr_ifru.ifru_mtu /* mtu of interface */ #define ifr_isno ifr_ifru.ifru_data /* pointer to if_netopts */ #define ifr_baudrate ifr_ifru.ifru_baudrate /* baudrate of interface */ };
/* Structure used in SIOCGIFCONF request. Used to retrieve interface configuration for machine (useful for programs which must know all networks accessible). */
struct ifconf { int ifc_len; /* size of associated buffer */
union { caddr_t ifcu_buf; struct ifreq *ifcu_req; } ifc_ifcu;
Following macros are provided for convenience #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ };
SIOCGIFADDR:获取接口地址,检索特定接口的地址 SIOCSIFADDR:设置接口地址。ifr.ifr_addr 字段返回地址。 SIOCGIFCONF:获取所有配置接口的信息,返回系统中配置的所有接口的配置信息 以上介绍转自:http://hi.baidu.com/leezongfanblog/blog/item/a86a564583934a88b3b7dc0e.html
struct sockaddr { unsigned short sa_family; /* 地址族, AF_xxx */ char sa_data[14]; /* 14字节的协议地址*/ };
typedef void *caddr_t; |