Sha256: 74a633f3a3dd29dd241d06ae8f770d25480c19f0bca609f560468ea69e693ef3

Contents?: true

Size: 1019 Bytes

Versions: 6

Compression:

Stored size: 1019 Bytes

Contents

module RubySL
  module Socket
    module IPv6
      # The IPv6 loopback address as produced by inet_pton(INET6, "::1")
      LOOPBACK = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]

      # The bytes used for an unspecified IPv6 address.
      UNSPECIFIED = [0] * 16

      # The first 10 bytes of an IPv4 compatible IPv6 address.
      COMPAT_PREFIX = [0] * 10

      def self.ipv4_embedded?(bytes)
        ipv4_mapped?(bytes) || ipv4_compatible?(bytes)
      end

      def self.ipv4_mapped?(bytes)
        prefix = bytes.first(10)
        follow = bytes[10..11]

        prefix == COMPAT_PREFIX &&
          follow[0] == 255 &&
          follow[1] == 255 &&
          (bytes[-4] > 0 || bytes[-3] > 0 || bytes[-2] > 0)
      end

      def self.ipv4_compatible?(bytes)
        prefix = bytes.first(10)
        follow = bytes[10..11]

        prefix == COMPAT_PREFIX &&
          follow[0] == 0 &&
          follow[1] == 0 &&
          (bytes[-4] > 0 || bytes[-3] > 0 || bytes[-2] > 0)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubysl-socket-2.2.1 lib/rubysl/socket/ipv6.rb
rubysl-socket-2.2 lib/rubysl/socket/ipv6.rb
rubysl-socket-2.1.3 lib/rubysl/socket/ipv6.rb
rubysl-socket-2.1.2 lib/rubysl/socket/ipv6.rb
rubysl-socket-2.1.1 lib/rubysl/socket/ipv6.rb
rubysl-socket-2.1.0 lib/rubysl/socket/ipv6.rb