开发者社区> 问答> 正文

linux网络编程libpcap获取网络接口信息失败

#include 
typedef u_int32_t in_addr_t;

struct in_addr
 {
 in_addr_t s_addr;
 };

void main()
 {
 char error_content[PCAP_ERRBUF_SIZE];
 struct in_addr net_ip_address;
 struct in_addr net_mask_address;
 char *net_interface;
 char *net_ip_string;
 char *net_mask_string;
u_int32_t net_ip;
u_int32_t net_mask;
net_interface = pcap_lookupdev(error_content);
pcap_lookupnet(net_interface,&net_ip,&net_mask,error_content);   
printf("Network Interface is : %s\n",net_interface);
net_ip_address.s_addr = net_ip;
net_ip_string = inet_ntoa(net_ip_address);
printf("Network IP Address is :%s\n",net_ip_string);
net_mask_address.s_addr = net_mask;
net_mask_string = inet_ntoa(net_mask_address);
printf("Network Mask Address is :%s\n",net_mask_string);

}

利用libpcap 编程获取网络接口信息的时候 无法 获得 IP地址和子网掩码,只能打印端口名,编译时报错 inet_ntoa()函数返回赋值时类型不匹配,运行程序时段错误 请教各位大神哪里出错

展开
收起
杨冬芳 2016-07-08 14:22:41 2216 0
1 条回答
写回答
取消 提交回答
  • IT从业

    类型不匹配 --- 进行类型转换

    2019-07-17 19:53:21
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
可预期数据中心网络 立即下载
可编程网络视角的网络创新研究 立即下载
阿里云栖开发者沙龙PHP技术专场-深入浅出网络编程与swoole内核-吴镇宇 立即下载