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


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

define_bit_fields_on :flags, :b, :mbz, 15

#bodyString

Returns:

  • (String)

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

define_field :body, Types::String

#chaddrString

client hardware address

Returns:

  • (String)

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

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

#ciaddrString

client IP address

Returns:

  • (String)

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

define_field :ciaddr, IP::Addr

#fileString

Boot file name, null terminated string

Returns:

  • (String)

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

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

#flagsInteger

16-bit flag field

Returns:

  • (Integer)

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

define_field :flags, Types::Int16

#giaddrString

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

Returns:

  • (String)

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

define_field :giaddr, IP::Addr

#hlenInteger

8-bit hardware address length

Returns:

  • (Integer)

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

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

#hopsInteger

Returns:

  • (Integer)

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

define_field :hops, Types::Int8

#htypeInteger

8-bit hardware address type

Returns:

  • (Integer)

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

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

#mbzObject

15-bit Must Be Zero bits, from #flags


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

define_bit_fields_on :flags, :b, :mbz, 15

#opInteger

8-bit opcode

Returns:

  • (Integer)

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

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)

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

define_field :secs, Types::Int16

#siaddrString

IP address of next server to use in bootstrap

Returns:

  • (String)

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

define_field :siaddr, IP::Addr

#snameString

optional server hostname, null-terminated string

Returns:

  • (String)

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

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

#xidInteger

32-bit Transaction ID

Returns:

  • (Integer)

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

define_field :xid, Types::Int32

#yiaddrString

'your' (client) IP address

Returns:

  • (String)

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

define_field :yiaddr, IP::Addr

Instance Method Details

#inspectString

Returns:

  • (String)

Since:

  • 2.2.0


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

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


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

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