getnameinfo
Table of Contents >> Application Reference >> DNS Resolver
| #include <trsocket.h> |
| int getnameinfo | ( |
| const struct sockaddr * addressPtr, | |
| int addressLength, | |
| char * hostname, | |
| int hostnameLength, | |
| char * serviceName, | |
| int serviceNameLength, | |
| int flags | |
| ); |
Function Description
Translates an address into itâs corresponding nodename (hostname). Similar to tfDnsGetHostByAddr(). Retrieving a service name or port number is not supported in our implementation of getnameinfo(), so serviceName must be set to NULL.
Non-blocking Mode
Like all of the other DNS functions, getnameinfo can be used in non-blocking mode by specifying TM_BLOCKING_OFF when tfDnsInit() is called. In non-blocking mode, getnameinfo may return TM_EWOULDBLOCK. This indicates that the operation is in progress. Continue to call getnameinfo() until a value other than TM_EWOULDBLOCK is returned, which indicates that the operation is complete. For example code using getnameinfo(), please see the examples/txdns.c file.
Parameters
- addressPtr
- Pointer to address to translate.
- addressLength
- Length of address structure.
- hostname
- Buffer to copy nodename into on completion.
- hostnameLength
- Size of hostname buffer.
- serviceName
- Not used.
- serviceNameLength
- Not used.
- flags
- NI_NUMERICHOST
Returns
- TM_ENOERROR
- Hostname info retrieved successfully.
- TM_ETIMEDOUT
- DNS request failed â requests to DNS server timed out.
- TM_EHOSTUNREACH
- No route to DNS server.
- TM_EWOULDBLOCK
- Indicates that an operation is currently in progress and has not yet completed. Only returned in non-blocking mode. (see above)
- EAI_NONAME
- NI_NUMERICHOST flag was set, but couldnât convert binary address into string.
- EAI_FAMILY
- Unrecognized or unsupported address family.
- EAI_MEMORY
- Memory allocation failure
- EAI_FAIL
- Non-recoverable error occurred.
- EAI_NONAME
- No entry found for this address.
- TM_DNS_EFORMAT
- Error from DNS server: Format error. The name server was unable to interpret the query.
- TM_DNS_ESERVER
- Error from DNS server: Server failure. The name server was unable to process this query due to a problem with the name server.
- TM_DNS_ENAME_ERROR
- Error from DNS server: Name error. Meaningful only for responses from an authoritative name server, this code signifies that the domain name referenced in the query does not exist.
- TM_DNS_ENOT_IMPLEM
- Error from DNS server: Not implemented. The name server does not support the requested kind of query.
- TM_DNS_EREFUSED
- Error from DNS server: Refused. The name server refuses to perform the specified operation for policy reasons. For example, a name server may not wish to provide the information to the particular requester, or a name server may not wish to perform a particular operation (e.g., zone transfer) for particular data.
- TM_DNS_EANSWER
- No answer received from name server (i.e., response packet received, but it did not contain the answer to our query).
- 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.