problem in getting host ip using gethostbyname() and hstent structure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajank0913
    New Member
    • Aug 2014
    • 1

    problem in getting host ip using gethostbyname() and hstent structure

    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**)mallo c(sizeof(struct hostent));
    write_at("Succe ss",7,1,1);
    SVC_WAIT(2000);
    i = gethostbyname(h ostname,he);
    if (i==0)
    {
    char buff[50]={'\0'};
    clrscr();
    write_at("Succe ss",7,6,4);
    SVC_WAIT(2000);
    //sprintf(buff,"T ype: %d Length: %d", (*he)->h_addrtype,(*h e)->h_length);
    sprintf(buff,"T ype: %s", (*he)->h_addr);
    write_at(buff,s trlen(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
Working...