Class: IPAddr

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#mask_addrObject (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_maskInteger

Converts network mask to CIDR format.

Returns:

  • (Integer)

    CIDR representation of address mask


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:

Returns:


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:

Returns:


35
36
37
# File 'lib/occi/monkey_island/ipaddr.rb', line 35

def network?
  !host?
end