Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to identify which interface a broadcast packet comes in on?

Reply
Thread Tools

How to identify which interface a broadcast packet comes in on?

 
 
Lincoln Yeoh
Guest
Posts: n/a
 
      09-03-2005
Hi,

If I have a program listening on 0.0.0.0someport) on all interfaces,
how do I know which network interface a broadcast packet is coming in
on - assuming Linux and _many_ interfaces. And how do I set which
interface a frame will leave on, assuming I'm sending a raw frame (no
IP address, just the ethernet address).

If I use C, it seems I'm to use the IP_PKTINFO socket options,
send/recv the ancillary messages and set/check the ipi_ifindex value.

struct in_pktinfo {
unsigned int ipi_ifindex; /* Interface index */
struct in_addr ipi_spec_dst; /* Local address */
struct in_addr ipi_addr; /* Header Destination address
*/
};

How would I achieve the same thing in Python?

This would be useful for writing something like a DHCP server - such a
server could receive packets with source IP addresses of 0.0.0.0
destined to 255.255.255.255, and will need to know which interface the
packet is coming in from AND the source ethernet (or other link layer)
address so that it can send the replies out the right interface.

Thanks!
Link.
 
Reply With Quote
 
 
 
 
Jorgen Grahn
Guest
Posts: n/a
 
      09-03-2005
On Sat, 03 Sep 2005 18:46:05 +0800, Lincoln Yeoh <(E-Mail Removed)> wrote:
> Hi,
>
> If I have a program listening on 0.0.0.0someport) on all interfaces,
> how do I know which network interface a broadcast packet is coming in
> on - assuming Linux and _many_ interfaces. And how do I set which
> interface a frame will leave on, assuming I'm sending a raw frame (no
> IP address, just the ethernet address).
>
> If I use C, it seems I'm to use the IP_PKTINFO socket options,
> send/recv the ancillary messages and set/check the ipi_ifindex value.

....
> How would I achieve the same thing in Python?


Someone may want to correct me, but from what I can see, the socket module
is almost a 1:1 mapping between the socket support your C lib has, and
Python. Plus some compatibility code for Windows.

You should be able to do everything you can do in C. Your code may
become Linux-specific if you're not careful, though.

/Jorgen

--
// Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
\X/ algonet.se> R'lyeh wgah'nagl fhtagn!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
%PIX-4-402106: Rec'd packet not an IPSEC packet. lfnetworking Cisco 3 08-27-2006 05:30 AM
How to identify which interface a broadcast packet comes in on? Lincoln Yeoh Perl Misc 2 09-06-2005 02:18 PM
How to know which interface a broadcast packet comes in on? Lincoln Yeoh Ruby 0 09-03-2005 10:45 AM
UDP Broadcast Packet (offtopic) Martin Farnik Ruby 3 07-04-2003 01:59 PM



Advertisments