Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the broadcast source ip address with boost::asio

I'm currently struggling with a basic socket problem using boost::asio. A server is sending broadcasts in my LAN to discover client machines. The broadcast is successfully read on the client, but now I'm stuck with the question of how to get the IP address of the server, to be able to establish a regular connection to it.

I tried to query the remote endpoint after receiving the broadcast, but of course I get 0.0.0.0 as a result. Same for querying the local endpoint before sending the broadcast on the server (I'd send the server IP in the broadcast, then)

So, what is the default procedure to get the broadcast sender address?

Thanks :)

like image 509
noIdea Avatar asked Dec 08 '25 15:12

noIdea


1 Answers

try using the recieve_from or async_recieve_from methods for the UDP socket... they take an endpoint parameter that is filled in when the data is recieved.

like image 165
diverscuba23 Avatar answered Dec 11 '25 16:12

diverscuba23