利用ioctl()獲取無線速率
睿豐德科技 專注RFID識別技術和條碼識別技術與管理軟件的集成項目。質量追溯系統、MES系統、金蝶與條碼系統對接、用友與條碼系統對接
其實對于自己裝了網卡驅動的來說,應該從最根本的驅動中獲取速率。
但是用ioctl()也可以,其實實現和iwconfig命令相同。
僅僅獲取速率這部分:
[cpp] view plain copy
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/socket.h>
- #include <string.h>
- #include "wireless_copy.h"
- #define dvname "ath0"
- int get_rate(int sock, struct iwreq* wrq,__s32 rate);
- int main()
- {
- struct iwreq wrq;
- int sock;
- char gInterfaceName[16];
- __s32 rate;
- memset(gInterfaceName, 0, sizeof(gInterfaceName));
- strcat(gInterfaceName,dvname);
- sock = socket(AF_INET, SOCK_DGRAM, 0);
- if (sock < 0)
- {
- printf("Error Creating Socket for ioctl/n");
- return 0;
- }
- memset(&wrq, 0, sizeof(wrq));
- strncpy(wrq.ifr_name, gInterfaceName, IFNAMSIZ);
- get_rate(sock, &wrq,rate);
- printf("/nrate:%dM/n/n",wrq.u.bitrate.value/1000000);
- return 0;
- }
- int get_rate(int sock, struct iwreq* wrq,__s32 rate)
- {
- if(ioctl(sock, SIOCGIWRATE, wrq) < 0)
- {
- perror("Ioctl error");
- return(0);
- }
- return 1;
- }
其中wireless_copy.h可以從madwifi /tools 文件夾中找到。
RFID管理系統集成商 RFID中間件 條碼系統中間層 物聯網軟件集成