其实对于自己装了网卡驱动的来说,应该从最根本的驱动中获取速率。

但是用ioctl()也可以,其实实现和iwconfig命令相同。

 

仅仅获取速率这部分:

 

 

[cpp] view plain copy
 
  1. #include <stdio.h>  
  2. #include <stdlib.h>  
  3. #include <sys/socket.h>  
  4. #include <string.h>  
  5. #include "wireless_copy.h"  
  6. #define dvname "ath0"  
  7. int get_rate(int sock, struct iwreq* wrq,__s32 rate);  
  8. int main()  
  9. {  
  10.     struct iwreq wrq;  
  11.     int sock;  
  12.     char gInterfaceName[16];  
  13.     __s32 rate;  
  14.     memset(gInterfaceName, 0, sizeof(gInterfaceName));  
  15.     strcat(gInterfaceName,dvname);  
  16.     sock = socket(AF_INET, SOCK_DGRAM, 0);  
  17.         if (sock < 0)  
  18.         {  
  19.             printf("Error Creating Socket for ioctl/n");  
  20.             return 0;  
  21.         }  
  22.     memset(&wrq, 0, sizeof(wrq));  
  23.     strncpy(wrq.ifr_name, gInterfaceName, IFNAMSIZ);  
  24.     get_rate(sock, &wrq,rate);  
  25.     printf("/nrate:%dM/n/n",wrq.u.bitrate.value/1000000);  
  26.     return 0;  
  27. }  
  28. int get_rate(int sock, struct iwreq* wrq,__s32 rate)  
  29. {  
  30.     if(ioctl(sock, SIOCGIWRATE, wrq) < 0)  
  31.     {  
  32.         perror("Ioctl error");  
  33.         return(0);  
  34.     }  
  35.     return 1;  
  36. }  

 

 

其中wireless_copy.h可以从madwifi /tools 文件夹中找到。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-15
  • 2021-09-10
  • 2021-10-10
  • 2021-07-07
猜你喜欢
  • 2022-02-12
  • 2021-05-03
  • 2022-12-23
  • 2022-12-23
  • 2021-08-28
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案