Name Resolution

Name Resolution

As you saw in Chapter 1, Winsock provides a convenient function, gethostbyname, which allows you to resolve a hostname to an IPv4 address using name resolution techniques in Windows such as DNS. The .NET Application Frameworks version 1 provides the System.Net.DNS class to support domain name resolution functionality for IPv4 addresses. Table 13-4 describes the available methods in this class.

Table 13-4 Available Methods for the System.Net.DNS Class

Method

Winsock Equivalent

GetHostByAddress

gethostbyaddr

GetHostByName, BeginGetHostByName, EndGetHostByName

gethostbyname

GetHostName

gethostname

Resolve, BeginResolve, EndResolve

gethostbyname

The System.Net.DNS class relies on the System.Net.IPHostEntry class to store IPv4 addresses that a DNS query returns. The DNS.GetHostByName method will return a list of host IPv4 addresses to an IPHostEntry container. This method can take a string representing both a name and even an IPv4 address in dot notation. The following code fragment demonstrates how to use DNS to resolve IPv4 addresses. It also demonstrates how you can set up an IPEndpoint to name a socket from the information we have described so far.

// Resolve a host name to an IPv4 address System.Net.IPHostEntry IPHost =      System.Net.Dns.GetHostByName("www.Microsoft.com"); // Set up an IPEndPoint using the first address in our IPHostEntry list System.Net.IPEndPoint ServerEndPoint = new      System.Net.IPEndPoint(IPHost.AddressList[0], Port);

note

IPv6 DNS name resolution is not available in the .NET Frameworks version 1. Therefore, it is not yet possible to develop agnostic C# socket applications (as described in Chapter 3) to transparently handle both IPv4 and IPv6 name resolution. IPv6 DNS name resolution is expected in the next version of the Frameworks.



Network Programming for Microsoft Windows
Network Programming for Microsoft Windows (Microsoft Professional Series)
ISBN: 0735605602
EAN: 2147483647
Year: 2001
Pages: 172
Authors: Anthony Jones

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net