开发者

using linux raw socket with vconfig interface

I want to use socket to transmit my packet untouched so I tried using raw socket like this.

static int raw_sock = 0;
static struct sockaddr_ll saddr;
static struct ifreq ifr;
static int ifindex;
raw_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
memset(&ifr,0,sizeof(ifr));
memset(&saddr,0,sizeof(saddr));
strcpy(ifr.ifr_name,"eth0");
ioctl(raw_sock,SIOCGIFINDEX,&ifr);
ifindex = ifr.ifr_ifindex;
sad开发者_高级运维dr.sll_family = AF_PACKET;
saddr.sll_ifindex = ifindex;
saddr.sll_protocol = ETH_P_ALL;
sendto(raw_sock,pkt.buffer,pkt.pkt_len,0,(struct sockaddr *)&saddr,sizeof(saddr));

Everything work correctly as I want but after I added some vlan interface using

vconfig add eth0 4000

The above code does not work as before. It automatically add the vlan tag 0x81 0x00 0x00 0x00 to all the packet it transmitted out. Does anyone has solution for this. I just want to send all packet untouched. Thank you.


Try sending from vlan0, instead of from eth0.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜