3

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

GameFreak
  • 2,881
  • 7
  • 34
  • 38
guruz
  • 1,604
  • 14
  • 21
  • 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 Nov 07 '08 at 13:32
  • Yeah, but see my Update about the unicast packets :) – guruz Nov 07 '08 at 13:35
  • 1
    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 Jun 21 '12 at 21:16

1 Answers1

2

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.

wds
  • 31,873
  • 11
  • 59
  • 84
  • I have the same fuzzy recollection, and a quick re-reading of Steven's TCP/IP Illustrated seems to bear this out. – Ken Gentle Nov 07 '08 at 12:37
  • 1
    Well, 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. – guruz Nov 07 '08 at 13:25