recv()函数没有收到

时间:2012-08-22 00:05:44

标签: c linux sockets recv

SA,

我正在尝试创建套接字并从接入点接收数据和日志,当我从shell运行代码时代码正常工作。但是,当我尝试使用运行命令的execvp从代码连接到AP时

sudo iwconfig wlan0 essid "access point name"

recv函数不再从代码或shell中运行,似乎某些设置在我运行此命令时已经改变但我不确定究竟发生了什么变化

这就是我创建套接字的方式

memset(&proc_addr, 0, sizeof(struct sockaddr_nl));
proc_addr.nl_family = AF_NETLINK;
proc_addr.nl_pid = getpid();            
proc_addr.nl_groups = CN_IDX_IWLAGN;

if (bind(sock_fd, (struct sockaddr *)&proc_addr, sizeof(struct sockaddr_nl)) == -1)
    exit_program_err(-1, "bind");

{
    int on = proc_addr.nl_groups;
    ret = setsockopt(sock_fd, 270, NETLINK_ADD_MEMBERSHIP, &on, sizeof(on));
    if (ret)
        exit_program_err(-1, "setsockopt");
}

while (1)
{
    /* Receive from socket with infinite timeout */
    printf("trying to receive");
    ret = recv(sock_fd, buf, sizeof(buf), 0);
    printf("received");
}

所以尽管我可以ping AP中的数据

,但只打印接收然后没有打印

execvp代码:

string cmd1_connect = "sudo iwconfig wlan0 essid ciscosb_3"; 
string cmd_check = "sudo dhclient wlan0";
 string cmd2_connect = "sudo iwconfig wlan0 essid Cisco13-guest"; 
while(true) { 
if(stream1) { 
shell->runcmd(&m, &cmd1_connect); 
shell->runcmd(&m, &cmd_check); 
} else { 
shell->runcmd(&m, &cmd2_connect); 
shell->runcmd(&m, &cmd_check); }

0 个答案:

没有答案