i am making an application for fetching the IP address from the domain name using the hostent structure i am able to insert all the data in the structure successfully and i am able to fetch the
Host Name:
Type:
Length:
but not able to fetch the IP address in the dotted format using by the below function
int get_ip()
{
int i;
const char *hostname="www.google.co.in";
struct hostent **he;
struct hostent *VAL;
he= (struct hostent**)malloc(sizeof(struct hostent));
write_at("Success",7,1,1);
SVC_WAIT(2000);
i = gethostbyname(hostname,he);
if (i==0)
{
char buff[50]={'\0'};
clrscr();
write_at("Success",7,6,4);
SVC_WAIT(2000);
//sprintf(buff,"Type: %d Length: %d", (*he)->h_addrtype,(*he)->h_length);
sprintf(buff,"Type: %s", (*he)->h_addr);
write_at(buff,strlen(buff),1,2);
SVC_WAIT(3000);
}
else
{
clrscr();
write_at("fail",4,1,1);
SVC_WAIT(2000);
}
return 0;
}
STRUCTURE:
struct hostent
{
char * h_name; /* Official name of host. */
char **h_aliases; /* Alias list. */
int h_addrtype; /* Host 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. */
};
but the output is not the expected. output is not readable.
please help me.
thanks in advance