zoukankan      html  css  js  c++  java
  • 利用ioctl()获取无线速率

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

    但是用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 文件夹中找到。

  • 相关阅读:
    【题解】P3796【模板】AC自动机(加强版)
    【模板】P3806点分治1
    【题解】P2602[JZOI2010]数字计数
    【题解】P2444 病毒
    【题解】[P3557 POI2013]GRA-Tower Defense Game
    【题解】DZY Loves Chinese
    【题解】[Ghd]
    【题解】CF264B Good Sequences
    【题解】P3162CQOI2012组装
    【题解】P2279消防局的设立
  • 原文地址:https://www.cnblogs.com/lidabo/p/5344816.html
Copyright © 2011-2022 走看看