linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Glynn Clements <glynn@gclements.plus.com>
To: HIToC <hitoc_mail@yahoo.it>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: Host IP address
Date: Wed, 23 Feb 2005 00:26:08 +0000	[thread overview]
Message-ID: <16923.52640.306669.975526@gargle.gargle.HOWL> (raw)
In-Reply-To: <200502221751.44585.hitoc_mail@yahoo.it>


HIToC wrote:

> Sometimes is useful to know the IP address of the machine we are working on,
> for example when we connect a SMTP server and do the EHLO <domain> command.
> I have written a short C++ program that first prints the host name and the
> host IP address, then if arguments from command line are passed prints
> the IP address of each domain name.

> My intent is to know my real IP address!

A system may have any number of IP addresses, including zero. You
can't assume that there is exactly one IP address.

Also, the results obtained from gethostname() and gethostbyname()
aren't necessarily correct. That just tells you what your hostname
resolves to using whatever name resolution method(s) your system is
configured to use (e.g. /etc/hosts, DNS, NIS etc).

If you want to determine the IP addresses of any local interfaces,
first obtain a list of interfaces by either calling ioctl(SIOCGIFCONF)
or parsing /proc/net/dev. Then call ioctl(SIOCGIFADDR) for each
interface to obtain its address. See the source code for "ifconfig"
(from the net-tools package) for more details.

-- 
Glynn Clements <glynn@gclements.plus.com>

      reply	other threads:[~2005-02-23  0:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-22 16:53 Host IP address HIToC
2005-02-23  0:26 ` Glynn Clements [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=16923.52640.306669.975526@gargle.gargle.HOWL \
    --to=glynn@gclements.plus.com \
    --cc=hitoc_mail@yahoo.it \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).