C
Cyril Mougel
Hi,
I ask me a question since few day and I don't understand why this code
doesn't run :
require 'ipaddr'
IPAddr.new '2002:0000:1234:4561'
In fact this code raise an Exception :
/usr/lib64/ruby/1.8/ipaddr.rb:422:in `initialize': invalid address
(ArgumentError)
But this adress is syntactically valid like an Ipv6. My search lead me
to this conclusion :
IPAddr think my IP like an invalid adress because it hadn't a name
resolution. The line who raise the exception is :
IPSocket.getaddress(prefix)
For me, the prefix is '2002:0000:1234:4561', because it's never modify
before in intialize of IPAddr (Verify with the debuggeur). The command
follow prouve it :
hello% host 2002:0000:1234:4561
Host 2002:0000:1234:4561 not found: 3(NXDOMAIN)
or with irb :
hello% irb
irb(main):001:0> require 'socket'
=> true
irb(main):002:0> IPSocket.getaddress('2002:0000:1234:4561')
SocketError: getaddrinfo: Name or service not known
from (irb):2:in `getaddress'
from (irb):2
But , it's not specify anywhere that an IPAddr must be "valid" for be
use. Likewise, if we see the code of this file ipaddr.rb, We remark
that in first step, there are :
unless Socket.const_defined? "AF_INET6"
But if you have compile Ruby with Ipv6 support like some binary linux
distribution, this variable is define. So the
override of the method getaddress made after this unless is never
execute. In this new method, we can see that :
return true if /\A[\dA-Fa-f]{1,4}[\dA-Fa-f]{1,4})*\Z/ =~ addr
With this my Ipv6 is valid.
The question that I ask me is the follow :
It's a bug or not ?
thank for your answer
I ask me a question since few day and I don't understand why this code
doesn't run :
require 'ipaddr'
IPAddr.new '2002:0000:1234:4561'
In fact this code raise an Exception :
/usr/lib64/ruby/1.8/ipaddr.rb:422:in `initialize': invalid address
(ArgumentError)
But this adress is syntactically valid like an Ipv6. My search lead me
to this conclusion :
IPAddr think my IP like an invalid adress because it hadn't a name
resolution. The line who raise the exception is :
IPSocket.getaddress(prefix)
For me, the prefix is '2002:0000:1234:4561', because it's never modify
before in intialize of IPAddr (Verify with the debuggeur). The command
follow prouve it :
hello% host 2002:0000:1234:4561
Host 2002:0000:1234:4561 not found: 3(NXDOMAIN)
or with irb :
hello% irb
irb(main):001:0> require 'socket'
=> true
irb(main):002:0> IPSocket.getaddress('2002:0000:1234:4561')
SocketError: getaddrinfo: Name or service not known
from (irb):2:in `getaddress'
from (irb):2
But , it's not specify anywhere that an IPAddr must be "valid" for be
use. Likewise, if we see the code of this file ipaddr.rb, We remark
that in first step, there are :
unless Socket.const_defined? "AF_INET6"
But if you have compile Ruby with Ipv6 support like some binary linux
distribution, this variable is define. So the
override of the method getaddress made after this unless is never
execute. In this new method, we can see that :
return true if /\A[\dA-Fa-f]{1,4}[\dA-Fa-f]{1,4})*\Z/ =~ addr
With this my Ipv6 is valid.
The question that I ask me is the follow :
It's a bug or not ?
thank for your answer