Libpcap编程(6)

上篇文章中针对libpcap进行了理论总结,以及部分函数和结构的介绍,这里就整个数据包抓包由浅到深进行分析。

获取网络接口名字和掩码信息

#include
   
   
    
    
#include
    
    
     
     
#include
     
     
      
      //in_addr头文件
int main(int argc,char **argv)
{
	char error[PCAP_ERRBUF_SIZE];//#define PCAP_ERRBUF_SIZE 256
	struct in_addr ip;
	struct in_addr mask;
	char *interface;
	bpf_u_int32 net_ip;
	bpf_u_int32 net_mask;
	interface=pcap_lookupdev(error);//获取网络设备指针
	if(interface==NULL)
	{
		printf("pcap_lookupdev error\n");
		return -1;
	}
	printf("Network interface:%s\n",interface);
	int ret=pcap_lookupnet(interface,&net_ip,&net_mask,error);//获取网络接口地址和掩码
	if(ret<0)
	{
		printf("pcap_lookupnet error\n");
		return -1;
	}
	ip.s_addr=net_ip;
	mask.s_addr=net_mask;
	printf("Interface ip:%s\n",inet_ntoa(ip));//地址输出
	printf("Interface mask:%s\n",in
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值