3

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

Dima
  • 1,253
  • 3
  • 21
  • 31

1 Answers1

1

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.

ottomeister
  • 5,415
  • 2
  • 23
  • 27
  • http://stackoverflow.com/questions/5281409/get-destination-address-of-a-received-udp-packet – Dima Apr 24 '12 at 23:46