July 5, 2007
How do you find your own ip address in C programming on a linux machine?
- #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;
} - Type in.. www.whatismyip.com
thats yours - ifconfig
- Ha! Dang I lost now; System > Administration > Network Tools
Dang, if I know what happening, everyone drinking beer and jammin' here! Sorry. - Experience
- Try Panky's method…or if you're short on time just enter "ifconfig" at the console.
Tags: linux for dummy, mandrake linux























