Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To the best of my knowledge the only way to do this would be with the </p> <p><code>IP_RECVDSTADDR</code> </p> <p>socket option. This option is supposed to make sure that the dst address of the interface the packet came in on is available when bound to the wildcard address. So it should work with broadcast too I assume.</p> <p>Here is a C example I picked up off the internet:</p> <p><a href="http://groups.google.com/group/comp.os.linux.development.system/msg/e09d9c278c7e6fe1?pli=1" rel="nofollow noreferrer">How to get UDP destination address on incoming packets</a></p> <p>I would read up on <a href="http://linux.die.net/man/2/recvmsg" rel="nofollow noreferrer"><code>recvmsg</code></a> and then try and find out if this interface is available in Java.</p> <p><strong>Edit:</strong> </p> <p>I just realized that you may have one more option if it's supported in Java. You may still need the <code>IP_RECVDSTADDR</code> socket option ( not sure ), but instead of using recvmsg you could use a raw socket and get the destination address from the IP header. </p> <p>Open your socket as using <code>SOCK_RAW</code> and you'll get the full IP header at the beginning of each message including source and destination addresses.</p> <p>Here's an example of using UDP with a raw socket in C on Linux:</p> <p><a href="http://www.tenouk.com/Module43a.html" rel="nofollow noreferrer">Advanced TCP/IP - THE RAW SOCKET PROGRAM EXAMPLES</a></p> <p>I'd be surprised if this method doesn't work in Java also.</p> <p><strong>Edit2</strong></p> <p>One more idea. Is there a reason you can't use Multicast or a specific reason you chose Broadcast over Multicast? As far as I understand with Multicast you'd always know which Interface the packets are received on since you always bind to a specific interface when joining a Multicast group ( especially with IP4 where you bind to the interface via one of it's IP addresses ).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload