locked
How to retrieve SRV record in WinRT (DNS-SRV )

    Question

  • We know that, HostName can take both domain name and IP address. But what about DNS SRV?

    If for a particular application we need to retrieve the SRV records from server. How can we do this in WinRT?

    I tried following way but failed.

    socket->ConnectAsync(ref new HostName("_stun._udp.example.com"), "dns-srv");

    Advance thanks to the repliers.


    Thursday, May 23, 2013 9:31 AM

Answers

  • If you want to connect a DatagramSocket based on the address/port information in DNS SRV records, you'd do:

    connect->ConnectAsync(ref new HostName("example.com"), "stun");

    This will result in a DNS SRV record query for _stun._udp.example.com (the _udp is derived from the fact that you're doing it on a DatagramSocket), sort the results and connect the UDP socket to the best result.

    If you just want to get all address/port pairs without connecting the socket, you can use
    DatagramSocket::GetEndpointPairsAsync(ref new HostName("example.com"), "stun")

    Tuesday, July 02, 2013 10:24 PM

All replies

  • Hi,

    What function do you want to achieve? Or did you have any worked code in native C++ or .NET?

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, May 24, 2013 7:30 AM
  • DnsQueryEx  is desktop-only, so you can't use that from a store app. You could look for a web service API that allows you to query SRV records, or even write your own and deploy it to a location from where your store app can access it.

    http://blog.voidnish.com

    • Proposed as answer by Jesse Jiang Monday, May 27, 2013 2:13 AM
    • Unproposed as answer by Mokarrom Hossain Tuesday, June 11, 2013 2:36 PM
    Friday, May 24, 2013 3:20 PM
  • If you want to connect a DatagramSocket based on the address/port information in DNS SRV records, you'd do:

    connect->ConnectAsync(ref new HostName("example.com"), "stun");

    This will result in a DNS SRV record query for _stun._udp.example.com (the _udp is derived from the fact that you're doing it on a DatagramSocket), sort the results and connect the UDP socket to the best result.

    If you just want to get all address/port pairs without connecting the socket, you can use
    DatagramSocket::GetEndpointPairsAsync(ref new HostName("example.com"), "stun")

    Tuesday, July 02, 2013 10:24 PM
  • And what about SRV record under a CNAME. Is it possible to get it ?

    _stun._foo._udp.example.com where foo is a CNAME and stun a SRV record

    DatagramSocket::GetEndpointPairsAsync(new HostName("example.com"), "stun._foo") can't find it.

    Best regards.

    Wednesday, June 11, 2014 3:54 PM
  • Thank you for pointing this out.  We have confirmed that this is a bug in the current implementation of
    DatagramSocket::GetEndpointPairsAsync(), and are looking at fixing this in the future.  A possible workaround in the meantime would be to implement sending the DNS queries yourself, using a DatagramSocket.  If you choose to do so, you can get the DNS server addresses via the Win32 DhcpRequestParams /  Dhcpv6RequestParams APIs which are available to store apps.
    Tuesday, June 24, 2014 9:12 PM