How to finding a Machine Address?

Answer

Finding an address that can be used to connect to a remote machine is done with either of the following commands:

#include <netdb.h>

struct hostent *gethostbyname(char *name)

struct hostent *gethostbyaddr(char *addr,
int len, int type)

name contains the host name for which the IP address is needed. addr points to a structure of type in_addr and len is the size in bytes of this structure. In this discussion type is always AF_INET since the discussion is limited to use of IP addresses on the Internet.
Both calls return a pointer to a host entry structure.

This structure has the following form:

struct hostent {
char *h_name; /*official name of host*/
char **h_aliases; /* alias list */
int h_addrtype; /* address type */
int h_length; /* length of address */
char **h_addr_list;
/* list of addresses from name server */
#define h_addr h_addr_list[0]
/* address for backward compatibility */
}; 

All sockets Questions

Ask your interview questions on sockets

Write Your comment or Questions if you want the answers on sockets from sockets Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---