Issue #6479 has been updated by knu (Akinori MUSHA).

Status changed from Open to Assigned
Assignee set to knu (Akinori MUSHA)


----------------------------------------
Bug #6479: ipaddr.rb???????篁?????????後???????????????????????若????????c??違???
https://bugs.ruby-lang.org/issues/6479#change-26781

Author: kachick (Kenichi Kamiya)
Status: Assigned
Priority: Normal
Assignee: knu (Akinori MUSHA)
Category: lib
Target version: 1.9.3
ruby -v: ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux]


# ??倶??

罔?羣?羞私?????ゃ??????? ipaddr.rb ???若????????≪?????号?後??????с????????絅?????????????????????????若????????c??違?????????????????障????????
IPv4??ф???????ゃ?????????????с????????罨<??2??鴻??Windows?????絽????紊?????????????Linux??????後???????c???(????????c??)??喝???????c????ゃ??菴??????障?????

* 0??????????????????翫??
* ??壕?????絖?????????????翫??

???篏?箴????莠??????障?????

## ??演??

    require 'ipaddr'

    p IPAddr.new("11.22.33.45") #=> #<IPAddr: IPv4:11.22.33.45/255.255.255.255>


## Windows(7) / ruby 1.9.3p194 (2012-04-20) [i386-mingw32]

    # 篁ヤ??????с????????箴?紊????????????障?????
    p IPAddr.new("011.22.33.45")
    p IPAddr.new("011.0022.00033.000045")
    p IPAddr.new("011.0022.00033.000045\n")
    p IPAddr.new("011.0022.00033.000045\nfoo32/0024/bar \n/foobar  ")
    p IPAddr.new("011.0022.00033.000045\n056.0067.00078.00089\nfoo32/0024/bar \n/foobar  ")
    
    # 箴?紊?
    ArgumentError: invalid address
    from C:/Ruby193/lib/ruby/1.9.1/ipaddr.rb:496:in `rescue in initialize'

## Linux(Mint12) / ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux]

    # Windows???????????綣???違?絲???????筝???ゃ??箴?紊????????????障?????
    p IPAddr.new("011.22.33.45")                                                            #=> #<IPAddr: IPv4:11.22.33.45/255.255.255.255>
    p IPAddr.new("011.0022.00033.000045")                                                   #=> #<IPAddr: IPv4:11.22.33.45/255.255.255.255>
    p IPAddr.new("011.0022.00033.000045\n")                                                 #=> #<IPAddr: IPv4:11.22.33.45/255.255.255.255>
    p IPAddr.new("011.0022.00033.000045\nfoo32/0024/bar \n/foobar  ")                       #=> #<IPAddr: IPv4:11.22.33.0/255.255.255.0>
    p IPAddr.new("011.0022.00033.000045\n056.0067.00078.00089\nfoo32/0024/bar \n/foobar  ") #=> #<IPAddr: IPv4:45.67.78.0/255.255.255.0>

# 絽????

Windows??医??筝????????帥???????????筝?荐?????????帥?若?潟?т??紊?????????????????????鴻?????吟????????障????????
??鴻??Linux筝???с??0?????????≪???????罅???違??狗?????荀?????????<????鴻???IPSocket.getaddress(8??我???)?????????ゃ??違??c?????障????鴻??羂????????障?????

## Linux(Mint12) / ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux]

    require 'socket'
    
    p IPSocket.getaddress("011.0022.00033.000045") #=> "9.18.27.37"
    

# ??????

ipaddr.rb?????????????茯?????с?帥???????????罨<???膣???莎????????????с??????????????????????ゃ?????帥?障??????????祉?祉?紫∈篆<????????障????????

* ????????????????с?????罩hΘ??<?炊??絖???? \A\z ???篏帥??????? \A\Z ??? ^$ ??ф??c????????????
* #initialize ??с?? IPSocket.getaddress ???箴?紊????菴??????????????????罩e幻??医幻???ゆ???紊с???????????????????
* #in_addr ??с??1??ゃ?????????????? \d+ ???帥?с??c???????c???????????????

????????????????#in_addr???帥??罨<????????????吾??????????????Windows????罕?????篏?????????????障?с?腆肴???с????障????????

    require 'ipaddr'

    class IPAddr

      private

      remove_method :in_addr

      def in_addr(addr)
        if addr =~ /\A(?:(?:0|[1-9]\d{0,2})\.){3}(?:0|[1-9]\d{0,2})\z/  
          return addr.split('.').inject(0) { |i, s|
            n = s.to_i
            raise ArgumentError, 'invalid address' unless n <= 255

            i << 8 | n
          }
        end
        return nil
      end

    end


-- 
http://bugs.ruby-lang.org/