delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/05/11/21:47:37

From: dbe AT wgn DOT net ($Bill Luebkert)
Subject: Re: Finding Out My Own IP-Address
11 May 1998 21:47:37 -0700 :
Message-ID: <3557753B.A75B9179.cygnus.gnu-win32@wgn.net>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 980511085238 DOT 22871C-100000 AT terra>
Mime-Version: 1.0
To: gnu-win32 AT cygnus DOT com

Ron G. Minnich wrote:
> 
> On Wed, 6 May 1998, $Bill Luebkert wrote:
> > > When I dial in to my provider via NT-RAS, I'm assigned a dynamic IP address -
> > > which is what I'm trying to find out.
> > $name = (gethostbyname ("localhost"))[0];
> > $addr = (gethostbyname ($name))[4];
> OK, I believe this works. But why doesn't
> gethostname
> followed by a gethostbyname? no gethostname entry?

Well, first I am also in the Perl mailing list and didn't realize 
that the question was a GNU question and the same question appears 
a lot on the Perl list so I answered it in Perl.  Perl doesn't 
have gethostname function.

> 
> Also why the [4]?

gethostbyname returns several vrbls and I wanted the 
fourth one (which is the IP address).  Since using it in a scalar 
context returns the fourth one anyway; you may leave it off.

You can do this in C with the method mentioned by someone earlier:

gethostbyname
socket 
bind
connect to a well-known port (I tried 80 - my web server - and it worked)
getsockname

-- 
  ,-/-  __      _  _         $Bill Luebkert
 (_/   /  )    // //       DBE Collectibles
  / ) /--<  o // //      http://www.wgn.net/~dbe/
-/-' /___/_<_</_</_    Mailto:dbe AT wgn DOT net
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019