2008-06-25 22:21:18 how to deal with the head of ethernet packet?
edward jiang (CHINA)
in networking programming,i want to creat my own ether head,which including 6 bytes of source hardware address and 6 bytes of destination hardware address plus 2 bytes of ether type and ip head we creat .
i do it as follows:
1.sendfd = socket(AF_INET, SOCK_RAW, htons(0x0003));//declare a raw socket
2.setsockopt(sendfd,IPPROTO_IP,IP_HDRINCL,&on,sizeof(on));//through this step ,we could change our ip head.
in the third step,buff is the beginning of the ether head i created myself.
here,we want to send buff as our complete ether packet.but what confusing me is i found that function sendto has just
send buff as the head of a ip head,at the same time,14 bytes of ether head is set zero.
a complete ether frame shows the condition:
//we hope buff is send from here
ether head:buff starts(including mac address and 2bytes of ether type)
ip head: ip head i created
//but the conditon is :
ether:14 bytes of zero.
ip head:buff starts(including mac address and 2bytes of ether type)
data:ip head i created
so dose anybody know how to creat our own raw socket and send it out(the raw socket must conclude ether head we creat),
thanks a lot.
2008-06-26 00:35:09 Re: how to deal with the head of ethernet packet?
Mike Frysinger (UNITED STATES)
people generally use libpcap to deal with raw packets. check out their website for information.