title: Java UDP multicast, determine which group sent packet
body: <p>I'm making an application where there is a certain thread (MulticastListenerThread) which has a MulticastSocket and is listening for UDP (datagram) packets sent to the multicast group the socket is listening too.</p>
  
  <p>This works. I can join a multicast group, send a message to that group and receive it through the MulticastSocket.</p>
  
  <p>However, I would like to determine, from the receiver point of view, from which multicast group he received the packet. The following code gives me the address of the originator of the packet, not the multicast group:</p>
  
  <pre><code>DatagramPacket packet = new DatagramPacket(buf, buf.length);
  mlcSenderSocket.receive(packet);
  String src_addr = packet.getAddress().getHostAddress();
  </code></pre>
  
  <p>The code for sending the packet is as follows:</p>
  
  <pre><code>InetAddress address = InetAddress.getByName(dest);
  packet = new DatagramPacket(payload, payload.length,
      address, mlcEventPort);
  LLog.out(this,"[NC] MLC packet Sent to ev port MLC " + mlcEventPort
      + " and to addr " + address);
  mlcSenderSocket.send(packet);
  </code></pre>
  
  <p>Is it at all possible to determine which group sent the packet? </p>
  
  <p>Edit:</p>
  
  <p>It appears this isn't possible. 
  In terms of performance impact (I'm working for IoT devices), would assigning a socket per multicast group (and hence, a listener thread per group) be viable? Potentially many groups may be joined (in terms of tens or hundreds even). If it is viable, then I just need to keep the joined group address somewhere manually and refer to it as necessary.
  Suggestions for other work arounds are welcome!</p>