#121 Multicast query sending on wrong NIC

open-accepted
None
5
2011-12-27
2011-12-22
Anonymous
No

Appears to be related to #3270653.

JmDNS is sending query packets on the first available interface regardless of constructor arguments. Responses are received correctly on the specified interface. setNetworkInterface() statements on MulticastSockets are being ignored; this may be a quirk of the socket binding rules used on the MacOS JVM.

This can be remedied by explicitly binding to an address in the MulticastSocket's constructor. Possible fix in supplied Eclipse .patch file (works for me, but only tested on one machine).

Discussion

  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous

    Anonymous - 2011-12-22

    Possible fix

     
    Last edit: Anonymous 2014-02-17
  • Pierre Frisch

    Pierre Frisch - 2011-12-23

    I would prefer to fix the socket directly as your implementation will reopen the socket at each send which can be quite costly. I have committed the following patch could you check that it fix your issue/ Thanks

    Pierre

    ### Eclipse Workspace Patch 1.0
    #P jmdns
    Index: src/main/java/javax/jmdns/impl/JmDNSImpl.java
    ===================================================================
    --- src/main/java/javax/jmdns/impl/JmDNSImpl.java (revision 326)
    +++ src/main/java/javax/jmdns/impl/JmDNSImpl.java (working copy)
    @@ -9,6 +9,7 @@
    import java.net.Inet4Address;
    import java.net.Inet6Address;
    import java.net.InetAddress;
    +import java.net.InetSocketAddress;
    import java.net.MulticastSocket;
    import java.net.SocketException;
    import java.util.AbstractMap;
    @@ -449,7 +450,7 @@
    if (_socket != null) {
    this.closeMulticastSocket();
    }
    - _socket = new MulticastSocket(DNSConstants.MDNS_PORT);
    + _socket = new MulticastSocket(new InetSocketAddress((_localHost != null ? _localHost.getInetAddress() : null), DNSConstants.MDNS_PORT));
    if ((hostInfo != null) && (hostInfo.getInterface() != null)) {
    try {
    _socket.setNetworkInterface(hostInfo.getInterface());

    commit -m "Multicast query sending on wrong NIC - ID: 3463811" /Users/pierre/Projects/workspace/jmdns/CHANGELOG.txt /Users/pierre/Projects/workspace/jmdns/src/main/java/javax/jmdns/impl/JmDNSImpl.java
    Sending /Users/pierre/Projects/workspace/jmdns/CHANGELOG.txt
    Sending /Users/pierre/Projects/workspace/jmdns/src/main/java/javax/jmdns/impl/JmDNSImpl.java
    Transmitting file data ...
    Committed revision 330.

     
  • Pierre Frisch

    Pierre Frisch - 2011-12-23
    • assigned_to: nobody --> spearway
    • status: open --> pending-fixed
     
  • Pierre Frisch

    Pierre Frisch - 2011-12-27
    • status: pending-fixed --> open-fixed
     
  • Pierre Frisch

    Pierre Frisch - 2011-12-27

    This fix does not work. Reopening.

    Pierre

     
  • Pierre Frisch

    Pierre Frisch - 2011-12-27

    The suggested patch send the packets on the right interface but the wrong port mine creates a conflicts reverting it all.

    Pierre

     
  • Pierre Frisch

    Pierre Frisch - 2011-12-27
    • status: open-fixed --> open-accepted