努力学习啊哈 2014-02-24 03:12 采纳率: 0%
浏览 1928

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()函数返回赋值时类型不匹配,运行程序时段错误 请教各位大神哪里出错

  • 写回答

1条回答

  • oyljerry 2014-12-28 07:29
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法