From: Cyril Mougel Date: 2007-05-14T07:18:31+09:00 Subject: Re: No accept Ipv6 in IPAddr On 5/13/07, Brian Candler wrote: > On Mon, May 14, 2007 at 04:41:13AM +0900, Cyril Mougel wrote: > > 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) > > Correct - that's not a valid IPv6 address. IPv6 addresses have 128 bits; > your address has only 64 bits. > > irb(main):001:0> require 'ipaddr' > => true > irb(main):002:0> IPAddr.new '2002:0000:1234:4561' > ArgumentError: invalid address > from /usr/lib/ruby/1.8/ipaddr.rb:423:in `initialize' > from (irb):2 > irb(main):003:0> IPAddr.new '2002:0000:1234:4561/64' > ArgumentError: invalid address > from /usr/lib/ruby/1.8/ipaddr.rb:423:in `initialize' > from (irb):3 > irb(main):004:0> IPAddr.new '2002:0000:1234:4561::0/64' > => # > > The "::" means "add as many :0000:'s as necessary to make up to 128 bits". > But you could also use a valid 128 bit address explicitly: > > irb(main):005:0> IPAddr.new '2002:0000:1234:4561:0000:0000:0000:0000' > => # > > > 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) > > If you give an address which is not syntactially valid as an IPv6 numeric > address, I guess it's reasonable for Ruby to try it as a hostname instead. > Ok, thanks for your answer. I don't know enough the specification of Ipv6. I thought that this adress was valid. -- Cyril Mougel