Class: NetAddr::CIDR

Inherits:
Object
  • Object
show all
Defined in:
lib/ipaccess/patches/netaddr.rb

Overview

This class contains methods extending original CIDR class.

Instance Method Summary collapse

Instance Method Details

#ipv4_compat?Boolean

Returns true if an IP address is IPv4-compatible IPv6 address.

Returns:

  • (Boolean)


45
46
47
48
49
50
# File 'lib/ipaccess/patches/netaddr.rb', line 45

def ipv4_compat?
  return false if @version != 6
  return false if (@ip >> 32) != 0
  a = (@ip & 0xffffffff)
  return (a != 0 && a != 1)
end

#ipv4_compliant?Boolean

Returns true if an IP address is IPv4-compatible or IPv4-mapped IPv6 address.

Returns:

  • (Boolean)


55
56
57
58
59
60
61
# File 'lib/ipaccess/patches/netaddr.rb', line 55

def ipv4_compliant?
  return false if @version != 6
  a = (@ip >> 32)
  return (a == 0xffff) if a.nonzero?
  a = (@ip & 0xffffffff)
  return (a != 0 && a != 1)
end

#ipv4_mapped?Boolean

Returns true if an IP address is IPv4-mapped IPv6 address.

Returns:

  • (Boolean)


39
40
41
# File 'lib/ipaccess/patches/netaddr.rb', line 39

def ipv4_mapped?
  return @version == 6 && (@ip >> 32) == 0xffff
end

#safe_dup(*tags_to_remove) ⇒ Object

This method duplicates CIDR and removes tags specified as symbols. It returns new Netaddr::CIDR object.



67
68
69
70
71
72
73
74
75
76
# File 'lib/ipaccess/patches/netaddr.rb', line 67

def safe_dup(*tags_to_remove)
  tags = self.tag.dup
  tags_to_remove.each { |t| tags.delete t }
  return NetAddr.cidr_build(
    @version,
    @network,
    @netmask,
    tags,
    @wildcard_mask)
end