要知道无线网络的通过C ++在Ubuntu的ESSID [英] Want to know the ESSID of wireless network via C++ in UBUNTU

查看:233
本文介绍了要知道无线网络的通过C ++在Ubuntu的ESSID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了下面的程序去哪个我的桌面当前连接的无线网络的ESSID,但它给我的错误。谁能帮我纠正错误? code:

 的#include<&stdio.h中GT;
#包括LT&;&stdlib.h中GT;
#包括LT&;&string.h中GT;
#包括LT&; SYS / ioctl.h>
#包括LT&; SYS / stat.h>
#包括LT&; SYS / socket.h中>
#包括LT&; SYS / types.h中>
#包括LT&;&fcntl.h GT;
#包括LT&;&errno.h中GT;
#包括LT&; Linux的/ wireless.h>#定义IW_INTERFACE为wlan0EXTERN INT错误号;
结构iwreq WREQ;INT主要(无效)
{
    INT的sockfd;
    字符* ID;    memset的(安培; WREQ,0,sizeof的(结构iwreq));
    sprintf的(wreq.ifr_name,IW_INTERFACE);    如果((的sockfd =插座(AF_INET,SOCK_DGRAM,0))== -1){
        fprintf中(标准错误,无法打开插座\\ n);
        fprintf中(标准错误,错误号=%d个\\ N,错误号);
        fprintf中(标准错误,错误说明是:%S \\ n字符串错误(错误));
        出口(1);
    }
    的printf(套接字成功打开的\\ n);
    编号=新炭(IW_ESSID_MAX_SIZE + 1);
    wreq.u.essi​​d.pointer = ID;
    如果(的ioctl(的sockfd,SIOCGIWESSID,&安培; WREQ)== -1){
        fprintf中(标准错误,GET ESSID的ioctl失败\\ n);
        fprintf中(标准错误,错误号=%d个\\ N,错误号);
        fprintf中(标准错误,错误描述:%S \\ n字符串错误(错误));
        出口(2);
    }
    的printf(IOCTL全成\\ n);
    的printf(ESSID为%s \\ n,wreq.u.essi​​d.pointer);
    出口(0);
}

我收到以下错误:

 > 1.获取ESSID的ioctl失败
  > 2.错误号= 7
  > 3.错误描述:参数列表太长


解决方案

尝试设置 wreq.u.essi​​d.length 到正确的值。

I have written the following program to get the ESSID of the wireless network to which my Desktop is currently connected, but it is giving me errors. Can anyone help me correct the bugs? Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/types.h> 
#include <fcntl.h>
#include <errno.h>
#include <linux/wireless.h>

#define IW_INTERFACE "wlan0"

extern int errno;
struct iwreq wreq;

int main (void)
{
    int sockfd;
    char * id;

    memset(&wreq, 0, sizeof(struct iwreq));
    sprintf(wreq.ifr_name, IW_INTERFACE);

    if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
        fprintf(stderr, "Cannot open socket \n");
        fprintf(stderr, "errno = %d \n", errno);
        fprintf(stderr, "Error description is : %s\n",strerror(errno));
        exit(1);
    }
    printf("Socket opened successfully \n");


    id = new char(IW_ESSID_MAX_SIZE+1);
    wreq.u.essid.pointer = id;
    if (ioctl(sockfd,SIOCGIWESSID, &wreq) == -1) {
        fprintf(stderr, "Get ESSID ioctl failed \n");
        fprintf(stderr, "errno = %d \n", errno);
        fprintf(stderr, "Error description : %s\n",strerror(errno));
        exit(2);
    }
    printf("IOCTL Successfull\n");
    printf("ESSID is %s\n", wreq.u.essid.pointer);
    exit(0);
}

I am getting following error:

  > 1. Get ESSID ioctl failed 
  > 2. errno = 7 
  > 3. Error description : Argument list too long

解决方案

Try setting wreq.u.essid.length to the right value.

这篇关于要知道无线网络的通过C ++在Ubuntu的ESSID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆