- May
- 13,211
- 180
Using @IPNAME on my internet address ...
That's a meaningless and useless (doesn't work with Winsock functions) combination of my computer's "given" name and LocalAreaConnection2's "Primary and connection-specific DNS suffixes".
Once upon a time (pre-W2K?), gethostbyaddr() (and related functions) would cause a DNS lookup and give the actual internet name of my computer, but no longer. According to a seemingly knowledgeable gent in microsoft.public.win32.programmer.network the computer's public address is considered local and you cannot get gethostbyaddr(), WSAAsyncGetHostByAddr(), or getnameinfo() to do a real lookup. All three functions give the same bogus name.
Recommend, for W2K and later:
I have more robust code that does GetBestInterface() and creates a list of DNS servers to give DnsQuery() (instead of NULL) but, at least on XP, that seems to be DnsQuery()'s default behavior.
To be continued.
Code:
v:\> echo %_ip
72.230.122.241 192.168.1.3 169.254.1.2
v:\> echo %@ipname[72.230.122.241]
ZZ.twcny.rr.com
Once upon a time (pre-W2K?), gethostbyaddr() (and related functions) would cause a DNS lookup and give the actual internet name of my computer, but no longer. According to a seemingly knowledgeable gent in microsoft.public.win32.programmer.network the computer's public address is considered local and you cannot get gethostbyaddr(), WSAAsyncGetHostByAddr(), or getnameinfo() to do a real lookup. All three functions give the same bogus name.
Recommend, for W2K and later:
Code:
#define IsRoutable(X,Y) \
(!(X==10 || (X==192 && Y==168) || (X==172 && (Y&240)==16) || (X==169 && Y==254) ))
/* do the lookup for routable IP */
CHAR szNameBuf[32];
/* address in already in network order */
/* backwards, e.g., jpsoft: "219.19.242.66.in-addr.arpa"
wsprintf(szNameBuf, "%s.in-addr.arpa", inet_ntoa(address));
PDNS_RECORD pDnsRecord;
DNS_STATUS dnsResult = DnsQuery(szNameBuf, DNS_TYPE_PTR,
DNS_QUERY_BYPASS_CACHE
| DNS_QUERY_NO_HOSTS_FILE
| DNS_QUERY_NO_LOCAL_NAME
| DNS_QUERY_NO_NETBT
| DNS_QUERY_WIRE_ONLY,
NULL,
&pDnsRecord, NULL);
if ( dnsResult == NO_ERROR )
{
wsprintf(szName, "%s", pDnsRecord->Data.PTR.pNameHost);
DnsRecordListFree(pDnsRecord, DnsFreeRecordListDeep);
}
I have more robust code that does GetBestInterface() and creates a list of DNS servers to give DnsQuery() (instead of NULL) but, at least on XP, that seems to be DnsQuery()'s default behavior.
To be continued.