How do I identify a broadcast message?

Sometimes I have to send a message to a specific IP address, and sometimes I have to broadcast a message to all the IP addresses on my network. On the other end, I have to distinguish between broadcast and normal, but recvfrom()

just returns the address from which the message came; there is no difference between them. Can anyone help me distinguish between them?

UDP is a protocol.

+2


a source to share


1 answer


I don't think this is possible with the Python module socket

. UDP is a very minimal protocol, and the only way to distinguish between broadcast and untransmitted UDP packets is to look at the destination address. However, you cannot validate this part of the package with the BSD socket API (if I remember it correctly) and the module socket

only provides the BSD socket API. The best way would be to use the first byte of the message to indicate whether it is a broadcast or unicast message.



+5


a source







All Articles