Problem receiving UDP broadcast packets.

Grant Edwards invalid at invalid.invalid
Wed Apr 20 02:00:56 CEST 2011


On 2011-04-19, Dan Stromberg <drsalists at gmail.com> wrote:
> On Tue, Apr 19, 2011 at 3:21 PM, Grant Edwards <invalid at invalid.invalid> wrote:
>> I'm have problems figuring out how to receive UDP broadcast packets on
>> Linux.
>>
>> Here's the receiving code:
>>
>> ------------------------------receive.py-------------------------------
>
>> But, the receiving Python program never sees any packets unless the
>> _source_ IP address in the packets is on the same subnet as the
>> receiving machine.
>
> This is just how broadcasts work.
>
> Normally, you take your subnet mask and "bitwise and" it with the IP
> addresses of the sending and receiving machines.  If the results match
> for two such pairs on two different machines, then the broadcast
> should be visible, given appropriate code.

That certainly looks like what's hapenning, but it seems very
counter-productive to me.

If I send a packet to ff:ff:ff:ff:ff:ff--255.255.255.255, it's because
I want everybody on the Ethernet segment to receive it.  If I wanted
only people on a particular subnet (e.g. 10.0.0.0/8) to receive it, I
would have sent it to the subnet broadcast address (e.g. 10.255.255.255).

> However, some routers have the ability to pass packets from one subnet
> to another.  I believe this is called a "helper", at least in the
> Cisco world, and must be configured specially.

There are no routers or firewalls involved -- just a dumb Ethernet
switch.

It seems I'm going to have to use raw sockets to do what I need to do.
That's exactly what I was trying to avoid by using UDP: I'm replacing
a proprietary (non IP) MAC-level protocol that was implemented using
raw sockets.

-- 
Grant Edwards               grant.b.edwards        Yow! I'm young ... I'm
                                  at               HEALTHY ... I can HIKE
                              gmail.com            THRU CAPT GROGAN'S LUMBAR
                                                   REGIONS!



More information about the Python-list mailing list