Main Page | Report this Page
Linux Forum Index  »  Linux Networking  »  Getting/setting eth frame interface for raw socket...
Page 1 of 1    

Getting/setting eth frame interface for raw socket...

Author Message
...
Posted: Wed Sep 30, 2009 1:19 am
Guest
Hi

I've written a network monitoring app for linux that displays information about
ethernet frames it receives. It creates the socket as follows:

sock = socket(PF_PACKET,SOCK_RAW,htons(ETH_P_ALL))

My 1st question is , is there a simple way to get the interface name the
frame arrived on or would I have to issue an ioctl SIOCGIFCONF call
and loop through the list of interfaces comparing the MAC addresses?

My 2nd related question is - how can I specify what interface to send an
outgoing frame on when I update the code to write to the socket?

Thanks for any help.

B2003
 
...
Posted: Wed Sep 30, 2009 1:54 am
Guest
On Wed, 30 Sep 2009 06:34:22 -0500
gordon at (no spam) hammy.burditt.org (Gordon Burditt) wrote:
Quote:
I'm not sure you can *TELL* the interface name the frame arrived
on by looping through the list of interfaces comparing MAC addresses.

You can if it has arrived from an ethernet interface.

Quote:
Localhost doesn't have a MAC address.
Lots of virtual interfaces like 'gif' don't either.
Neither do some of the packets removed from the system, then re-injected
into it (say, by a userland NATD daemon).
What about broadcast packets?

None of the above work, which is why I was hoping that there was a way
of obtaining the packets interface directly but I suspect not.

B2003
 
Gordon Burditt...
Posted: Wed Sep 30, 2009 5:34 am
Guest
Quote:
I've written a network monitoring app for linux that displays information about
ethernet frames it receives. It creates the socket as follows:

sock = socket(PF_PACKET,SOCK_RAW,htons(ETH_P_ALL))

My 1st question is , is there a simple way to get the interface name the
frame arrived on or would I have to issue an ioctl SIOCGIFCONF call
and loop through the list of interfaces comparing the MAC addresses?

I'm not sure you can *TELL* the interface name the frame arrived
on by looping through the list of interfaces comparing MAC addresses.

Localhost doesn't have a MAC address.
Lots of virtual interfaces like 'gif' don't either.
Neither do some of the packets removed from the system, then re-injected
into it (say, by a userland NATD daemon).
What about broadcast packets?
 
Robert Harris...
Posted: Wed Sep 30, 2009 6:47 am
Guest
You have to do an ioctl with a request code SIOCGIFINDEX to get the
index and an ioctl with request code SIOCGIFNAME to get the interface
name from the index.

man 7 netdevice

will tell you a fuller story.

Robert

boltar2003 at (no spam) yahoo.co.uk wrote:
Quote:
Hi

I've written a network monitoring app for linux that displays information about
ethernet frames it receives. It creates the socket as follows:

sock = socket(PF_PACKET,SOCK_RAW,htons(ETH_P_ALL))

My 1st question is , is there a simple way to get the interface name the
frame arrived on or would I have to issue an ioctl SIOCGIFCONF call
and loop through the list of interfaces comparing the MAC addresses?

My 2nd related question is - how can I specify what interface to send an
outgoing frame on when I update the code to write to the socket?

Thanks for any help.

B2003

 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Thu Nov 26, 2009 6:03 am