July 5, 2007

How do you find your own ip address in C programming on a linux machine?

  1. #include <stdio.h>
    #include <netdb.h>

    int main()
    {
    char hostn[400]; //placeholder for the hostname
    struct hostent *hostIP; //placeholder for the IP address

    //if the gethostname returns a name then the program will get the ip
    address using gethostbyname
    if((gethostname(hostn, sizeof(hostn))) == 0)
    {
    hostIP = gethostbyname(hostn); //the netdb.h function gethostbyname
    printf("IP address: %s\n", inet_ntoa(*(struct in_addr
    *)hostIP->h_addr));
    }
    else
    {
    printf("ERROR:FC4539 - IP Address not found."); //error if the
    hostname is not found
    }
    return 0;
    }

  2. Type in.. www.whatismyip.com
    thats yours
  3. ifconfig
  4. Ha! Dang I lost now; System > Administration > Network Tools
    Dang, if I know what happening, everyone drinking beer and jammin' here! Sorry.
  5. Experience
  6. Try Panky's method…or if you're short on time just enter "ifconfig" at the console.

Tags: ,

Tell a Friend Today!

del.icio.us Digg Furl Reddit Ask BlinkList blogmarks Blogg-Buzz Google Ma.gnolia Netscape ppnow Rojo Shadows Simpy Socializer Spurl StumbleUpon Tailrank Technorati Windows Live Wists Yahoo! Help

Permalink • Print

Track this entry

RSS BlogPulse

RSS Technorati Cosmos

Related Searches

, , , ,