module Pio::Ethernet

Adds ethernet_header macro.

Constants

MINIMUM_FRAME_SIZE

Public Class Methods

included(klass) click to toggle source

This method smells of :reek:TooManyStatements rubocop:disable MethodLength

# File lib/pio/ethernet_header.rb, line 24
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

Public Instance Methods

ethernet_header_length() click to toggle source

rubocop:enable MethodLength

# File lib/pio/ethernet_header.rb, line 41
def ethernet_header_length
  vlan? ? 18 : 14
end

Private Instance Methods

vlan?() click to toggle source
# File lib/pio/ethernet_header.rb, line 47
def vlan?
  ether_type == Type::VLAN
end