From: Miloserdin Oleg on
I'm interesting how to get IP address from C application. I've used
gethostname() and gethostbyname() in my application. I've edited /etc/hosts
file to add my hostname and IP address. My PC is connected to server
which using DHCP. If I remove added lines from /etc/hosts gethostbyname()
function returns error.
How can I get IP address from my application without using /etc/hosts
editing?

--
Best regards,
Miloserdin Oleg

=============================================
MicroLAB Systems
address: 83 Dubninskaya street, #612, 127591 Moscow, Russia
phone/fax: +7-(499)-900-6208
e-mail: oleg.miloserdin(a)mlabsys.com WEB: http://www.mlabsys.com
=============================================


From: Rick Jones on
Miloserdin Oleg <oleg.miloserdin(a)mlabsys.com> wrote:
> I'm interesting how to get IP address from C application. I've used
> gethostname() and gethostbyname() in my application. I've edited
> /etc/hosts file to add my hostname and IP address. My PC is
> connected to server which using DHCP. If I remove added lines from
> /etc/hosts gethostbyname() function returns error.
> How can I get IP address from my application without using /etc/hosts
> editing?

Which IP address do you want? The IP address of a remote system so
you can connect to it? The IP address of the local system? If the IP
address of the local system, are you satisfied with just one of the
possibly many IP addresses being used by the local system?

rick jones
--
oxymoron n, commuter in a gas-guzzling luxury SUV with an American flag
these opinions are mine, all mine; HP might not want them anyway... :)
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...
From: William Ahern on
Miloserdin Oleg <oleg.miloserdin(a)mlabsys.com> wrote:
> I'm interesting how to get IP address from C application. I've used
> gethostname() and gethostbyname() in my application. I've edited /etc/hosts
> file to add my hostname and IP address. My PC is connected to server
> which using DHCP. If I remove added lines from /etc/hosts gethostbyname()
> function returns error.
> How can I get IP address from my application without using /etc/hosts
> editing?

There's usually not a single IP address on a system.

The portable way to get a local IP address is to first connect a socket to
an interesting peer, and then use getsockname(2). This way you don't have to
mess with any non-portable interfaces, and the kernel would have already
chosen the appropriate local IP address according to its routing policy.

There's a common alternative, non-portable but widely supported, to
enumerate all local addresses. See getifaddrs(2).

From: David Schwartz on
On May 21, 10:32 am, "Miloserdin Oleg" <oleg.miloser...(a)mlabsys.com>
wrote:

> How can I get IP address from my application without using /etc/hosts
> editing?

It's always 127.0.0.1. If that's not the answer you want, you're not
asking the right question.

DS
From: Kenny McCormack on
In article <8bef2c4c-87eb-4d70-a774-0da9a6246a99(a)e34g2000pra.googlegroups.com>,
David Schwartz <davids(a)webmaster.com> wrote:
>On May 21, 10:32�am, "Miloserdin Oleg" <oleg.miloser...(a)mlabsys.com>
>wrote:
>
>> How can I get IP address from my application without using /etc/hosts
>> editing?
>
>It's always 127.0.0.1. If that's not the answer you want, you're not
>asking the right question.
>
>DS

Isn't it actually, 127.0.0.anything?

(It might be 127.0.anything.anything; I can't remember at the moment...)

--
> No, I haven't, that's why I'm asking questions. If you won't help me,
> why don't you just go find your lost manhood elsewhere.

CLC in a nutshell.