Sha256: c29cf6749a2e45e9ba768d842b9d456446411adbe6bc379f3083044312022001

Contents?: true

Size: 859 Bytes

Versions: 24

Compression:

Stored size: 859 Bytes

Contents

require 'pio/dhcp/dhcp_field'
require 'pio/dhcp/field_util'
require 'pio/ipv4_header'
require 'pio/ethernet_header'
require 'pio/udp_header'

module Pio
  class Dhcp
    # Dhcp frame parser.
    class Frame < BinData::Record
      include FieldUtil

      OPTION_FIELD_LENGTH = 60

      include EthernetHeader
      include IPv4Header
      include UdpHeader

      endian :big
      ethernet_header ether_type: EtherType::IPV4
      ipv4_header ip_protocol: ProtocolNumber::UDP
      udp_header
      dhcp_field :dhcp
      string :padding, read_length: 0, initial_value: :ff_and_padding

      def to_binary
        to_binary_s
      end

      private

      def ff_and_padding
        padding_length = OPTION_FIELD_LENGTH - dhcp.optional_tlvs.num_bytes - 1
        "\xFF" + (padding_length > 0 ? "\x00" * padding_length : '')
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
pio-0.30.0 lib/pio/dhcp/frame.rb
pio-0.29.0 lib/pio/dhcp/frame.rb
pio-0.28.1 lib/pio/dhcp/frame.rb
pio-0.28.0 lib/pio/dhcp/frame.rb
pio-0.27.2 lib/pio/dhcp/frame.rb
pio-0.27.1 lib/pio/dhcp/frame.rb
pio-0.27.0 lib/pio/dhcp/frame.rb
pio-0.26.0 lib/pio/dhcp/frame.rb
pio-0.25.0 lib/pio/dhcp/frame.rb
pio-0.24.2 lib/pio/dhcp/frame.rb
pio-0.24.1 lib/pio/dhcp/frame.rb
pio-0.24.0 lib/pio/dhcp/frame.rb
pio-0.23.1 lib/pio/dhcp/frame.rb
pio-0.23.0 lib/pio/dhcp/frame.rb
pio-0.22.0 lib/pio/dhcp/frame.rb
pio-0.21.1 lib/pio/dhcp/frame.rb
pio-0.21.0 lib/pio/dhcp/frame.rb
pio-0.20.1 lib/pio/dhcp/frame.rb
pio-0.20.0 lib/pio/dhcp/frame.rb
pio-0.19.0 lib/pio/dhcp/frame.rb