⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p14.1.c

📁 linux程序设计例程
💻 C
字号:
#include <stdio.h>#include <pcap.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>int main(void){	char *net_dev;	char *ip_addr;	char *net_mask;	char errbuf[PCAP_ERRBUF_SIZE];	bpf_u_int32 netp;	bpf_u_int32 maskp;	struct in_addr addr;	net_dev=pcap_lookupdev(errbuf);	if(net_dev==NULL){		printf("cannot get the network device info: %s\n",errbuf);		return 1;	}	        printf("the network device is: %s\n",net_dev);	if(pcap_lookupnet(net_dev,&netp,&maskp,errbuf)==-1){		printf("cannot get the network device ip info:%s\n",errbuf);		return 1;	}	addr.s_addr=netp;	ip_addr=inet_ntoa(addr);	if(ip_addr==NULL){		printf("convert network address fail\n");		return 1;	}        printf("ip address is : %s\n",ip_addr);	addr.s_addr=maskp;	net_mask=inet_ntoa(addr);	if(net_mask==NULL){		printf("convert network mask fail\n");		return 1;	}	printf("network mask is : %s\n",net_mask);	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -