Connecting Tech Pros Worldwide Help | Site Map

Find ip on my local machine

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 15th, 2005, 03:30 AM
Rusty
Guest
 
Posts: n/a
Default Find ip on my local machine

I am trying to find the ip of my machine, but all I get is the local
ip, not the ip I want. This is a program that finds the local ip, what
should be modified:

#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;
}

Rusty
Norway


  #2  
Old November 15th, 2005, 03:31 AM
Michael Wojcik
Guest
 
Posts: n/a
Default Re: Find ip on my local machine


In article <1129811224.247993.238380@g47g2000cwa.googlegroups .com>, "Rusty" <andersrustad@yahoo.no> writes:[color=blue]
> I am trying to find the ip of my machine, but all I get is the local
> ip, not the ip I want.[/color]

Off-topic for comp.lang.c, where we discuss the standard C language,
which knows nothing of IP addresses or anything else about networking.

I recommend you try a group specific to your platform. If you're
working on a Unix system, for example, try comp.unix.programmer.

--
Michael Wojcik michael.wojcik@microfocus.com

Please enjoy the stereo action fully that will surprise you. -- Pizzicato Five
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.