I’m using at struct sockaddr_in to receive multicast data sent out from another machine. When I print out the source address using inet_ntop it gives me the source address of the PC that sent the data.
I would like to know if there is a way of getting the multicast address that the data was ‘sent to’?
Use
setsockopt(2)to set theIP_PKTINFOoption (seeip(7)) on your receiving socket. Then userecvmsg(2)to collect incoming datagrams, with themsg_controlandmsg_controllenfields of itsmsgargument referring to a buffer where the datagram’s destination address can be captured.Systems other than Linux might provide this capability through the BSD
IP_RECVDSTADDRoption instead.