Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Determine receiving address when receiving with MulticastSocket

I am using MulticastSocket to receive UDP Multicast packets. How can I determine to which address such a packet was sent? With the methods provided, I am only able to determine the sender address.

Of course, I am the one who sets the To-Address when creating the listening socket, but can I really be sure about this? What about broadcast packets? What about packets that somehow end up here? I really want to distinguish if the packet was REALLY multicast.

Thank you!

Update: Currently it seems like unicast packets just sent to that port also end up in the multicast sockets receive() :( Binding to devices also gives me no better results

like image 667
guruz Avatar asked Aug 05 '26 17:08

guruz


1 Answers

I'm a bit fuzzy on the details but a multicast packet will have been sent to the ip/port combo you subscribed to (and this info will be in the packet, somewhere), assuming you managed to have a clear path of intermediary routers that understand multicast. If you want to make sure the multicastsocket is receiving from the right network interface, there's a bunch of functions to bind it to a specific interface.

I don't think you have any way of knowing if the packet was "really" multicast, i.e. someone could always forge one, since there's no real security built in.

like image 51
wds Avatar answered Aug 07 '26 07:08

wds