首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

查看arp缓存出错,该怎么处理

2012-03-06 
查看arp缓存出错C/C++ code#include sys/types.h#include sys/socket.h#include netinet/in.h#inclu

查看arp缓存出错

C/C++ code
#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <sys/ioctl.h>#include <net/if_arp.h>#include <string.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>char *ip = "192.168.205.168";int main(){    struct arpreq arp;    /**/    struct sockaddr_in * paddr = (struct sockaddr_in *)&arp.arp_pa;;    int s, ret = 0;    char *mac = arp.arp_pa.sa_data;        s = socket(AF_INET, SOCK_STREAM, 0);        paddr->sin_family = AF_INET;    paddr->sin_port = htons(9090);    paddr->sin_addr.s_addr = inet_addr(ip);        strcpy(arp.arp_dev, "eth0");        ret = ioctl(s, SIOCGARP, &arp);    if(ret == -1)         {             perror("ioctl SIOCGARP");             exit(1);          }        printf("%2x-%2x-%2x-%2x-%2x-%2x\n",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);        return 0;}

编译没问题,运行出现ioctl SIOCGARP: Invalid argument错误,请问这是什么原因,该怎么改?

[解决办法]
开发不会
不过看错误应该是参数错误 是不是缺头文件?
[解决办法]
socket有没有成功返回?

热点排行