2009/12/17 Nicolas Vincent <n.galineau / gmail.com>:
> Hello to forum members,
>
> Here's my issue : I have IPs stored in a database but those are "little
> endian byte order" encoded and the field type of the BDD is BigInt
> (similar to Ruby's BigNum).
>
> How could I get back my human readable IP ? I've been digging around
> 'unpack' for a while now but without success.
>
> Here's an example :
> BigNum stored in the database : 3232235797
> Resulting IP : 192.168.1.21
>
> Could you give me some ideas or code ? I'm really stucked !

Do you mean like this:

irb(main):020:0> i
=> 3232235797
irb(main):021:0> ([i].pack("N")).unpack("C*")
=> [192, 168, 1, 21]
irb(main):022:0> ([i].pack("N")).unpack("C*").join(".")
=> "192.168.1.21"
irb(main):023:0>

Cheers

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/