Receiving UDP broadcast

前端 未结 2 680
小鲜肉
小鲜肉 2021-02-04 13:27

I have to receive an UDP broadcast (in Ubuntu if that makes any difference). Using Wireshark, I can see the packet being sent from the server machine, and I can see it being rec

2条回答
  •  旧巷少年郎
    2021-02-04 13:34

    To send and receive broadcast

    1. Be sure that netmask is correct. in windows mask for broadcast packets does not matters, but not in linux.

    2. bind socket to INADDR_ANY

    3. setsockopt to BROADCAST

    4. call sendto with sendaddr.sin_addr.s_addr = inet_addr("your_interface_broadcast_address"). or - call sento several times for each interface with its broadcast ip address.

    5. call recvfrom. any time before calling recvfrom, set up length parameter.

提交回复
热议问题