Class: PacketGen::Header::BOOTP

Inherits:
Base show all
Defined in:
lib/packetgen/header/bootp.rb

Overview

Bootstrap Protocol, RFC 951

A BOOTP header consists of:

Create a BOOTP header

# standalone
bootp = PacketGen::Header::BOOTP.new
# in a packet
pkt = PacketGen.gen('IP').add('BOOTP')
# access to BOOTP header
pkt.bootp      # => PacketGen::Header::BOOTP

Author:

  • Sylvain Daubert

Since:

  • 2.2.0

Constant Summary collapse

UDP_SERVER_PORT =

Since:

  • 2.2.0

67
UDP_CLIENT_PORT =

Since:

  • 2.2.0

68
OPCODES =

DHCP opcodes

Since:

  • 2.2.0

{
  'BOOTREQUEST' => 1,
  'BOOTREPLY' => 2
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

bind, calculate_and_set_length, #header_id, inherited, #initialize, #ip_header, #ll_header

Methods included from PacketGen::Headerable

#added_to_packet, included, #method_name, #packet, #packet=, #parse?, #protocol_name, #read

Methods inherited from Types::Fields

#[], #[]=, #bits_on, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, fields, inherited, #initialize, #offset_of, #optional?, #optional_fields, #present?, #read, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field

Constructor Details

This class inherits a constructor from PacketGen::Header::Base

Instance Attribute Details

#bObject

Broadcast flag, from #flags



132
# File 'lib/packetgen/header/bootp.rb', line 132

define_bit_fields_on :flags, :b, :mbz, 15

#bodyString

Returns:

  • (String)


124
# File 'lib/packetgen/header/bootp.rb', line 124

define_field :body, Types::String

#chaddrString

client hardware address

Returns:

  • (String)


110
# File 'lib/packetgen/header/bootp.rb', line 110

define_field :chaddr, Types::String, static_length: 16

#ciaddrString

client IP address

Returns:

  • (String)


90
# File 'lib/packetgen/header/bootp.rb', line 90

define_field :ciaddr, IP::Addr

#fileString

Boot file name, null terminated string

Returns:

  • (String)


120
# File 'lib/packetgen/header/bootp.rb', line 120

define_field :file, Types::CString, static_length: 128

#flagsInteger

16-bit flag field

Returns:

  • (Integer)


85
# File 'lib/packetgen/header/bootp.rb', line 85

define_field :flags, Types::Int16

#giaddrString

Relay agent IP address, used in booting via a relay agent

Returns:

  • (String)


105
# File 'lib/packetgen/header/bootp.rb', line 105

define_field :giaddr, IP::Addr

#hlenInteger

8-bit hardware address length

Returns:

  • (Integer)


65
# File 'lib/packetgen/header/bootp.rb', line 65

define_field :hlen, Types::Int8, default: 6

#hopsInteger

Returns:

  • (Integer)


69
# File 'lib/packetgen/header/bootp.rb', line 69

define_field :hops, Types::Int8

#htypeInteger

8-bit hardware address type

Returns:

  • (Integer)


60
# File 'lib/packetgen/header/bootp.rb', line 60

define_field :htype, Types::Int8, default: 1

#mbzObject

15-bit Must Be Zero bits, from #flags



132
# File 'lib/packetgen/header/bootp.rb', line 132

define_bit_fields_on :flags, :b, :mbz, 15

#opInteger

8-bit opcode

Returns:

  • (Integer)


55
# File 'lib/packetgen/header/bootp.rb', line 55

define_field :op, Types::Int8Enum, enum: OPCODES

#secsInteger

16-bit integer: number of seconds elapsed since client began address acquisition or renewal process

Returns:

  • (Integer)


80
# File 'lib/packetgen/header/bootp.rb', line 80

define_field :secs, Types::Int16

#siaddrString

IP address of next server to use in bootstrap

Returns:

  • (String)


100
# File 'lib/packetgen/header/bootp.rb', line 100

define_field :siaddr, IP::Addr

#snameString

optional server hostname, null-terminated string

Returns:

  • (String)


115
# File 'lib/packetgen/header/bootp.rb', line 115

define_field :sname, Types::CString, static_length: 64

#xidInteger

32-bit Transaction ID

Returns:

  • (Integer)


74
# File 'lib/packetgen/header/bootp.rb', line 74

define_field :xid, Types::Int32

#yiaddrString

‘your’ (client) IP address

Returns:

  • (String)


95
# File 'lib/packetgen/header/bootp.rb', line 95

define_field :yiaddr, IP::Addr

Instance Method Details

#inspectString

Returns:

  • (String)

Since:

  • 2.2.0



135
136
137
138
139
140
141
# File 'lib/packetgen/header/bootp.rb', line 135

def inspect
  super do |attr|
    next unless (attr == :chaddr) && (self.hlen == 6)

    Inspect.inspect_attribute(attr, Eth::MacAddr.new.read(self[:chaddr][0, 6]))
  end
end

#reply!self

Invert opcode, if known

Returns:

  • (self)

Since:

  • 2.2.0



145
146
147
148
149
150
151
# File 'lib/packetgen/header/bootp.rb', line 145

def reply!
  case self.op
  when 1 then self.op = 2
  when 2 then self.op = 1
  end
  self
end