Cannot send UDP DNS request to IPv6 DNS?












2















For a project I am writing a simple dig-like tool for sending DNS requests and processing the responses. I am using C# UdpClient to send the packet. Right now I can send to any IPv4 server just fine but when I try to specify an IPv6 DNS (2001:4860:4860:0:0:0:0:8888 or 2001:4860:4860:0:0:0:0:8844) I get errors.



My code is:



try {
var ip = "[dns ip]";
var DNSServer = IPAddress.Parse(ip);
var endpoint = new IPEndPoint(DNSServer, 53);

byte packet = new byte[UDP_LENGTH];
var index = createRequest(type, hostname, packet);

client.Send(packet, index, endpoint);

var result = client.Receive(ref endpoint);
ParseResponse(result);

}
catch(Exception e){
Console.WriteLine(e.ToString());
Environment.Exit(0);
}


If ip == 8.8.8.8 or any other IPv4 address it all runs as intended. If ip == 2001:4860:4860::8844 or any other IPv6 I get:



System.Net.Sockets.SocketException (10051): A socket operation was attempted to an unreachable network
at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
at System.Net.Sockets.Socket.SendTo(Byte buffer, Int32 offset, Int32 size, SocketFlags socketFlags, EndPoint remoteEP)
at System.Net.Sockets.UdpClient.Send(Byte dgram, Int32 bytes, IPEndPoint endPoint)
at Program.queryDNS(IPAddress DNSServer, DnsType type, String hostname) in C:...Program.cs:line 66









share|improve this question



























    2















    For a project I am writing a simple dig-like tool for sending DNS requests and processing the responses. I am using C# UdpClient to send the packet. Right now I can send to any IPv4 server just fine but when I try to specify an IPv6 DNS (2001:4860:4860:0:0:0:0:8888 or 2001:4860:4860:0:0:0:0:8844) I get errors.



    My code is:



    try {
    var ip = "[dns ip]";
    var DNSServer = IPAddress.Parse(ip);
    var endpoint = new IPEndPoint(DNSServer, 53);

    byte packet = new byte[UDP_LENGTH];
    var index = createRequest(type, hostname, packet);

    client.Send(packet, index, endpoint);

    var result = client.Receive(ref endpoint);
    ParseResponse(result);

    }
    catch(Exception e){
    Console.WriteLine(e.ToString());
    Environment.Exit(0);
    }


    If ip == 8.8.8.8 or any other IPv4 address it all runs as intended. If ip == 2001:4860:4860::8844 or any other IPv6 I get:



    System.Net.Sockets.SocketException (10051): A socket operation was attempted to an unreachable network
    at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
    at System.Net.Sockets.Socket.SendTo(Byte buffer, Int32 offset, Int32 size, SocketFlags socketFlags, EndPoint remoteEP)
    at System.Net.Sockets.UdpClient.Send(Byte dgram, Int32 bytes, IPEndPoint endPoint)
    at Program.queryDNS(IPAddress DNSServer, DnsType type, String hostname) in C:...Program.cs:line 66









    share|improve this question

























      2












      2








      2








      For a project I am writing a simple dig-like tool for sending DNS requests and processing the responses. I am using C# UdpClient to send the packet. Right now I can send to any IPv4 server just fine but when I try to specify an IPv6 DNS (2001:4860:4860:0:0:0:0:8888 or 2001:4860:4860:0:0:0:0:8844) I get errors.



      My code is:



      try {
      var ip = "[dns ip]";
      var DNSServer = IPAddress.Parse(ip);
      var endpoint = new IPEndPoint(DNSServer, 53);

      byte packet = new byte[UDP_LENGTH];
      var index = createRequest(type, hostname, packet);

      client.Send(packet, index, endpoint);

      var result = client.Receive(ref endpoint);
      ParseResponse(result);

      }
      catch(Exception e){
      Console.WriteLine(e.ToString());
      Environment.Exit(0);
      }


      If ip == 8.8.8.8 or any other IPv4 address it all runs as intended. If ip == 2001:4860:4860::8844 or any other IPv6 I get:



      System.Net.Sockets.SocketException (10051): A socket operation was attempted to an unreachable network
      at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
      at System.Net.Sockets.Socket.SendTo(Byte buffer, Int32 offset, Int32 size, SocketFlags socketFlags, EndPoint remoteEP)
      at System.Net.Sockets.UdpClient.Send(Byte dgram, Int32 bytes, IPEndPoint endPoint)
      at Program.queryDNS(IPAddress DNSServer, DnsType type, String hostname) in C:...Program.cs:line 66









      share|improve this question














      For a project I am writing a simple dig-like tool for sending DNS requests and processing the responses. I am using C# UdpClient to send the packet. Right now I can send to any IPv4 server just fine but when I try to specify an IPv6 DNS (2001:4860:4860:0:0:0:0:8888 or 2001:4860:4860:0:0:0:0:8844) I get errors.



      My code is:



      try {
      var ip = "[dns ip]";
      var DNSServer = IPAddress.Parse(ip);
      var endpoint = new IPEndPoint(DNSServer, 53);

      byte packet = new byte[UDP_LENGTH];
      var index = createRequest(type, hostname, packet);

      client.Send(packet, index, endpoint);

      var result = client.Receive(ref endpoint);
      ParseResponse(result);

      }
      catch(Exception e){
      Console.WriteLine(e.ToString());
      Environment.Exit(0);
      }


      If ip == 8.8.8.8 or any other IPv4 address it all runs as intended. If ip == 2001:4860:4860::8844 or any other IPv6 I get:



      System.Net.Sockets.SocketException (10051): A socket operation was attempted to an unreachable network
      at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
      at System.Net.Sockets.Socket.SendTo(Byte buffer, Int32 offset, Int32 size, SocketFlags socketFlags, EndPoint remoteEP)
      at System.Net.Sockets.UdpClient.Send(Byte dgram, Int32 bytes, IPEndPoint endPoint)
      at Program.queryDNS(IPAddress DNSServer, DnsType type, String hostname) in C:...Program.cs:line 66






      c# .net sockets dns udp






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 26 '18 at 4:48









      SamSam

      1,1481823




      1,1481823
























          1 Answer
          1






          active

          oldest

          votes


















          1















          A socket operation was attempted to an unreachable network




          Likely you don't have IPv6 connectivity to the network you are trying to reach. This might be because you don't have IPv6 inside your local network, that you have no IPv6 gateway, that you have no public IPv6 address on your router ... . Other tools like dig should show the same behavior when called on the same machine, i.e. it is not related to your code.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474919%2fcannot-send-udp-dns-request-to-ipv6-dns%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1















            A socket operation was attempted to an unreachable network




            Likely you don't have IPv6 connectivity to the network you are trying to reach. This might be because you don't have IPv6 inside your local network, that you have no IPv6 gateway, that you have no public IPv6 address on your router ... . Other tools like dig should show the same behavior when called on the same machine, i.e. it is not related to your code.






            share|improve this answer




























              1















              A socket operation was attempted to an unreachable network




              Likely you don't have IPv6 connectivity to the network you are trying to reach. This might be because you don't have IPv6 inside your local network, that you have no IPv6 gateway, that you have no public IPv6 address on your router ... . Other tools like dig should show the same behavior when called on the same machine, i.e. it is not related to your code.






              share|improve this answer


























                1












                1








                1








                A socket operation was attempted to an unreachable network




                Likely you don't have IPv6 connectivity to the network you are trying to reach. This might be because you don't have IPv6 inside your local network, that you have no IPv6 gateway, that you have no public IPv6 address on your router ... . Other tools like dig should show the same behavior when called on the same machine, i.e. it is not related to your code.






                share|improve this answer














                A socket operation was attempted to an unreachable network




                Likely you don't have IPv6 connectivity to the network you are trying to reach. This might be because you don't have IPv6 inside your local network, that you have no IPv6 gateway, that you have no public IPv6 address on your router ... . Other tools like dig should show the same behavior when called on the same machine, i.e. it is not related to your code.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 26 '18 at 5:50









                Steffen UllrichSteffen Ullrich

                62.3k360102




                62.3k360102
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474919%2fcannot-send-udp-dns-request-to-ipv6-dns%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Wiesbaden

                    Marschland

                    Dieringhausen