c - ioctl IOCGIWSCAN : invalid arguments, -


hi i'm trying information iwlist command. got invalid arguments errno, , don't understand why, i'm fellowing paper deals : ioctl & iwreq . code fellowing :

#include <sys/ioctl.h> #include <sys/types.h> #include <sys/socket.h> #include <string.h> #include <errno.h> #include <stdlib.h> #include <stdio.h> #include <netpacket/packet.h> #include <netinet/if_ether.h> #include "ioctlcmd.h" #include <arpa/inet.h>  /*  siocgiwname     0x8b01  power     siocgiwtxpow    0x8b27       siocsiwfreq     0x8b04        set channel/frequency (hz)    */    int check_ifname_exist(char * ifname) {      int sock = socket(af_packet,sock_raw,0) ;      if (sock == ret_err) {       printf("error while checking ifname [errno : %d], [strerror : %s]\n",errno,strerror(errno));        return ret_err ;      }         struct ifreq ifr ;      strncpy(ifr.ifr_name,ifname,ifnamsiz) ;      int ret = ioctl(sock,siocgifindex,&ifr) ;      if (ret == ret_err) {       printf("error while checking ifname [errno : %d], [strerror : %s]\n",errno,strerror(errno));        return ret_err ;      }     return ret_succes ;  }  int get_channel_fq(char * essid, char * ifname) {    int sock = socket(af_packet,sock_raw,0) ;    if (sock == ret_err) {     fprintf(stderr,"error while opening socket [errno : %d] [strerror : %s]\n",errno,strerror(errno));      return ret_err ;       }    if (bind_socket(ifname,sock) == ret_err)     return ret_err ;    printf("coucou\n") ; //debug    struct iwreq iwr ;    memset(&iwr,0,sizeof(struct iwreq)) ;    memcpy(iwr.ifr_ifrn.ifrn_name,ifname,ifnamsiz) ;   printf("%s\n",iwr.ifr_ifrn.ifrn_name) ;      iwr.u.data.pointer = essid ;    iwr.u.data.length = strlen(essid)+1 ;    iwr.u.data.flags |= iw_scan_this_essid ;     if ((sock =ioctl(sock,siocsiwscan,&iwr)) == ret_err) {     fprintf(stderr,"error while getting freq of card. [errno : %d] [strerror : %s]\n",errno,strerror(errno)) ;      return ret_err ;    }   printf("coucou\n") ;  // debug   int bufsize = 4096 ;   struct iwreq iwr2 ={0} ;    //memset(&iwr2,0,sizeof(struct iwreq)) ;    char  *p = null ;    p=calloc(bufsize,1) ;    iwr2.u.data.pointer = p ;    iwr2.u.data.length = bufsize ;    iwr2.u.data.flags = 0 ;   memcpy(iwr2.ifr_ifrn.ifrn_name,ifname,ifnamsiz) ;   if (ioctl(sock,siocgiwscan,&iwr2) == ret_err) { // error           fprintf(stderr,"error while getting freq of card. [errno : %d] [strerror : %s]\n",errno,strerror(errno)) ; // error here          return ret_err ;   }     return ret_succes ;  }  int bind_socket(char * ifname,int sock_fd) {    struct ifreq ifr ;    struct sockaddr_ll sall ;    memset(&sall,0,sizeof(struct sockaddr_ll)) ;    strncpy(ifr.ifr_name,ifname,ifnamsiz) ;    ifr.ifr_addr.sa_family = af_inet ;     if (ioctl(sock_fd,siocgifindex,&ifr) == ret_err)      goto ret_err ;    if (ifr.ifr_ifindex < 0)       goto ret_err ;     sall.sll_ifindex = ifr.ifr_ifindex  ;    sall.sll_family = af_packet ;    sall.sll_protocol = htons(eth_p_all) ;     if (bind(sock_fd,(struct sockaddr *)&sall,sizeof(sall)) == ret_err)      goto ret_err ;    return sock_fd ;   ret_err :      fprintf(stderr,"error while binding socket. [errno = %d] [stderror = %s]\n",errno,strerror(errno)) ;     return ret_err ;  }  int main() {     get_channel_fq("ditwifi","wlan0") ;  } 

in code above, 2 printf("coucou") printed, i'm sure first ioctl() ioctl(sock,iocsiwscan,&iwr) works fine.

i think miss something, did't find.

thanks lot.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -