Module: Datadog::Core::Vendor::IPAddr
- Defined in:
- lib/datadog/core/vendor/ipaddr.rb
Overview
vendor code from github.com/ruby/ipaddr/blob/master/lib/ipaddr.rb Ruby version below 2.5 does not have the IpAddr#private? method We have to vendor the code because ruby versions below 2.5 did not extract ipaddr as a gem So we can not specify a specific version for ipaddr for ruby versions: 2.1, 2.2, 2.3, 2.4
Class Method Summary collapse
Class Method Details
.link_local?(ip) ⇒ Boolean
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/datadog/core/vendor/ipaddr.rb', line 49 def link_local?(ip) addr = ip.instance_variable_get(:@addr) case ip.family when Socket::AF_INET addr & 0xffff0000 == 0xa9fe0000 # 169.254.0.0/16 when Socket::AF_INET6 addr & 0xffc0_0000_0000_0000_0000_0000_0000_0000 == 0xfe80_0000_0000_0000_0000_0000_0000_0000 else raise ::IPAddr::AddressFamilyError, 'unsupported address family' end end |
.loopback?(ip) ⇒ Boolean
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/datadog/core/vendor/ipaddr.rb', line 62 def loopback?(ip) addr = ip.instance_variable_get(:@addr) case ip.family when Socket::AF_INET addr & 0xff000000 == 0x7f000000 when Socket::AF_INET6 addr == 1 else raise ::IPAddr::AddressFamilyError, 'unsupported address family' end end |
.private?(ip) ⇒ Boolean
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/datadog/core/vendor/ipaddr.rb', line 34 def private?(ip) addr = ip.instance_variable_get(:@addr) case ip.family when Socket::AF_INET addr & 0xff000000 == 0x0a000000 || # 10.0.0.0/8 addr & 0xfff00000 == 0xac100000 || # 172.16.0.0/12 addr & 0xffff0000 == 0xc0a80000 # 192.168.0.0/16 when Socket::AF_INET6 addr & 0xfe00_0000_0000_0000_0000_0000_0000_0000 == 0xfc00_0000_0000_0000_0000_0000_0000_0000 else raise ::IPAddr::AddressFamilyError, 'unsupported address family' end end |