File: block.rb

package info (click to toggle)
ruby-packetfu 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,520 kB
  • sloc: ruby: 8,344; makefile: 2
file content (25 lines) | stat: -rw-r--r-- 571 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# -*- coding: binary -*-
module PacketFu
  module PcapNG

    module Block

      # Calculate block length and update :block_len and block_len2 fields
      def recalc_block_len
        len = to_a.map(&:to_s).join.size
        self[:block_len].value = self[:block_len2].value = len
      end

      # Pad given field to 32 bit boundary, if needed
      def pad_field(*fields)
        fields.each do |field|
          unless self[field].size % 4 == 0
            self[field] << "\x00" * (4 - (self[field].size % 4))
          end
        end
      end

    end

  end
end