日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

1. iwconfig代码框架

發布時間:2023/12/15 综合教程 33 生活家
生活随笔 收集整理的這篇文章主要介紹了 1. iwconfig代码框架 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、基本概念

iwconfig 作用域WLAN層,和ifconfig類似, 但僅作用于80211設備。
射頻層不支持iwconfig。

二、主要接口

iw_sockets_open      //函數根據不同的協議創建對應的socket,以便和無線設備驅動進行交互。
iw_enum_devices      //當輸入的一個參入時,則羅列出全部接口,如果是網絡接口,則輸出網絡接口狀態信息。
print_info		//獲取參數信息傳入后,打印出與參數對應的需求信息。
set_info		//設置參數輸入后,進行ioctl操作,向無線設備驅動傳參,并生效。

三、數據結構體

/*
 * The structure to exchange data for ioctl.
 * This structure is the same as 'struct ifreq', but (re)defined for
 * convenience...
 * Do I need to remind you about structure size (32 octets) ?
 */
struct    iwreq 
{
    union
    {
        char    ifrn_name[IFNAMSIZ];    /* if name, e.g. "eth0" 接口名稱*/
    } ifr_ifrn;

    /* Data part (defined just above) */
    union    iwreq_data    u; //存放數據的地方
};
/* ------------------------ IOCTL REQUEST ------------------------ */
/*
 * This structure defines the payload of an ioctl, and is used 
 * below.
 *
 * Note that this structure should fit on the memory footprint
 * of iwreq (which is the same as ifreq), which mean a max size of
 * 16 octets = 128 bits. Warning, pointers might be 64 bits wide...
 * You should check this when increasing the structures defined
 * above in this file...
 */
union    iwreq_data
{
    /* Config - generic */
    char        name[IFNAMSIZ];
    /* Name : used to verify the presence of  wireless extensions.
     * Name of the protocol/provider... */

    struct iw_point    essid;        /* Extended network name */
    struct iw_param    nwid;        /* network id (or domain - the cell) */
    struct iw_freq    freq;        /* frequency or channel :
                     * 0-1000 = channel
                     * > 1000 = frequency in Hz */

    struct iw_param    sens;        /* signal level threshold */
    struct iw_param    bitrate;    /* default bit rate */
    struct iw_param    txpower;    /* default transmit power */
    struct iw_param    rts;        /* RTS threshold threshold */
    struct iw_param    frag;        /* Fragmentation threshold */
    __u32        mode;        /* Operation mode */
    struct iw_param    retry;        /* Retry limits & lifetime */

    struct iw_point    encoding;    /* Encoding stuff : tokens */
    struct iw_param    power;        /* PM duration/timeout */
    struct iw_quality qual;        /* Quality part of statistics */

    struct sockaddr    ap_addr;    /* Access point address */
    struct sockaddr    addr;        /* Destination address (hw/mac) */

    struct iw_param    param;        /* Other small parameters */
    struct iw_point    data;        /* Other large parameters */
};

四、接口解析

1. iw_enum_device

 1 /*------------------------------------------------------------------*/
 2 /*
 3  * Enumerate devices and call specified routine
 4  * The new way just use /proc/net/wireless, so get all wireless interfaces,
 5  * whether configured or not. This is the default if available.
 6  * The old way use SIOCGIFCONF, so get only configured interfaces (wireless
 7  * or not).
 8  */
 9 void
10 iw_enum_devices(int        skfd,
11         iw_enum_handler    fn,
12         char *        args[],
13         int        count)
14 {
15   char        buff[1024];
16   FILE *    fh;
17   struct ifconf ifc;
18   struct ifreq *ifr;
19   int        i;
20 
21 #ifndef IW_RESTRIC_ENUM
22   /* Check if /proc/net/dev is available */
23   fh = fopen(PROC_NET_DEV, "r");
24 #else
25   /* Check if /proc/net/wireless is available */
26   fh = fopen(PROC_NET_WIRELESS, "r");
27 #endif
28 
29   if(fh != NULL)
30     {
31       /* Success : use data from /proc/net/wireless */
32 
33       /* Eat 2 lines of header 跳過2行開頭 */
34       fgets(buff, sizeof(buff), fh);
35       fgets(buff, sizeof(buff), fh);
36 
37       /* Read each device line */
38       while(fgets(buff, sizeof(buff), fh))
39     {
40       char    name[IFNAMSIZ + 1];
41       char *s;
42 
43       /* Skip empty or almost empty lines. It seems that in some
44        * cases fgets return a line with only a newline. 跳過空行 */
45       if((buff[0] == '') || (buff[1] == ''))
46         continue;
47 
48       /* Extract interface name 獲取接口名稱 easy skip */
49       s = iw_get_ifname(name, sizeof(name), buff);
50 
51       if(!s)
52         {
53           /* Failed to parse, complain and continue */
54 #ifndef IW_RESTRIC_ENUM
55           fprintf(stderr, "Cannot parse " PROC_NET_DEV "
");
56 #else
57           fprintf(stderr, "Cannot parse " PROC_NET_WIRELESS "
");
58 #endif
59         }
60       else
61         /* Got it, print info about this interface */
62         (*fn)(skfd, name, args, count);
63     }
64 
65       fclose(fh);
66     }
67   else
68     {
69       /* Get list of configured devices using "traditional" way */
70       ifc.ifc_len = sizeof(buff);
71       ifc.ifc_buf = buff;
72       if(ioctl(skfd, SIOCGIFCONF, &ifc) < 0)
73     {
74       fprintf(stderr, "SIOCGIFCONF: %s
", strerror(errno));
75       return;
76     }
77       ifr = ifc.ifc_req;
78 
79       /* Print them */
80       for(i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; ifr++)c
81     (*fn)(skfd, ifr->ifr_name, args, count);
82     }
83 }

iw_enum_device

從代碼和圖片可以看到,iwconfig列出來的所有接口是從/proc/dev/net 這個文件中讀出來的。

總結

以上是生活随笔為你收集整理的1. iwconfig代码框架的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。