Class: DHCP::IPAddressLeaseTimeOption

Inherits:
Option
  • Object
show all
Defined in:
lib/net/dhcp/options.rb

Overview

This option is used in a client request (DHCPDISCOVER or DHCPREQUEST) to allow the client to request a lease time for the IP address. In a server reply (DHCPOFFER), a DHCP server uses this option to specify the lease time it is willing to offer.

The time is in units of seconds, and is specified as a 32-bit unsigned integer.

The code for this option is 51, and its length is 4.

The default value is 7200 (2h)

Instance Attribute Summary

Attributes inherited from Option

#len, #payload, #type

Instance Method Summary collapse

Methods inherited from Option

#eql?, #pack, #to_a

Constructor Details

#initialize(params = {}) ⇒ IPAddressLeaseTimeOption

Returns a new instance of IPAddressLeaseTimeOption.



224
225
226
227
228
# File 'lib/net/dhcp/options.rb', line 224

def initialize(params={})
  params[:type] = $DHCP_LEASETIME
  params[:payload] = params.fetch(:payload, [7200].pack('N').unpack('C*'))
  super(params)
end

Instance Method Details

#to_sObject



230
231
232
233
234
235
# File 'lib/net/dhcp/options.rb', line 230

def to_s()
  value = self.payload.pack('C*').unpack('N').first
  value = "infinite" if value == 0xffffffff

  "IP Address Lease Time = #{value} seg"
end