2
votes

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

1
I'm confused. When setting up the MulticastSocket don't you bind it to a specific address? Isn't that the address anyone can use to send to everyone? You should already have the information even if it isn't available off the packet itself.John Meagher
Yeah, but see my Update about the unicast packets :)guruz
The ugly part of this is that it seems a java multicast socket recieves datagrams to any multicast address that matches the socket's port. So if one server is multicasting to 226.1.1.6:5003 and another is multicasting to 226.2.1.99:5003, your java app will recieve all the packets, and have no way to untangle them. This is regardless of what multicast group the socket joins.Mutant Bob

1 Answers

2
votes

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.