问题
I have an Application (written in C/C++) thats communicating over UDP between many Windows and Linux Hosts inside the local Network (via winsock / Linux-Sockets). I only use one Port and so only one Socket on each host. Some messages are Broadcastet, replies are often Unicast but some are Broadcasts too. Everthing is working so far but:
How can i find out whether a Paket i received (via recvfrom) was a Broadcast or Unicast?
The only solution i found was to send this info inside the Payload or to use different ports. Both are not very nice...
回答1:
On Linux side you can set PKT_INFO
ip(7) socket option with setsockopt(2), and then use recvmsg(2) to get the destination address of the UDP packet.
来源:https://stackoverflow.com/questions/10667647/how-to-differentiate-between-udp-broadcasts-and-unicasts