Glynn Clements (
Sun, 14 Mar 1999 17:03:19 +0000 (GMT)

Spyro Papademetriou wrote:

> i am trying to parse the src mac and src ip of an incoming ethernet
> frame.
> i seem to be able to parse the mac frame. however i am getting sets of
> "ffffff"'s when i shouldn't. also i seem to be unable to extract the src
> ip.
> below is the code and a sample output. i am using SOCK_PACKET.
> any help or suggestions would be very helpful.
> this is the code that prints out the mac address it should be:
> 00:60:97:19:B4:C9
> ---------------
> .
> .
> .
> socket(PF_INET,SOCK_PACKET,htons(ETH_P_ALL));
> recvfrom(fd0,rbuff,ETH_LEN,0,&saddr,&fromlen);
> for(i=0;i<20;i++)
> printf("%s.",rbuff[i]);
> ----------------
> this is the output
> 0.60.ffffff97.19.ffffffb4.ffffffc9.

You have declared `rbuff' as `char[]', when it should be `unsigned char[]'.
This is causing bytes above 127 to be interpreted as negative numbers.

> also, how do i extract the ip portion ?

The IP header should immediately follow the ethernet header. However,
you will have to specify a larger value than ETH_LEN to recvfrom() in
order to retrieve this data.

Glynn Clements <>
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to