<commit_before>module PacketGen
  module Header

    # Mixin for various headers
    # @author <NAME>
    module HeaderMethods

      # @api private
      # Set reference of packet which owns this header
      # @param [Packet] packet
      # @return [void]
      def packet=(packet)
        @packet = packet
      end

      # @api private
      # Get rference on packet which owns this header
      # @return [Packet]
      def packet
        @packet
      end

      # @api private
      # Get +header+ id in packet headers array
      # @param [Header] header
      # @return [Integer]
      # @raise FormatError +header+ not in a packet
      def header_id(header)
        raise FormatError, "header of type #{header.class} not in a packet" if packet.nil?
        id = packet.headers.index(header)
        if id.nil?
          raise FormatError, "header of type #{header.class} not in packet #{packet}"
        end
        id
      end

      # @api private
      # Get IP or IPv6 previous header from +header+
      # @param [Header] header
      # @return [Header]
      # @raise FormatError no IP or IPv6 header previous +header+ in packet
      # @raise FormatError +header+ not in a packet
      def ip_header(header)
        hid = header_id(header)
        iph = packet.headers[0...hid].reverse.find { |h| h.is_a? IP }
        raise FormatError, 'no IP or IPv6 header in packet' if iph.nil?
        iph
      end
    end
  end
end<commit_msg>Update Header::HeaderMethods#ip_header to return first of IP or IPv6 header<commit_after>module PacketGen
  module Header

    # Mixin for various headers
    # @author <NAME>
    module HeaderMethods

      # @api private
      # Set reference of packet which owns this header
      # @param [Packet] packet
      # @return [void]
      def packet=(packet)
        @packet = packet
      end

      # @api private
      # Get rference on packet which owns this header
      # @return [Packet]
      def packet
        @packet
      end

      # @api private
      # Get +header+ id in packet headers array
      # @param [Header] header
      # @return [Integer]
      # @raise FormatError +header+ not in a packet
      def header_id(header)
        raise FormatError, "header of type #{header.class} not in a packet" if packet.nil?
        id = packet.headers.index(header)
        if id.nil?
          raise FormatError, "header of type #{header.class} not in packet #{packet}"
        end
        id
      end

      # @api private
      # Get IP or IPv6 previous header from +header+
      # @param [Header] header
      # @return [Header]
      # @raise FormatError no IP or IPv6 header previous +header+ in packet
      # @raise FormatError +header+ not in a packet
      def ip_header(header)
        hid = header_id(header)
        iph = packet.headers[0...hid].reverse.find { |h| h.is_a? IP or h.is_a? IPv6 }
        raise FormatError, 'no IP or IPv6 header in packet' if iph.nil?
        iph
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08411528150134048, 'fraction_numerical': 0.003351206434316354, 'mean_word_length': 2.090062111801242, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4877110', 'n_tokens_mistral': 865, 'n_tokens_neox': 844, 'n_words': 327}