獲取 無線速率300M get bitrate

gogo_coco_yoyo發表於2014-08-24

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if.h>

#include <sys/types.h>
#include <stdlib.h>
#include <net/if_arp.h>

  int  main

{

  int ret;

  int socket_id;

  struct iwreq wrq;

  char temp[64]={0};

unsigned int linkspeed;


  socket_id = socket(AF_INET, SOCK_DGRAM, 0);

  strncpy(wrq.ifr_name, ifname, IFNAMSIZ);



  ret = ioctl(socket_id, SIOCGIWRATE, &wrq);
  if(ret < 0)
    printf("rate error.\n");
  else
        printf("rate success.\n");
  
linkspeed = wrq.u.bitrate.value / 1000000;
ret = snprintf(temp, sizeof(temp), "%d\n", linkspeed);

printf("%s\n", temp);


 }   

相關文章