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

Jorgen Grahn jgrahn-nntq at algonet.se
Sat Sep 3 18:15:25 CEST 2005


On Sat, 03 Sep 2005 18:46:05 +0800, Lincoln Yeoh <junkto at tm.net.my> wrote:
> Hi,
>
> If I have a program listening on 0.0.0.0:(someport) 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!



More information about the Python-list mailing list