tfDnsGetSrvHost

Jump to: navigation, search

Table of Contents >> Application Reference >> DNS Resolver


#include <trsocket.h>


int tfDnsGetSrvHost (
const char TM_FAR * service,
const char TM_FAR * protocol,
const char TM_FAR * domainStr,
struct sockaddr_storage TM_FAR * addrPtr,
ttUser32Bit flags
);


Function Description

This function creates and transmits an SRV query. It then returns the result to the user in the form of a sockaddr_storage structure. A single SRV query may generate multiple results. To retrieve consecutive results, this function may be called again with the same parameters. In particular, the sockaddr_storage structure returned in the previous call must be passed back in, unchanged, to find the next result. Please note that when using this API to retrieve IPv6 addresses, it may be necessary to set a scope ID on the returned sockaddr_storage structure. If this is the case, the scope ID must be reset to its original value before passing the sockaddr_storage structure back in to the function to retrieve the next result.


Parameters

  • service
    Service name (e.g., “http”, “ftp”, “telnet”).
  • protocol
    Protocol for this service (e.g.,“udp”,“tcp”). Two predefined macros have been created for this parameter: TM_DNS_SRV_PROTO_UDP and TM_DNS_SRV_PROTO_TCP. To specify other protocols, pass in the desired string.
  • domainStr
    String containing the ASCII representation of the domain for this query (e.g., “treck.com”).
  • addrPtr
    A pointer to a sockaddr_storage structure. This structure will be filled out with the address and port returned by the server. When retrieving the “next” server response, this structure must be passed back into the function unchanged. To retrieve the first response, this structure must be zero’d out.
  • flags
    Currently used only to specify how to sort the returned addresses, based on address family (IPv4 or IPv6). See below for more details.


Flags

  • TM_DNS_SRV_SORT_FAST
    Return any address available for an SRV host. If both IPv4 and IPv6 addresses are available, IPv4 will be used. Once all available addresses for the host have been returned, move on to the next host. If no addresses are available, IPv4 will be queried first. If no response is received, IPv6 will be queried. If the stack is not in dual stack mode, this option will behave like TM_DNS_SRV_SORT_IP4_ONLY or TM_DNS_SRV_SORT_IP6_ONLY.
  • TM_DNS_SRV_SORT_DUAL_PREF_IP4
    If any IPv4 addresses are available for the host, return them. If not, query for them. Then return any IPv6 address available. If no IPv6 addresses are available, query for them. This option is only available in dual stack mode.
  • TM_DNS_SRV_SORT_DUAL_PREF_IP6
    If any IPv6 addresses are available for the host, return them. If not, query for them. Then return any IPv4 addresses available. If no IPv4 addresses are available, query for them. This option is only available in dual stack mode.
  • TM_DNS_SRV_SORT_IP4_ONLY
    If any IPv4 addresses are available for the host, return them. If not, query for them. This option is unavailable if TM_USE_IPV4 is undefined.
  • TM_DNS_SRV_SORT_IP6_ONLY
    If any IPv6 addresses are available for the host, return them. If not, query for them. This option is unavailable if TM_USE_IPV6 is undefined.


Returns

  • TM_EINVAL
    Invalid parameters.
  • TM_EPROTONOSUPPORT
    Asked for v6 addresses when the stack is configured for v4 only, or vice versa.
  • TM_ENOMEM
    Not enough free memory to complete request.
  • TM_EFILE
    Treck was unable to successfully allocate a socket for the DNS request. This could indicate Treck did not have the resources to allocate another socket. It could also be due to Treck hitting the limit of sockets set by TM_DNS_MAX_SOCKETS_ALLOWED or the tfDnsSetOption() option: TM_DNS_OPTION_MAX_SOCKETS_ALLOWED.
  • TM_DNS_Exxx
    DNS server-specific errors. Please see DNS documentation for more details.


Table of Contents >> Application Reference >> DNS Resolver