IOCTL SIOCGIWSCAN错误E2BIG

时间:2017-02-13 13:04:43

标签: c linux wireless ioctl

我尝试使用IOCTL" SIOCGIWSCAN"从无线扩展中,以便从驱动程序中检索扫描结果:

问题是iwrq.u.data.length总是0 我一直都会收到错误E2BIG。

对此错误有什么想法,背后可能的原因是什么?

这是来自用于获取扫描结果的代码的片段"它类似于来自无线工具的iwlist命令" : 注意:iwlist完美运行" iwlist wlan0 scan"给出扫描结果?

...

while(true){

  fd_set   rfds;        
  int       last_fd;    
  int       retc;
  // re init
  FD_ZERO(&rfds);
  last_fd = -1;

  retc = select(last_fd + 1, &rfds, NULL, NULL, &time_out);
  int ret_errno = errno; 

  if(retc < 0) // errno check the type 
  {
     if(ret_errno == EAGAIN || ret_errno == EINTR) 
     {
        continue; // try another time          
     } 
        goto exit;
  }

  if(retc == 0)
  {

     iwrq.u.data.pointer = buffer; 
     iwrq.u.data.length = data_length;
     iwrq.u.data.flags = 0 ; 

       if(ioctl(sk_fd, SIOCGIWSCAN , &iwrq) < 0){
        errn = errno;

     if(errn == EAGAIN)
     {
       if(num_try > 0){ 
            num_try --; // decrease max try       
        }
        else
        {
            goto exit;
        }
        time_out.tv_sec = 0;
        time_out.tv_usec = 300000; // sleep for 300 ms
        continue;
     }



     else if(errn == E2BIG){

           // buffer too small to hold result 
           // extend it 
           if(iwrq.u.data.length > data_length) 
           {
               data_length *= 2;
               buffer =(char *) realloc(buffer,data_length * sizeof(char));
              if(!buffer){
              goto exit;
              }
           }
           // setup timer
        time_out.tv_sec = 0;
        time_out.tv_usec = 300000; // 100 ms
           continue; // try again
     } 
        //ioctl Wireless Scan Unhandled ERROR 
        goto exit;
     }else
  {
    break;  // we have result go and parse it
  }

  }

  /// parse scan result section
  ....

0 个答案:

没有答案