473,563 Members | 2,904 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Hi,

If I have a program listening on 0.0.0.0:(somepo rt) 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.
Sep 3 '05 #1
1 2808
On Sat, 03 Sep 2005 18:46:05 +0800, Lincoln Yeoh <ju****@tm.net. my> wrote:
Hi,

If I have a program listening on 0.0.0.0:(somepo rt) 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!
Sep 3 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1741
by: Sandeep Arya | last post by:
Hello to all Well this is my first mail on this list. I am facing a problem associated with collecting IP address on my network. What i thought is to send broadcast packet over the network and then recieving back the reply from the computers and bridges connected to my network and then adding their IP Address in a list. How this can be...
9
4629
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
0
11845
by: Stephan Steiner | last post by:
Hi The project I'm currently working on involves sending large UDP broadcasts. As the .NET framework already provides an easy facility for sending and receiving UDP packets I thought it was a good idea to use UdpClient rather than sockets directly. A few weeks back I ended up rewriting the receiver part to use sockets directly because I had...
3
3626
by: LinuxGuy | last post by:
Hi All, I have 2 interfaces with IP addresses configured with same subnet on machine. my application need to send udp broadcast packet to subnet. but whenever I send any packet it is going through both the interfaces. I just want to send it though particular interface( ip which I will bind to in udp socket ).
3
2557
by: Sam | last post by:
Hi I am trying to create a arraylist of Intefaces so I only need to create each once and I would like to be able to identify the specific interface when I loop thru ??? Is there some way to set a Custom Attribute on each Instance of the Interface??? Thanks
0
1496
by: =?Utf-8?B?aXdkdTE1?= | last post by:
Hi, im trying to broadcast a UDP packet to my networks broadcast address (192.168.255.255) which i have verified with my network admin is the correct address. i can ping that address and get responses from the other computers on the network (via the command prompt) but when i attempt to send a UDP packet, it does not go through. there are no...
2
6370
by: Mali Findik | last post by:
Hi @ll, i've got problems with sending an UDP broadcast datagramm over two network interfaces. The code is like this: <Code> UdpClient client = new UdpClient(); IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Parse("255.255.255.255"), 1234);
0
1699
by: riaancillie | last post by:
I apologize in advance since this isn't strictly the most appropriate group to ask this question in. I am using a Socket to broadcast UDP datagrams as such: FSocket.EnableBroadcast = true; FSocket.SendTo(bytes, new IPEndPoint(IPAddress.Broadcast, 9991) ); I receive the datagram on the other computers on the network, but the computer...
6
2895
by: deeas | last post by:
hi everyone : please how to change the destination address from "localhost" to the ip: "192.168.1.1" Static port_server As Integer = 5000 Static name_server As String = "localhost" Static port_client As Integer = 5001 Dim sock_server As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.