ip.c
author Kevin Geiss <kevin.geiss@ticketmaster.com>
Wed Jul 08 16:15:32 2009 -0700 (14 months ago)
changeset 3 2d46f991dab7
permissions -rw-r--r--
add short version
     1 #include <stdio.h>
     2 #include <arpa/inet.h>
     3 #include <netinet/in.h>
     4 #include <unistd.h>
     5 #include <netdb.h>
     6 
     7 int main()
     8 {
     9    char name[80]; /*store my hostname*/
    10    struct hostent *hostent_ptr;
    11    int ret = gethostname( name, 80 );
    12    if ( ret < 0 )
    13    {
    14       printf("gethostname failed\n");
    15    }
    16    else
    17    {
    18          hostent_ptr = gethostbyname(name);
    19          if ( hostent_ptr == NULL )
    20          {
    21             printf("hostent_ptr is null\n");
    22          }
    23          else
    24          {
    25             struct in_addr internet_address;
    26             internet_address.s_addr = ((struct in_addr *)hostent_ptr->h_addr_list[0])->s_addr;
    27             printf("%s\n",  inet_ntoa(internet_address) );
    28          }
    29    }
    30    return 0;
    31 }