Class: DHCP::Option
- Inherits:
-
Object
- Object
- DHCP::Option
- Defined in:
- lib/net/dhcp/options.rb
Overview
General object to capture DHCP options. Every option of the protocol has three fields: an option type, a defined length and a payload
Direct Known Subclasses
AutoConfigurationOption, BroadcastAddressOption, ClientFQDNOption, ClientIdentifierOption, ClientNetworkDeviceInterfaceOption, ClientSystemArchitectureOption, DomainNameOption, DomainNameServerOption, HostNameOption, IPAddressLeaseTimeOption, MaximumMsgSizeOption, MessageTypeOption, ParameterRequestListOption, PrivateOption, RequestedIPAddressOption, RouterOption, ServerIdentifierOption, SubnetMaskOption, SubnetSelectionOption, UUIDGUIDOption, UserClassInformationOption, VendorClassIDOption
Instance Attribute Summary collapse
-
#len ⇒ Object
Returns the value of attribute len.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#eql?(obj) ⇒ Boolean
(also: #==)
Check wether a given option is equivalent (protocol level) to this one.
-
#initialize(params = {}) ⇒ Option
constructor
Create a DHCP option object with the given type and payload.
-
#pack ⇒ Object
Return the option packed as a binary string.
-
#to_a ⇒ Object
Return the option packed as an array of bytes.
- #to_s ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Option
Create a DHCP option object with the given type and payload. params
must be an array containing at least these two keys: :type and :payload The length is calculated with the size of the payload
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/net/dhcp/options.rb', line 33 def initialize(params = {}) # We need a type, and a payload if (([:type, :payload] & params.keys).size != 2) raise ArgumentError, 'you need to specify values for :type and :payload' end self.type = params[:type] self.payload = params[:payload] self.len = params.fetch(:len, self.payload.size) end |
Instance Attribute Details
#len ⇒ Object
Returns the value of attribute len.
28 29 30 |
# File 'lib/net/dhcp/options.rb', line 28 def len @len end |
#payload ⇒ Object
Returns the value of attribute payload.
28 29 30 |
# File 'lib/net/dhcp/options.rb', line 28 def payload @payload end |
#type ⇒ Object
Returns the value of attribute type.
28 29 30 |
# File 'lib/net/dhcp/options.rb', line 28 def type @type end |
Instance Method Details
#eql?(obj) ⇒ Boolean Also known as: ==
Check wether a given option is equivalent (protocol level) to this one.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/net/dhcp/options.rb', line 56 def eql?(obj) return false unless (self.class == obj.class) vars = self.instance_variables # check all the other instance vairables vars.each do |var| return false unless (self.instance_variable_get(var) == obj.instance_variable_get(var)) end return true end |
#pack ⇒ Object
Return the option packed as a binary string.
51 52 53 |
# File 'lib/net/dhcp/options.rb', line 51 def pack (self.to_a).pack('C*') end |
#to_a ⇒ Object
Return the option packed as an array of bytes. The first two elements are the type and length of this option. The payload follows afterwards.
46 47 48 |
# File 'lib/net/dhcp/options.rb', line 46 def to_a return [self.type, self.len] + self.payload end |
#to_s ⇒ Object
68 69 70 |
# File 'lib/net/dhcp/options.rb', line 68 def to_s "to_s NOT implemented for option type: #{self.type}" end |