Class: Socket

Inherits:
Object
  • Object
show all
Defined in:
lib/tagen/socket.rb

Class Method Summary collapse

Class Method Details

.addr(str) ⇒ String

pack human-readable address to Socket address

Examples:


addr("192.168.1.1") #=> "\xC0\xA8\x01\x01"

Returns:

  • (String)

    address used by Socket

See Also:



71
72
73
# File 'lib/tagen/socket.rb', line 71

def addr(str) 
  str.split(".").map{|v|v.to_i}.pack("CCCC") 
end

.unaddr(str) ⇒ String

unpack to humna-readable address from Socket address

Examples:


unaddr("\xC0\xA8\x01\x01") #=> "192.168.1.1"

Returns:

  • (String)

    human readable address



82
83
84
# File 'lib/tagen/socket.rb', line 82

def unaddr(str)
  str.unpack("CCCC").join(".") 
end