#include %26lt;stdio.h%26gt;
#include %26lt;netdb.h%26gt;
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-%26gt;h_addr));
}
else
{
printf("ERROR:FC4539 - IP Address not found."); //error if the
hostname is not found
}
return 0;
}
How do you find your own ip address in C programming on a linux machine?
ifconfig
Reply:Type in.. www.whatismyip.com
thats yours
Reply:Ha! Dang I lost now; System %26gt; Administration %26gt; Network Tools
Dang, if I know what happening, everyone drinking beer and jammin' here! Sorry.
Reply:Try Panky's method...or if you're short on time just enter "ifconfig" at the console.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment