diff options
author | Mark J. Titorenko <mark.titorenko@alces-software.com> | 2012-01-21 19:57:23 +0000 |
---|---|---|
committer | Mark J. Titorenko <mark.titorenko@alces-software.com> | 2012-01-21 19:57:23 +0000 |
commit | 5e53ab81a37c8c712d693f8d8dd91331e1b4bc65 (patch) | |
tree | ea9321f51ed8daf5f2d88068751c10928892c4b9 /lib | |
parent | e53e015ba0c969585e7dea6127d5eee3a416a9f6 (diff) | |
download | net-dhcp-ruby-5e53ab81a37c8c712d693f8d8dd91331e1b4bc65.tar.gz |
Replace incorrect equality check with assignment in Message#from_udp_payload to correct behaviour when an unrecognised option or message is encountered
Allow callers to disable the debug output emitted in Message#from_udp_payload for unrecognised options or messages
Added rake test task
Correct test_from_udp_payload test assertion
Default to 00:00:00:00:00:00 in Message#initialize if local MAC address can't be read
Diffstat (limited to 'lib')
-rw-r--r-- | lib/net/dhcp/core.rb | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/lib/net/dhcp/core.rb b/lib/net/dhcp/core.rb index e05b82e..ae4b33a 100644 --- a/lib/net/dhcp/core.rb +++ b/lib/net/dhcp/core.rb @@ -33,7 +33,8 @@ module DHCP alias == eql? - def Message.from_udp_payload(data) + def Message.from_udp_payload(data, opts={}) + opts = {:debug => true}.merge(opts) values = data.unpack('C4Nn2N4C16C192NC*') params = { @@ -74,11 +75,13 @@ module DHCP # check what is the type of dhcp option opt_class = $DHCP_MSG_OPTIONS[p[:type]] - if(opt_class.nil?) - puts '-------------------- please further investigate!!' - puts p[:type] - puts '-------------------- /' - opt_class == Option + if opt_class.nil? + if opts[:debug] + puts '-------------------- please further investigate!!' + puts p[:type] + puts '-------------------- /' + end + opt_class = Option end if (opt_class == MessageTypeOption) msg_class = $DHCP_MSG_CLASSES[p[:payload].first] @@ -87,11 +90,13 @@ module DHCP next_opt = values.shift end - if(msg_class.nil?) - puts '-------------------- please further investigate!!' - p params[:options] - puts '-------------------- /' - opt_class == Option + if msg_class.nil? + if opts[:debug] + puts '-------------------- please further investigate!!' + p params[:options] + puts '-------------------- /' + end + msg_class = Message end msg_class.new(params) end @@ -139,6 +144,7 @@ module DHCP raise 'chaddr field should be of 16 bytes' unless self.chaddr.size == 16 else mac = `/sbin/ifconfig | grep HWaddr | cut -c39- | head -1`.chomp.strip.gsub(/:/,'') + mac = '000000000000' if mac.empty? self.chaddr = [mac].pack('H*').unpack('CCCCCC') self.chaddr += [0x00]*(16-self.chaddr.size) end |