tags:

views:

33

answers:

1

How can I distinguish between a broadcasted message and a direct message for my ip?

I'm doing this in python.

A: 

Basically what you need to do is create a raw socket, receive a datagram, and examine the destination address in the header. If that address is a broadcast address for the network adapter the socket is bound to, then you're golden.

I don't know how to do this in Python, so I suggest looking for examples of raw sockets and go from there. Bear in mind, you will need root access to use raw sockets, and you had better be real careful if you plan on sending using a raw socket.

As you might imagine, this will not be a fun thing to do. I suggest trying to find a way to avoid doing this.

Michael Melanson
udp is the the protocol
sia
no there is no difference between the address i can detect from a broadcast and a direct one
sia
I don't understand. Broadcast messages are just packets that are sent to a broadcast address for a particular net. A packet sent to 172.16.1.255 will be broadcast to the entire 172.16.1.0/24 network. When you receive it, the destination address in the IP header will have this broadcast address.
Michael Melanson