IPSocket.getaddress giving unexpected IP address

Hi,

In the below code :

[email protected]:~> irb
2.0.0-p451 :001 > require ‘socket’
=> true
2.0.0-p451 :002 > IPSocket.getaddress(“localhost”)
=> “::1”
2.0.0-p451 :003 >

Why am I getting “::1” instead of “127.0.0.1” ? Took the example from
the doc

On Mon, May 12, 2014 at 4:18 PM, Arup R.
[email protected] wrote:

Why am I getting “::1” instead of “127.0.0.1” ? Took the example from the doc

localhost is the host name used to communicate via network services to
your own computer, through the loopback interface. Its IP is defined
in your OS hosts file (/etc/hosts). For example, an extract of mine:

$ cat /etc/hosts
127.0.0.1 localhost

The following lines are desirable for IPv6 capable hosts

::1 ip6-localhost ip6-loopback

2.0.0-p195 :001 > require ‘socket’
=> true
2.0.0-p195 :002 > IPSocket.getaddress(“localhost”)
=> “127.0.0.1”
2.0.0-p195 :003 > IPSocket.getaddress(“ip6-localhost”)
=> “::1”

Jesus.

On Monday, May 12, 2014 05:49:11 PM Jess Gabriel y Galn wrote:

2.0.0-p195 :003 > IPSocket.getaddress(“ip6-localhost”)
=> “::1”

Here is mine, which is a bit odd :

[email protected]:~> cat /etc/hosts

hosts This file describes a number of hostname-to-address

mappings for the TCP/IP subsystem. It is mostly

used at boot time, when no name servers are running.

On small systems, this file can be used instead of a

“named” name server.

Syntax:

IP-Address Full-Qualified-Hostname Short-Hostname

127.0.0.1 localhost

special IPv6 addresses

::1 localhost ipv6-localhost ipv6-loopback

[email protected]:~> irb
2.0.0-p451 :001 > require ‘socket’
=> true
2.0.0-p451 :002 > IPSocket.getaddress(“localhost”)
=> “::1”
2.0.0-p451 :003 > IPSocket.getaddress(“ip6-localhost”)
=> “67.215.65.132”
2.0.0-p451 :004 >

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs