网卡数据捕获

这篇博客介绍了一段C语言代码,用于在链路层捕获网络数据,并展示了如何设置网卡混杂模式及轮询抓取数据。目前是初步版本,后续会继续完善。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这部分代码用于从链路层抓取数据并简单显示,目前为第一个版本,后期还会进一步完善。

编译  gcc -o file file.c

执行:./file -a eth0  |-b

-a eth0:为将网卡etho设置为混杂模式

-b 为轮询抓取数据。

#include
#include
#include
#include
#include
#include 
#include
#include
#include
#include
#include
#include
#include
#include

//#include
//以太网帧信息
#define ETH_ALEN 6
#define ETH_HLEN 14
#define ETH_ZLEN 60
#define ETH_DATA_LEN 1500
#define ETH_FRAME_LEN 1514
/*
struct ethhdr
{
	unsigned char h_dest[ETH_ALEN];
	unsigned char h_source[ETH_ALEN];
	__be16 h_proto;
};
*/


int set_eth(int,char *);
int get_data_info(int);
int get_eth_info(char *);
int get_ip_info(char*);
int get_arp_info(char*);
int get_tcp_info(char*,int len);
int get_icmp_info(char*,int len);
int get_udp_info(char *,int len);
//static int arp=0;
int main(int argc,char **argv)
{
	
	int ch;//参数列表
	int fd=0;
	int ret;
	fd=socket(PF_INET,SOCK_PACKET,htons(0x0003));
	i
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值