linux socket raw发送,使用raw socket发送以太网帧

/*

* send a raw ethernet frame

*/

#include //memcpy()

#include //strxxx()

#include //close()

#include //socket()

#include //htons()

#include //struct ifreq

#include //ETH_ALEN(6),ETH_HLEN(14),ETH_FRAME_LEN(1514),struct ethhdr

#include //struct sockaddr_ll

#include //ioctl()

union ethframe {

struct {

struct ethhdr header;

char data[ETH_DATA_LEN];

} field;

char buffer[ETH_FRAME_LEN];

};

int main(void)

{

char *iface = "ext1";

char dest[ETH_ALEN] = {0x00, 0x12, 0x34, 0x56, 0x78, 0x90};

short proto = 0x1234;

char *data = "hello world";

unsigned short data_len = strlen(data);

int s;

if ((s = socket(AF_PACKET, SOCK_RAW, htons(proto))) < 0) {

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值