Host File
On your local PC the DNS mapping entries are found in the host file. On Windows NT,
2K, XP the file “hosts” is located at:
%WINDOWS%\system32\drivers\etc\
The host files (shown in blue) contains a space separated IP address and hostname. All
this info ends up in the router table, where network traffic control occurs.
127.0.0.1 localhost
192.168.1.106 freedom.home.com
192.168.1.105 download.bigdaddy.com
192.168.1.100 sal.home.com
loopback
Note: the loopback address of “127.0.0.1” also known as “localhost” is the IP address
used when communicating with other process running on the same PC. This is how we
will test our client and server application, they will run on the same “local” host PC.
IP from hostname
The gethostbyname function retrieves host information corresponding to a host name
from a host database.
struct hostent* FAR gethostbyname(
const char* name
);
hostname from IP
The gethostbyaddr function retrieves the host information corresponding to a network
address.
struct HOSTENT* FAR gethostbyaddr(
const char* addr,
int len,
int type
);
hostent structure
[msdn] The hostent structure is used by functions to store information about a given host,
such as host name, IP address. An application should never attempt to modify this
structure or to free any of its components.
Furthermore, only one copy of the hostent structure is allocated per thread, and an
application should therefore copy any information that it needs before issuing any
other Windows Sockets API calls.
typedef struct hostent {
char FAR* h_name;
char FAR FAR** h_aliases;
short h_addrtype;
short h_length;
char FAR FAR** h_addr_list;
} hostent;
Rajinder Yadav Copyright © 2007 www.devmentor.org
No comments:
Post a Comment