net-dhcp 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 084b32f482d254159e2d66d8d5baa30ffb925fd9
4
+ data.tar.gz: 1d3a98623bd9bc5f9e45f460b25e3c476c56459f
5
+ SHA512:
6
+ metadata.gz: d110ea9681c2cadb72948fe3178d1b6e270e6335c972139433e5460f3a9d368a47fab20bab591fb1c8f5db310f33c546afbec054e58d11735d96d2a0e734c467
7
+ data.tar.gz: fc80df66795f01a9e5c855a3fac7f20d43799b92c1a9120f8a3ea52dc45dc7417e617a56888f33a95a2cbed4099f0fea5020c9ca57c153d1c73ec5adae8179bc
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ *1.2.0
2
+
3
+ * Fix Array handling for message payloads [presto53]
4
+ * Use a raise syntax that isn't archaic [presto53]
5
+ * Depend on simplecov rather than rcov for Ruby 1.9+ compat [mjtko]
6
+
1
7
  *1.1.1
2
8
 
3
9
  * Replace incorrect equality check with assignment in Message#from_udp_payload to correct behaviour when an unrecognised option or message is encountered [mjtko]
@@ -20,4 +26,4 @@
20
26
 
21
27
  *1.0.0
22
28
 
23
- * Initial release to rubygems - originally authored by etd, migrated to github by syonbori, gemified by mjtko. [mjtko]
29
+ * Initial release to rubygems - originally authored by etd, migrated to github by syonbori, gemified by mjtko. [mjtko]
File without changes
@@ -1,5 +1,5 @@
1
1
  module Net
2
2
  module Dhcp
3
- VERSION = "1.1.1"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
@@ -29,6 +29,7 @@ module DHCP
29
29
  attr_accessor :xid
30
30
  attr_accessor :secs, :flags
31
31
  attr_accessor :ciaddr, :yiaddr, :siaddr, :giaddr, :chaddr
32
+ attr_accessor :sname, :fname
32
33
  attr_accessor :options
33
34
 
34
35
  alias == eql?
@@ -50,11 +51,13 @@ module DHCP
50
51
  :yiaddr => values.shift,
51
52
  :siaddr => values.shift,
52
53
  :giaddr => values.shift,
53
- :chaddr => values.slice!(0..15)
54
+ :chaddr => values.slice!(0..15),
55
+ :sname => values.slice!(0..63),
56
+ :fname => values.slice!(0..127),
54
57
  }
55
58
 
56
- # sname and file
57
- not_used = values.slice!(0..191)
59
+ # sname and file are now used
60
+ #not_used = values.slice!(0..191) 127+63 190
58
61
 
59
62
  return nil unless ($DHCP_MAGIC == values.shift)
60
63
 
@@ -64,7 +67,6 @@ module DHCP
64
67
  opt_class = Option
65
68
 
66
69
  params[:options] = []
67
-
68
70
  next_opt = values.shift
69
71
  while(next_opt != $DHCP_END)
70
72
  p = {
@@ -106,7 +108,7 @@ module DHCP
106
108
  # message operation and options. We need at least an operation and a
107
109
  # MessageTypeOption to create a DHCP message!!
108
110
  if (([:op, :options] & params.keys).size != 2)
109
- raise ArgumentError('you need to specify at least values for :op and :options')
111
+ raise ArgumentError, 'you need to specify at least values for :op and :options'
110
112
  end
111
113
 
112
114
  self.op = params[:op]
@@ -117,7 +119,7 @@ module DHCP
117
119
  next unless opt.class == MessageTypeOption
118
120
  found = true
119
121
  end
120
- raise ArgumentError(':options must include a MessageTypeOption') unless found
122
+ raise ArgumentError, ':options must include a MessageTypeOption' unless found
121
123
 
122
124
  #hardware type and length of the hardware address
123
125
  self.htype = params.fetch(:htype, $DHCP_HTYPE_ETHERNET)
@@ -148,7 +150,34 @@ module DHCP
148
150
  self.chaddr = [mac].pack('H*').unpack('CCCCCC')
149
151
  self.chaddr += [0x00]*(16-self.chaddr.size)
150
152
  end
151
-
153
+
154
+ if (params.key?(:sname))
155
+ sname = params[:sname]
156
+ case
157
+ when sname.size == 64
158
+ self.sname = sname
159
+ when sname.size < 64 && sname.class == String
160
+ self.sname = sname.unpack('C64').map {|x| x ? x : 0}
161
+ else
162
+ raise 'sname field should be of 64 bytes or a string of less'
163
+ end
164
+ else
165
+ self.sname = [0x00]*64
166
+ end
167
+
168
+ if (params.key?(:fname))
169
+ fname = params[:fname]
170
+ case
171
+ when fname.size == 128
172
+ self.fname = fname
173
+ when fname.size < 128 && fname.class == String
174
+ self.fname = fname.unpack('C128').map {|x| x ? x : 0}
175
+ else
176
+ raise 'fname field should be of 128 bytes or a string of less'
177
+ end
178
+ else
179
+ self.fname = [0x00]*128
180
+ end
152
181
 
153
182
  end
154
183
 
@@ -168,9 +197,12 @@ module DHCP
168
197
  else
169
198
  out << (self.chaddr + [0x00]*(16-self.chaddr.size)).pack('C16')
170
199
  end
171
-
200
+ # file_name/server_name for pxe
201
+ out << self.sname.pack('C64')
202
+ out << self.fname.pack('C128')
203
+
172
204
  # sname and file
173
- out << ([0x00]*192).pack('C192')
205
+ # out << ([0x00]*192).pack('C192')
174
206
 
175
207
  out << [$DHCP_MAGIC].pack('N')
176
208
  self.options.each do |option|
@@ -217,6 +249,8 @@ module DHCP
217
249
  out << "\t\tNext server IP address = #{[self.siaddr].pack('N').unpack('C4').join('.')}\r\n"
218
250
  out << "\t\tRelay agent IP address = #{[self.giaddr].pack('N').unpack('C4').join('.')}\r\n"
219
251
  out << "\t\tHardware address = #{self.chaddr.slice(0..(self.hlen-1)).collect do |b| b.to_s(16).upcase.rjust(2,'0') end.join(':')}\r\n"
252
+ out << "\t\tServer Name = #{self.sname.pack('n*').unpack('A*')}\r\n"
253
+ out << "\t\tFile Name = #{self.fname.pack('n*').unpack('A*')}\r\n"
220
254
  out << "\tOPT:\r\n"
221
255
  self.options.each do |opt|
222
256
  out << "\t\t #{opt.to_s}\r\n"
@@ -244,7 +278,7 @@ module DHCP
244
278
  def initialize(params={})
245
279
  params[:op] = $DHCP_OP_REPLY
246
280
  params[:options] = params.fetch(:options, [
247
- MessageTypeOption.new({:payload=>$DHCP_MSG_OFFER}),
281
+ MessageTypeOption.new({:payload=>[$DHCP_MSG_OFFER]}),
248
282
  ServerIdentifierOption.new,
249
283
  DomainNameOption.new
250
284
  ])
@@ -259,7 +293,7 @@ module DHCP
259
293
  class Request < Message
260
294
  def initialize(params={})
261
295
  params[:op] = $DHCP_OP_REQUEST
262
- params[:options] = params.fetch(:options, [MessageTypeOption.new({:payload=>$DHCP_MSG_REQUEST}), ParameterRequestListOption.new])
296
+ params[:options] = params.fetch(:options, [MessageTypeOption.new({:payload=>[$DHCP_MSG_REQUEST]}), ParameterRequestListOption.new])
263
297
  super(params)
264
298
  end
265
299
  end
@@ -277,7 +311,7 @@ module DHCP
277
311
  def initialize(params={})
278
312
  params[:op] = $DHCP_OP_REPLY
279
313
  params[:options] = params.fetch(:options, [
280
- MessageTypeOption.new({:payload=>$DHCP_MSG_ACK}),
314
+ MessageTypeOption.new({:payload=>[$DHCP_MSG_ACK]}),
281
315
  ServerIdentifierOption.new,
282
316
  DomainNameOption.new
283
317
  ])
@@ -297,7 +331,7 @@ module DHCP
297
331
  def initialize(params={})
298
332
  params[:op] = $DHCP_OP_REQUEST
299
333
  params[:options] = params.fetch(:options, [
300
- MessageTypeOption.new({:payload=>$DHCP_MSG_RELEASE}),
334
+ MessageTypeOption.new({:payload=>[$DHCP_MSG_RELEASE]}),
301
335
  ServerIdentifierOption.new
302
336
  ])
303
337
  super(params)
@@ -309,7 +343,7 @@ module DHCP
309
343
  class Inform < Message
310
344
  def initialize(params={})
311
345
  params[:op] = $DHCP_OP_REQUEST
312
- params[:options] = params.fetch(:options, [MessageTypeOption.new({:payload=>$DHCP_MSG_INFORM}), ParameterRequestListOption.new])
346
+ params[:options] = params.fetch(:options, [MessageTypeOption.new({:payload=>[$DHCP_MSG_INFORM]}), ParameterRequestListOption.new])
313
347
  super(params)
314
348
  end
315
349
  end
@@ -33,7 +33,7 @@ module DHCP
33
33
  def initialize(params = {})
34
34
  # We need a type, and a payload
35
35
  if (([:type, :payload] & params.keys).size != 2)
36
- raise ArgumentError('you need to specify values for :type and :payload')
36
+ raise ArgumentError, 'you need to specify values for :type and :payload'
37
37
  end
38
38
 
39
39
  self.type = params[:type]
@@ -252,6 +252,7 @@ module DHCP
252
252
  #
253
253
  # The default value is 1 (DHCPDISCOVER)
254
254
  class MessageTypeOption < Option
255
+ #DEBUG
255
256
  def initialize(params={})
256
257
  params[:type] = $DHCP_MESSAGETYPE
257
258
  params[:payload] = params.fetch(:payload, [$DHCP_MSG_DISCOVER])
@@ -509,7 +510,7 @@ module DHCP
509
510
  end
510
511
 
511
512
  def to_s
512
- "UserClassInformation = #{self.payload}"
513
+ "UserClassInformation = #{self.payload.pack('C*')}"
513
514
  end
514
515
  end
515
516
 
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
5
5
  s.name = 'net-dhcp'
6
6
  s.version = Net::Dhcp::VERSION
7
7
  s.platform = Gem::Platform::RUBY
8
- s.date = "2012-01-21"
8
+ s.date = "2014-01-02"
9
9
  s.authors = ['daniel martin gomez (etd)', 'syonbori', 'Mark J. Titorenko']
10
10
  s.email = 'mark.titorenko@alces-software.com'
11
11
  s.homepage = 'http://github.com/mjtko/net-dhcp-ruby'
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  s.add_development_dependency 'bundler'
31
31
  s.add_development_dependency 'bueller'
32
32
  s.add_development_dependency 'rake'
33
- s.add_development_dependency 'rcov'
33
+ s.add_development_dependency 'simplecov'
34
+ s.add_development_dependency 'rdoc'
34
35
  end
35
36
 
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-dhcp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - daniel martin gomez (etd)
@@ -11,63 +10,92 @@ authors:
11
10
  autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2012-01-21 00:00:00.000000000 Z
13
+ date: 2014-01-02 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: rspec
18
- requirement: &70354871060620 !ruby/object:Gem::Requirement
19
- none: false
17
+ requirement: !ruby/object:Gem::Requirement
20
18
  requirements:
21
- - - ! '>='
19
+ - - ">="
22
20
  - !ruby/object:Gem::Version
23
21
  version: '0'
24
22
  type: :development
25
23
  prerelease: false
26
- version_requirements: *70354871060620
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
27
29
  - !ruby/object:Gem::Dependency
28
30
  name: bundler
29
- requirement: &70354871060140 !ruby/object:Gem::Requirement
30
- none: false
31
+ requirement: !ruby/object:Gem::Requirement
31
32
  requirements:
32
- - - ! '>='
33
+ - - ">="
33
34
  - !ruby/object:Gem::Version
34
35
  version: '0'
35
36
  type: :development
36
37
  prerelease: false
37
- version_requirements: *70354871060140
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
38
43
  - !ruby/object:Gem::Dependency
39
44
  name: bueller
40
- requirement: &70354871059700 !ruby/object:Gem::Requirement
41
- none: false
45
+ requirement: !ruby/object:Gem::Requirement
42
46
  requirements:
43
- - - ! '>='
47
+ - - ">="
44
48
  - !ruby/object:Gem::Version
45
49
  version: '0'
46
50
  type: :development
47
51
  prerelease: false
48
- version_requirements: *70354871059700
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
49
57
  - !ruby/object:Gem::Dependency
50
58
  name: rake
51
- requirement: &70354871059240 !ruby/object:Gem::Requirement
52
- none: false
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: simplecov
73
+ requirement: !ruby/object:Gem::Requirement
53
74
  requirements:
54
- - - ! '>='
75
+ - - ">="
55
76
  - !ruby/object:Gem::Version
56
77
  version: '0'
57
78
  type: :development
58
79
  prerelease: false
59
- version_requirements: *70354871059240
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
60
85
  - !ruby/object:Gem::Dependency
61
- name: rcov
62
- requirement: &70354871058740 !ruby/object:Gem::Requirement
63
- none: false
86
+ name: rdoc
87
+ requirement: !ruby/object:Gem::Requirement
64
88
  requirements:
65
- - - ! '>='
89
+ - - ">="
66
90
  - !ruby/object:Gem::Version
67
91
  version: '0'
68
92
  type: :development
69
93
  prerelease: false
70
- version_requirements: *70354871058740
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
71
99
  description: The aim of Net::DHCP is to provide a set of classes to low level handle
72
100
  the DHCP protocol (rfc2131, rfc2132, etc.). With Net::DHCP you will be able to craft
73
101
  custom DHCP packages and have access to all the fields defined for the protocol.
@@ -80,8 +108,8 @@ extra_rdoc_files:
80
108
  - README
81
109
  - CHANGELOG
82
110
  files:
83
- - .document
84
- - .gitignore
111
+ - ".document"
112
+ - ".gitignore"
85
113
  - CHANGELOG
86
114
  - Gemfile
87
115
  - LICENSE
@@ -102,28 +130,24 @@ files:
102
130
  - test/test_dhcp.rb
103
131
  homepage: http://github.com/mjtko/net-dhcp-ruby
104
132
  licenses: []
133
+ metadata: {}
105
134
  post_install_message:
106
135
  rdoc_options: []
107
136
  require_paths:
108
137
  - lib
109
138
  required_ruby_version: !ruby/object:Gem::Requirement
110
- none: false
111
139
  requirements:
112
- - - ! '>='
140
+ - - ">="
113
141
  - !ruby/object:Gem::Version
114
142
  version: '0'
115
- segments:
116
- - 0
117
- hash: -2659112004771839654
118
143
  required_rubygems_version: !ruby/object:Gem::Requirement
119
- none: false
120
144
  requirements:
121
- - - ! '>='
145
+ - - ">="
122
146
  - !ruby/object:Gem::Version
123
147
  version: 1.3.7
124
148
  requirements: []
125
149
  rubyforge_project:
126
- rubygems_version: 1.8.10
150
+ rubygems_version: 2.2.0.rc.1
127
151
  signing_key:
128
152
  specification_version: 3
129
153
  summary: set of classes to low level handle the DHCP protocol