GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add support for mDNS by allowing multicast server address · Issue #147 · dnsjava/dnsjava

Add support for mDNS by allowing multicast server address #147

New issue
Copy link
New issue
Copy link
Open
#148
Open
Add support for mDNS by allowing multicast server address#147
#148
Copy link

Description

@ka2ddo
ka2ddo
opened on Jan 5, 2021
Issue body actions

The present version of the NioUdpClient code in dnsjava does not support specifying the mDNS multicast address (224.0.0.251 or [FF02::FB]) and port 5353 for the DNS server address, because the UDP socket is connected to the remote address, which will never be seen in a reply to a multicast query. Included is the diff of a proposed change to allow receiving data from the first mDNS server to respond (the most minimal form of an mDNS client, as defined by RFC6762), where the DatagramChannel is not connected to the remote address if the remote address is multicast, so that any mDNS server's unicast reply packet can be accepted.

diff --git a/src/main/java/org/xbill/DNS/NioUdpClient.java b/src/main/java/org/xbill/DNS/NioUdpClient.java
index 2c7df72..57a26c4 100644
--- a/src/main/java/org/xbill/DNS/NioUdpClient.java
+++ b/src/main/java/org/xbill/DNS/NioUdpClient.java
@@ -3,9 +3,7 @@ package org.xbill.DNS;
 
 import java.io.EOFException;
 import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.SocketException;
-import java.net.SocketTimeoutException;
+import java.net.*;
 import java.nio.ByteBuffer;
 import java.nio.channels.DatagramChannel;
 import java.nio.channels.SelectionKey;
@@ -84,6 +82,7 @@ final class NioUdpClient extends Client {
     private final int max;
     private final long endTime;
     private final DatagramChannel channel;
+    private final SocketAddress remoteSocketAddress;
     private final CompletableFuture<byte[]> f;
 
     void send() throws IOException {
@@ -91,9 +90,9 @@ final class NioUdpClient extends Client {
       verboseLog(
           "UDP write",
           channel.socket().getLocalSocketAddress(),
-          channel.socket().getRemoteSocketAddress(),
+          remoteSocketAddress,
           data);
-      int n = channel.send(buffer, channel.socket().getRemoteSocketAddress());
+      int n = channel.send(buffer, remoteSocketAddress);
       if (n <= 0) {
         throw new EOFException();
       }
@@ -109,10 +108,12 @@ final class NioUdpClient extends Client {
 
       DatagramChannel channel = (DatagramChannel) key.channel();
       ByteBuffer buffer = ByteBuffer.allocate(max);
+      SocketAddress source;
       int read;
       try {
-        read = channel.read(buffer);
-        if (read <= 0) {
+        source = channel.receive(buffer);
+        read = buffer.position();
+        if (read <= 0 || source == null) {
           throw new EOFException();
         }
       } catch (IOException e) {
@@ -128,7 +129,7 @@ final class NioUdpClient extends Client {
       verboseLog(
           "UDP read",
           channel.socket().getLocalSocketAddress(),
-          channel.socket().getRemoteSocketAddress(),
+          source,
           data);
       silentCloseChannel();
       f.complete(data);
@@ -185,9 +186,11 @@ final class NioUdpClient extends Client {
         }
       }
 
-      channel.connect(remote);
+      if (!remote.getAddress().isMulticastAddress()) {
+        channel.connect(remote);
+      }
       long endTime = System.nanoTime() + timeout.toNanos();
-      Transaction t = new Transaction(data, max, endTime, channel, f);
+      Transaction t = new Transaction(data, max, endTime, channel, remote, f);
       pendingTransactions.add(t);
       registrationQueue.add(t);
       selector.wakeup();

Activity

  1. ka2ddo commented on Jan 6, 2021

    @ka2ddo
    ka2ddo
    on Jan 6, 2021
    Author
    More actions

    Attached is a somewhat larger patch diff that also supports multiple mDNS servers responding instead of only the first response. No behavior change if a unicast address is specified for the DNS server.
    mDNS.patch.txt

  2. ibauersachs commented on Jan 6, 2021

    @ibauersachs
    ibauersachs
    on Jan 6, 2021
    Member
    More actions

    Why don't you create a pull request that I could review?

  3. ka2ddo commented on Jan 6, 2021

    @ka2ddo
    ka2ddo
    on Jan 6, 2021 via email
    Author
    More actions
    OK. I'm relatively new to github, so not familiar with that process. Will let you know when I have the branch created and pushed. Andrew, KA2DDO
    …
    ________________________________________ From: Ingo Bauersachs <[email protected]> Sent: Wednesday, January 6, 2021 10:41 AM To: dnsjava/dnsjava Cc: ka2ddo; Author Subject: Re: [dnsjava/dnsjava] Add support for mDNS by allowing multicast server address (#147) Why don't you create a pull request that I could review? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub<#147 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AESTBTIS3BDAQPIGGXIVEDTSYSAD3ANCNFSM4VVNMTRQ>.
  4. ka2ddo commented on Jan 6, 2021

    @ka2ddo
    ka2ddo
    on Jan 6, 2021 via email
    Author
    More actions
    I can't seem to push my private branch changes back to github. How do I get my private branch onto github so I can make a pull request for it?
    …
    ________________________________________ From: Ingo Bauersachs <[email protected]> Sent: Wednesday, January 6, 2021 10:41 AM To: dnsjava/dnsjava Cc: ka2ddo; Author Subject: Re: [dnsjava/dnsjava] Add support for mDNS by allowing multicast server address (#147) Why don't you create a pull request that I could review? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub<#147 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AESTBTIS3BDAQPIGGXIVEDTSYSAD3ANCNFSM4VVNMTRQ>.
  5. ibauersachs commented on Jan 6, 2021

    @ibauersachs
    ibauersachs
    on Jan 6, 2021
    Member
    More actions

    You need to fork the repository to your account, then push your branch there. You can create a pull request in GitHub's web ui afterwards. See e.g. this guide here: https://guides.github.com/activities/forking/

  6. ka2ddo commented on Jan 6, 2021

    @ka2ddo
    ka2ddo
    on Jan 6, 2021 via email
    Author
    More actions
    I have a cloned copy of your repository, I made and committed the changes on a branch named mDNS_patch_ka2ddo, and tried to push the changes upstream, but got the following error: remote: Permission to dnsjava/dnsjava.git denied to ka2ddo. fatal: unable to access 'https://github.com/dnsjava/dnsjava.git/': The requested URL returned error: 403 Do you need to grant me permission to push branch changes? Note that the file I attached in my second comment should easily modify an existing git checkout with my changes using the 'patch' command. Or is there a branch naming convention I have to follow to be given permission? Andrew, KA2DDO
    …
    ________________________________________ From: Ingo Bauersachs <[email protected]> Sent: Wednesday, January 6, 2021 11:51 AM To: dnsjava/dnsjava Cc: ka2ddo; Author Subject: Re: [dnsjava/dnsjava] Add support for mDNS by allowing multicast server address (#147) You need to fork the repository to your account, then push your branch there. You can create a pull request in GitHub's web ui afterwards. See e.g. this guide here: https://guides.github.com/activities/forking/ — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub<#147 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AESTBTKTD5XNQMDCJU77Y2LSYSIHRANCNFSM4VVNMTRQ>.
  7. ibauersachs commented on Jan 6, 2021

    @ibauersachs
    ibauersachs
    on Jan 6, 2021
    Member
    More actions

    You need to fork the repository to your account so that it appears here: https://github.com/ka2ddo?tab=repositories

    Then change the origin of your local clone, push and create the pull request. It's all explained in the link I posted before.

    I don't have my devenv with me atm, so I can't even look at the patch. And a PR would automatically run all tests and checks :-)

  8. ka2ddo commented on Jan 6, 2021

    @ka2ddo
    ka2ddo
    on Jan 6, 2021
    Author
    More actions

    Pull request now available.

  9. ibauersachs
    linked a pull request that will close this issuepatch to support mDNS and multicast to servers #148on Jan 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.