Sha256: dc481d491057e5d989d143cbbe0f96818c91992a35fb83502b4239ca6b2960d4

Contents?: true

Size: 881 Bytes

Versions: 1

Compression:

Stored size: 881 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: EthernetHeader::ETHER_TYPE_IP
      ipv4_header ip_protocol: IPv4Header::IP_PROTOCOL_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

1 entries across 1 versions & 1 rubygems

Version Path
pio-0.16.0 lib/pio/dhcp/frame.rb