How to differentiate between UDP Broadcasts and Unicasts?

人走茶凉 提交于 2019-12-10 21:59:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!