summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark J. Titorenko <mark.titorenko@alces-software.com>2012-01-21 19:57:23 +0000
committerMark J. Titorenko <mark.titorenko@alces-software.com>2012-01-21 19:57:23 +0000
commit5e53ab81a37c8c712d693f8d8dd91331e1b4bc65 (patch)
treeea9321f51ed8daf5f2d88068751c10928892c4b9
parente53e015ba0c969585e7dea6127d5eee3a416a9f6 (diff)
downloadnet-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
-rw-r--r--CHANGELOG8
-rw-r--r--Rakefile7
-rw-r--r--lib/net/dhcp/core.rb28
-rwxr-xr-x[-rw-r--r--]test/test_dhcp.rb (renamed from test/dhcp_test.rb)7
4 files changed, 35 insertions, 15 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 5b1a6af..0bff925 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,11 @@
+*1.1.1
+
+* Replace incorrect equality check with assignment in Message#from_udp_payload to correct behaviour when an unrecognised option or message is encountered [mjtko]
+* Allow callers to disable the debug output emitted in Message#from_udp_payload for unrecognised options or messages [mjtko]
+* Added rake test task [mjtko]
+* Correct test_from_udp_payload test assertion [mjtko]
+* Default to 00:00:00:00:00:00 in Message#initialize if local MAC address can't be read [mjtko]
+
*1.1.0
* Added BroadcastAddressOption and cleaned up the output for some options to make them more readable [rakshasa]
diff --git a/Rakefile b/Rakefile
index f0d77b9..24d7d70 100644
--- a/Rakefile
+++ b/Rakefile
@@ -40,3 +40,10 @@ Rake::RDocTask.new do |rdoc|
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
+
+require 'rake/testtask'
+Rake::TestTask.new do |t|
+ t.libs << "test"
+ t.test_files = FileList['test/test*.rb']
+ t.verbose = true
+end
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
diff --git a/test/dhcp_test.rb b/test/test_dhcp.rb
index d8eb0d7..7ccbdec 100644..100755
--- a/test/dhcp_test.rb
+++ b/test/test_dhcp.rb
@@ -1,3 +1,4 @@
+#!/usr/bin/env ruby
# dhcp_test.rb
# 4 de octubre de 2007
#
@@ -6,7 +7,7 @@ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
require 'test/unit'
-require 'dhcp'
+require 'net-dhcp'
class TestDhcp_test < Test::Unit::TestCase
# def setup
@@ -63,9 +64,7 @@ class TestDhcp_test < Test::Unit::TestCase
d1 = DHCP::Discover.new
d2 = DHCP::Message.from_udp_payload(d1.pack)
- #assert_equal d1, d2, 'udp data is not correctly parsed'
- puts d1.eql?(d2)
- puts(d1 == d2)
+ assert d1.eql?(d2), 'udp data is not correctly parsed'
end
end