Module: IPAddr::IPAddrExtensions::ClassMethods
- Defined in:
- lib/ruckus/extensions/ipaddr.rb
Instance Method Summary collapse
-
#inet_addr(str) ⇒ Object
construct an IPAddr from a dotted quad string or integer.
-
#lite(str) ⇒ Object
construct an IPAddr from a dotted quad string without incurring a reverse lookup.
-
#mask2mlen(mask) ⇒ Object
——————————————————— Convert 255.255.255.0 to 24.
Instance Method Details
#inet_addr(str) ⇒ Object
construct an IPAddr from a dotted quad string or integer
41 42 43 44 45 46 47 48 49 |
# File 'lib/ruckus/extensions/ipaddr.rb', line 41 def inet_addr(str) if str.kind_of? String IPAddr.lite(str).to_i else i = IPAddr.new(0, Socket::AF_INET) i.set_int(str) return i end end |
#lite(str) ⇒ Object
construct an IPAddr from a dotted quad string without incurring a reverse lookup.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ruckus/extensions/ipaddr.rb', line 68 def lite(str) # XXX self.new(0, Socket::AF_Inet, *args) instead? ip = IPAddr.new(0, Socket::AF_INET) parts = str.split "/" ip.set_int(ip.inet_addr(parts[0])) ip = ip.mask parts[1] if parts[1] return ip end |
#mask2mlen(mask) ⇒ Object
Convert 255.255.255.0 to 24
53 54 55 56 57 58 59 60 61 |
# File 'lib/ruckus/extensions/ipaddr.rb', line 53 def mask2mlen(mask) len = 0 while len < 32 && mask & 0x80000000 != 0 mask <<= 1 mask &= 0xFFFFFFFF len += 1 end return len end |