Sha256: 4e0ed18b3fe5c2788909ba67082cf897c8a5eee5beae770db15d9ae3ccec82a4
Contents?: true
Size: 1.32 KB
Versions: 1
Compression:
Stored size: 1.32 KB
Contents
require 'pio/class_inspector' require 'pio/instance_inspector' require 'pio/ruby_dumper' require 'pio/type/ether_type' require 'pio/type/mac_address' module Pio # Adds ethernet_header macro. module Ethernet MINIMUM_FRAME_SIZE = 64 # EtherType constants module Type ARP = 0x0806 IPV4 = 0x0800 VLAN = 0x8100 LLDP = 0x88cc end # This method smells of :reek:TooManyStatements # rubocop:disable MethodLength def self.included(klass) def klass.ethernet_header(options = nil) mac_address :destination_mac mac_address :source_mac if options ether_type :ether_type, value: options.fetch(:ether_type) else ether_type :ether_type end bit3 :vlan_pcp, onlyif: :vlan? bit1 :vlan_cfi, onlyif: :vlan? bit12 :vlan_vid, onlyif: :vlan? uint16 :ether_type_vlan, value: :ether_type, onlyif: :vlan? end end # rubocop:enable MethodLength def ethernet_header_length vlan? ? 18 : 14 end private def vlan? ether_type == Type::VLAN end end # Ethernet header generator/parser class EthernetHeader < BinData::Record extend ClassInspector include Ethernet include InstanceInspector include RubyDumper endian :big ethernet_header end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pio-0.30.1 | lib/pio/ethernet_header.rb |