Class: IPAddr
- Inherits:
-
Object
- Object
- IPAddr
- Defined in:
- lib/occi/monkey_island/ipaddr.rb
Overview
:nodoc:
Constant Summary collapse
- AF_INET_FULL_MASK =
32
- AF_INET6_FULL_MASK =
128
Instance Attribute Summary collapse
-
#mask_addr ⇒ Object
readonly
Returns the value of attribute mask_addr.
Instance Method Summary collapse
-
#cidr_mask ⇒ Integer
Converts network mask to CIDR format.
-
#host? ⇒ Boolean
:nodoc:.
-
#network? ⇒ Boolean
:nodoc:.
Instance Attribute Details
#mask_addr ⇒ Object (readonly)
Returns the value of attribute mask_addr.
6 7 8 |
# File 'lib/occi/monkey_island/ipaddr.rb', line 6 def mask_addr @mask_addr end |
Instance Method Details
#cidr_mask ⇒ Integer
Converts network mask to CIDR format.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/occi/monkey_island/ipaddr.rb', line 11 def cidr_mask case family when Socket::AF_INET AF_INET_FULL_MASK - Math.log2((1 << AF_INET_FULL_MASK) - mask_addr).to_i when Socket::AF_INET6 AF_INET6_FULL_MASK - Math.log2((1 << AF_INET6_FULL_MASK) - mask_addr).to_i else raise AddressFamilyError, 'unsupported address family' end end |
#host? ⇒ Boolean
:nodoc:
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/occi/monkey_island/ipaddr.rb', line 23 def host? case family when Socket::AF_INET cidr_mask == AF_INET_FULL_MASK when Socket::AF_INET6 cidr_mask == AF_INET6_FULL_MASK else raise AddressFamilyError, 'unsupported address family' end end |
#network? ⇒ Boolean
:nodoc:
35 36 37 |
# File 'lib/occi/monkey_island/ipaddr.rb', line 35 def network? !host? end |