diff options
author | Jari Sundell <sundell.software@gmail.com> | 2011-12-07 16:01:36 +0900 |
---|---|---|
committer | Jari Sundell <sundell.software@gmail.com> | 2011-12-07 16:01:36 +0900 |
commit | 4c6588c8d30ac32a484e2733f697ec806d460952 (patch) | |
tree | a01d41d271d9dad6098bdaef1b99f9cdffb02ff4 | |
parent | cac9a26f9dba1a136d96768ca4adb0c84f2a47da (diff) | |
download | net-dhcp-ruby-4c6588c8d30ac32a484e2733f697ec806d460952.tar.gz |
Added BroadcastAddressOption and cleaned up transaction id and parameter request list output.
-rw-r--r-- | lib/net/dhcp/core.rb | 2 | ||||
-rw-r--r-- | lib/net/dhcp/options.rb | 28 |
2 files changed, 26 insertions, 4 deletions
diff --git a/lib/net/dhcp/core.rb b/lib/net/dhcp/core.rb index bb42e52..e05b82e 100644 --- a/lib/net/dhcp/core.rb +++ b/lib/net/dhcp/core.rb @@ -205,7 +205,7 @@ module DHCP def to_s out = "DHCP Message\r\n" out << "\tFIELDS:\r\n" - out << "\t\tTransaction ID = #{self.xid}\r\n" + out << "\t\tTransaction ID = 0x#{self.xid.to_s(16)}\r\n" out << "\t\tClient IP address = #{[self.ciaddr].pack('N').unpack('C4').join('.')}\r\n" out << "\t\tYour IP address = #{[self.yiaddr].pack('N').unpack('C4').join('.')}\r\n" out << "\t\tNext server IP address = #{[self.siaddr].pack('N').unpack('C4').join('.')}\r\n" diff --git a/lib/net/dhcp/options.rb b/lib/net/dhcp/options.rb index 1033ed2..5b2ec58 100644 --- a/lib/net/dhcp/options.rb +++ b/lib/net/dhcp/options.rb @@ -172,6 +172,25 @@ module DHCP end end + # This option specifies the broadcast address in use on the client's + # subnet. Legal values for broadcast addresses are specified in + # section 3.2.1.3 of [4]. + # + # The code for this option is 28, and its length is 4. + # + # The default value for this option is 255.255.255.255 + class BroadcastAddressOption < Option + def initialize(params={}) + params[:type] = $DHCP_BROADCASTADDR + params[:payload] = params.fetch(:payload, [255, 255, 255, 255]) + super(params) + end + + def to_s() + "Broadcast Adress = #{self.payload.join('.')}" + end + end + # This option is used in a client request (DHCPDISCOVER) to allow the # client to request that a particular IP address be assigned. # @@ -209,7 +228,10 @@ module DHCP end def to_s() - "IP Address Lease Time = #{self.payload.pack('C*').unpack('N').first} seg" + value = self.payload.pack('C*').unpack('N').first + value = "infinite" if value == 0xffffffff + + "IP Address Lease Time = #{value} seg" end end @@ -289,7 +311,7 @@ module DHCP end def to_s - "Parameter Request List = #{self.payload}" + "Parameter Request List = #{self.payload.join(',')}" end end @@ -561,7 +583,7 @@ module DHCP $DHCP_MTUTABLE => Option, $DHCP_MTUSIZE => Option, $DHCP_LOCALSUBNETS => Option, - $DHCP_BROADCASTADDR => Option, + $DHCP_BROADCASTADDR => BroadcastAddressOption, $DHCP_DOMASKDISCOV => Option, $DHCP_MASKSUPPLY => Option, $DHCP_DOROUTEDISC => Option, |