2008-06-25 22:21:18     how to deal with the head of ethernet packet?

Document created by Aaronwu Employee on Aug 6, 2013
Version 1Show Document
  • View in full screen mode

2008-06-25 22:21:18     how to deal with the head of ethernet packet?

edward jiang (CHINA)

Message: 57876   

 

hello all:

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.

 

3.n=sendto(sendfd,buff,recv_len,0,(struct sockaddr*)&dest,sizeof(dest));

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

data:data

 

//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

data.

 

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.

QuoteReplyEditDelete

 

 

2008-06-26 00:35:09     Re: how to deal with the head of ethernet packet?

Mike Frysinger (UNITED STATES)

Message: 57878   

 

people generally use libpcap to deal with raw packets.  check out their website for information.

Attachments

    Outcomes