Dima
Dima

Reputation: 1311

getting multicast source IP address on Linux

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'?

Upvotes: 3

Views: 1447

Answers (1)

ottomeister
ottomeister

Reputation: 5828

Use setsockopt(2) to set the IP_PKTINFO option (see ip(7)) on your receiving socket. Then use recvmsg(2) to collect incoming datagrams, with the msg_control and msg_controllen fields of its msg argument 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_RECVDSTADDR option instead.

Upvotes: 1

Related Questions