Brian Candler wrote: <snip> > Hmm, that doesn't do any decimal conversion, just byte ordering. Are you > thinking of the C functions inet_aton and inet_ntoa which convert between > strings and struct in_addr? > Actually, I think I was...lol :) > In Ruby, the socket functions take the string representation directly, so > it's not normally necessary to convert: e.g. > > require 'socket' > t = TCPSocket.new('127.0.0.1', 23) # connect to my telnet port > > If you really want it as a 4-byte integer then you can convert easily, but > beware that IP addrs are likely to be represented as Bignum rather than > Fixnum because the size of Fixnum is 31 bits: > I expected Bignum, so at least I was prepared in this aspect. > class Socket > def Socket.aton(a) > res = 0 > a.split(/./).each { |byte| res<<=8; res|=byte.to_i } > res > end > end > > ip = '206.27.238.1' > puts Socket.aton(ip) #>> 3457936897 > printf "%08Xn", Socket.aton(ip) #>> CE1BEE01 > > Is that what you were looking for? > That was EXACTLY what I was looking for. You have my gratitude. Thank you, --ghost--