dhcpsapi 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dhcpsapi/class.rb +3 -77
- data/lib/dhcpsapi/client.rb +7 -130
- data/lib/dhcpsapi/common.rb +1 -8
- data/lib/dhcpsapi/data_structures.rb +654 -0
- data/lib/dhcpsapi/misc.rb +6 -18
- data/lib/dhcpsapi/option.rb +26 -112
- data/lib/dhcpsapi/option_value.rb +13 -183
- data/lib/dhcpsapi/reservation.rb +3 -63
- data/lib/dhcpsapi/server.rb +30 -1
- data/lib/dhcpsapi/subnet.rb +6 -80
- data/lib/dhcpsapi/version.rb +1 -1
- data/lib/dhcpsapi/win2008/class.rb +38 -0
- data/lib/dhcpsapi/win2008/client.rb +41 -0
- data/lib/dhcpsapi/win2008/free_memory.rb +14 -0
- data/lib/dhcpsapi/win2008/option.rb +57 -0
- data/lib/dhcpsapi/win2008/option_value.rb +61 -0
- data/lib/dhcpsapi/win2008/subnet.rb +46 -0
- data/lib/dhcpsapi/win2008/subnet_element.rb +26 -0
- data/lib/dhcpsapi/win2012/client.rb +21 -0
- data/lib/dhcpsapi/win2012/misc.rb +19 -0
- data/lib/dhcpsapi/win2012/reservation.rb +20 -0
- data/lib/dhcpsapi.rb +4 -6
- metadata +27 -21
- data/lib/dhcpsapi/common_data_structs.rb +0 -267
- data/lib/dhcpsapi/ffi.rb +0 -6
- data/lib/dhcpsapi/subnet_element.rb +0 -45
- data/lib/dhcpsapi_for_testing/server.rb +0 -9
- data/lib/dhcpsapi_for_testing.rb +0 -3
@@ -1,267 +0,0 @@
|
|
1
|
-
module DhcpsApi
|
2
|
-
=begin
|
3
|
-
typedef struct _DHCP_IP_ARRAY {
|
4
|
-
DWORD NumElements;
|
5
|
-
LPDHCP_IP_ADDRESS Elements;
|
6
|
-
} DHCP_IP_ARRAY, *LPDHCP_IP_ARRAY;
|
7
|
-
=end
|
8
|
-
class DHCP_IP_ARRAY < DHCPS_Struct
|
9
|
-
layout :num_elements, :uint32,
|
10
|
-
:elements, :pointer
|
11
|
-
end
|
12
|
-
|
13
|
-
=begin
|
14
|
-
typedef struct _DHCP_HOST_INFO {
|
15
|
-
DHCP_IP_ADDRESS IpAddress;
|
16
|
-
LPWSTR NetBiosName;
|
17
|
-
LPWSTR HostName;
|
18
|
-
} DHCP_HOST_INFO, *LPDHCP_HOST_INFO;
|
19
|
-
=end
|
20
|
-
class DHCP_HOST_INFO < DHCPS_Struct
|
21
|
-
layout :ip_address, :uint32,
|
22
|
-
:net_bios_name, :pointer,
|
23
|
-
:host_name, :pointer
|
24
|
-
|
25
|
-
ruby_struct_attr :uint32_to_ip, :ip_address
|
26
|
-
ruby_struct_attr :to_string, :net_bios_name, :host_name
|
27
|
-
end
|
28
|
-
|
29
|
-
=begin
|
30
|
-
typedef struct _DHCP_BINARY_DATA {
|
31
|
-
DWORD DataLength;
|
32
|
-
BYTE *Data;
|
33
|
-
} DHCP_BINARY_DATA, *LPDHCP_BINARY_DATA, DHCP_CLIENT_UID;
|
34
|
-
=end
|
35
|
-
class DHCP_CLIENT_UID < DHCPS_Struct
|
36
|
-
layout :data_length, :uint32,
|
37
|
-
:data, :pointer
|
38
|
-
|
39
|
-
def self.from_mac_address(mac_address)
|
40
|
-
to_return = new
|
41
|
-
mac_as_uint8s = to_return.mac_address_to_array_of_uint8(mac_address)
|
42
|
-
to_return[:data_length] = mac_as_uint8s.size
|
43
|
-
to_return[:data] = FFI::MemoryPointer.new(:uint8, mac_as_uint8s.size)
|
44
|
-
to_return[:data].write_array_of_uint8(mac_as_uint8s)
|
45
|
-
to_return
|
46
|
-
end
|
47
|
-
|
48
|
-
def intialize_with_mac_address(mac_address)
|
49
|
-
mac_as_uint8s = mac_address_to_array_of_uint8(mac_address)
|
50
|
-
self[:data_length] = mac_as_uint8s.size
|
51
|
-
self[:data] = FFI::MemoryPointer.new(:uint8, mac_as_uint8s.size)
|
52
|
-
self[:data].write_array_of_uint8(mac_as_uint8s)
|
53
|
-
self
|
54
|
-
end
|
55
|
-
|
56
|
-
def initialize_with_subnet_and_mac_addresses(subnet_address, mac_address)
|
57
|
-
mac_as_uint8s = mac_address_to_array_of_uint8(mac_address)
|
58
|
-
subnet_as_uint8s = subnet_address.split('.').reverse.map {|octet| octet.to_i}
|
59
|
-
self[:data_length] = 11
|
60
|
-
self[:data] = FFI::MemoryPointer.new(:uint8, 11)
|
61
|
-
self[:data].write_array_of_uint8(subnet_as_uint8s + [0x1] + mac_as_uint8s)
|
62
|
-
end
|
63
|
-
|
64
|
-
def data_as_ruby_struct_attr
|
65
|
-
self[:data].read_array_of_type(:uint8, :read_uint8, self[:data_length]).map {|w| "%02X" % w}.join(":")
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
class DHCP_BINARY_DATA < DHCPS_Struct
|
70
|
-
layout :data_length, :uint32,
|
71
|
-
:data, :pointer
|
72
|
-
|
73
|
-
def self.from_data(data)
|
74
|
-
to_return = new
|
75
|
-
to_return[:data_length] = data.size
|
76
|
-
to_return[:data] = FFI::MemoryPointer.new(:uint8, data.size)
|
77
|
-
to_return[:data].write_array_of_uint8(data)
|
78
|
-
to_return
|
79
|
-
end
|
80
|
-
|
81
|
-
def data_as_ruby_struct_attr
|
82
|
-
self[:data].read_array_of_type(:uint8, :read_uint8, self[:data_length])
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
=begin
|
87
|
-
typedef struct _DATE_TIME {
|
88
|
-
DWORD dwLowDateTime;
|
89
|
-
DWORD dwHighDateTime;
|
90
|
-
} DATE_TIME, *LPDATE_TIME;
|
91
|
-
=end
|
92
|
-
class DATE_TIME < DHCPS_Struct
|
93
|
-
layout :dw_low_date_time, :uint32,
|
94
|
-
:dw_high_date_time, :uint32
|
95
|
-
|
96
|
-
def as_ruby_struct
|
97
|
-
tmp = self[:dw_high_date_time]
|
98
|
-
tmp = (tmp << 32) + self[:dw_low_date_time]
|
99
|
-
tmp == 0 ? nil : Time.at(tmp/10000000 - 11644473600)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
=begin
|
104
|
-
typedef struct _DHCP_CLIENT_SEARCH_INFO {
|
105
|
-
DHCP_SEARCH_INFO_TYPE SearchType;
|
106
|
-
union {
|
107
|
-
DHCP_IP_ADDRESS ClientIpAddress;
|
108
|
-
DHCP_CLIENT_UID ClientHardwareAddress;
|
109
|
-
LPWSTR ClientName;
|
110
|
-
} SearchInfo;
|
111
|
-
} DHCP_SEARCH_INFO, *LPDHCP_SEARCH_INFO;
|
112
|
-
=end
|
113
|
-
class SEARCH_INFO_UNION < FFI::Union
|
114
|
-
layout :client_ip_address, :uint32,
|
115
|
-
:client_hardware_address, DHCP_CLIENT_UID,
|
116
|
-
:client_name, :pointer
|
117
|
-
end
|
118
|
-
class DHCP_SEARCH_INFO < DHCPS_Struct
|
119
|
-
layout :search_type, :uint32, # see DHCP_SEARCH_INFO_TYPE
|
120
|
-
:search_info, SEARCH_INFO_UNION
|
121
|
-
end
|
122
|
-
|
123
|
-
class DWORD_DWORD < DHCPS_Struct
|
124
|
-
layout :dword1, :uint32,
|
125
|
-
:dword2, :uint32
|
126
|
-
|
127
|
-
def self.from_int(an_int)
|
128
|
-
to_return = new
|
129
|
-
to_return[:dword1] = ((an_int >> 32) & 0xffffffff)
|
130
|
-
to_return[:dword2] = (an_int & 0xffffffff)
|
131
|
-
to_return
|
132
|
-
end
|
133
|
-
|
134
|
-
def as_ruby_struct
|
135
|
-
(self[:dword1] << 32) | self[:dword2]
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
=begin
|
140
|
-
typedef struct _DHCP_OPTION_DATA_ELEMENT {
|
141
|
-
DHCP_OPTION_DATA_TYPE OptionType;
|
142
|
-
union {
|
143
|
-
BYTE ByteOption;
|
144
|
-
WORD WordOption;
|
145
|
-
DWORD DWordOption;
|
146
|
-
DWORD_DWORD DWordDWordOption;
|
147
|
-
DHCP_IP_ADDRESS IpAddressOption;
|
148
|
-
LPWSTR StringDataOption;
|
149
|
-
DHCP_BINARY_DATA BinaryDataOption;
|
150
|
-
DHCP_BINARY_DATA EncapsulatedDataOption;
|
151
|
-
LPWSTR Ipv6AddressDataOption;
|
152
|
-
} Element;
|
153
|
-
} DHCP_OPTION_DATA_ELEMENT, *LPDHCP_OPTION_DATA_ELEMENT;
|
154
|
-
=end
|
155
|
-
class DHCP_OPTION_DATA_ELEMENT_UNION < FFI::Union
|
156
|
-
layout :byte_option, :uint8,
|
157
|
-
:word_opition, :uint16,
|
158
|
-
:dword_option, :uint32,
|
159
|
-
:dword_dword_option, DWORD_DWORD,
|
160
|
-
:ip_address_option, :uint32,
|
161
|
-
:string_data_option, :pointer,
|
162
|
-
:binary_data_option, DHCP_BINARY_DATA, # expects an array of uint8s
|
163
|
-
:encapsulated_data_option, DHCP_BINARY_DATA,
|
164
|
-
:ipv6_address_data_option, :pointer
|
165
|
-
end
|
166
|
-
|
167
|
-
class DHCP_OPTION_DATA_ELEMENT < DHCPS_Struct
|
168
|
-
layout :option_type, :uint32, # see DHCP_OPTION_DATA_TYPE
|
169
|
-
:element, DHCP_OPTION_DATA_ELEMENT_UNION
|
170
|
-
|
171
|
-
def element_as_ruby_struct_attr
|
172
|
-
case self[:option_type]
|
173
|
-
when DHCP_OPTION_DATA_TYPE::DhcpByteOption
|
174
|
-
self[:element][:byte_option]
|
175
|
-
when DHCP_OPTION_DATA_TYPE::DhcpWordOption
|
176
|
-
self[:element][:word_opition]
|
177
|
-
when DHCP_OPTION_DATA_TYPE::DhcpDWordOption
|
178
|
-
self[:element][:dword_option]
|
179
|
-
when DHCP_OPTION_DATA_TYPE::DhcpDWordDWordOption
|
180
|
-
self[:element][:dword_dword_option].as_ruby_struct
|
181
|
-
when DHCP_OPTION_DATA_TYPE::DhcpIpAddressOption
|
182
|
-
uint32_to_ip(self[:element][:ip_address_option])
|
183
|
-
when DHCP_OPTION_DATA_TYPE::DhcpStringDataOption
|
184
|
-
to_string(self[:element][:string_data_option])
|
185
|
-
when DHCP_OPTION_DATA_TYPE::DhcpBinaryDataOption
|
186
|
-
self[:element][:binary_data_option].as_ruby_struct
|
187
|
-
when DHCP_OPTION_DATA_TYPE::DhcpEncapsulatedDataOption
|
188
|
-
self[:element][:encapsulated_data_option].as_ruby_struct
|
189
|
-
when DHCP_OPTION_DATA_TYPE::DhcpIpv6AddressOption
|
190
|
-
to_string(self[:element][:ipv6_address_data_option])
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
def initialize_from_data(type, data)
|
195
|
-
self[:option_type] = type
|
196
|
-
case type
|
197
|
-
when DHCP_OPTION_DATA_TYPE::DhcpByteOption
|
198
|
-
self[:element][:byte_option] = data.nil? ? 0 : data & 0xff
|
199
|
-
when DHCP_OPTION_DATA_TYPE::DhcpWordOption
|
200
|
-
self[:element][:word_opition] = data.nil? ? 0 : data & 0xffff
|
201
|
-
when DHCP_OPTION_DATA_TYPE::DhcpDWordOption
|
202
|
-
self[:element][:dword_option] = data.nil? ? 0 : data & 0xffffffff
|
203
|
-
when DHCP_OPTION_DATA_TYPE::DhcpDWordDWordOption
|
204
|
-
self[:element][:dword_dword_option] = DWORD_DWORD.from_int(data.nil? ? 0 : data)
|
205
|
-
when DHCP_OPTION_DATA_TYPE::DhcpIpAddressOption
|
206
|
-
self[:element][:ip_address_option] = data.nil? ? 0 : ip_to_uint32(data)
|
207
|
-
when DHCP_OPTION_DATA_TYPE::DhcpStringDataOption
|
208
|
-
self[:element][:string_data_option] = FFI::MemoryPointer.from_string(to_wchar_string(data.nil? ? '' : data))
|
209
|
-
when DHCP_OPTION_DATA_TYPE::DhcpBinaryDataOption
|
210
|
-
self[:element][:binary_data_option] = DHCP_BINARY_DATA.from_data(data.nil? ? [0] : data)
|
211
|
-
when DHCP_OPTION_DATA_TYPE::DhcpEncapsulatedDataOption
|
212
|
-
self[:element][:encapsulated_data_option] = DHCP_BINARY_DATA.from_data(data.nil? ? [0] : data)
|
213
|
-
when DHCP_OPTION_DATA_TYPE::DhcpIpv6AddressOption
|
214
|
-
self[:element][:ipv6_address_data_option] = FFI::MemoryPointer.from_string(to_wchar_string(data.nil? ? '' : data))
|
215
|
-
else
|
216
|
-
raise DhcpError, "Unknown dhcp option data type: #{type}"
|
217
|
-
end
|
218
|
-
|
219
|
-
self
|
220
|
-
end
|
221
|
-
|
222
|
-
def self.initialize_from_data(type, data)
|
223
|
-
DHCP_OPTION_DATA_ELEMENT.new.initialize_from_data(type, data)
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
=begin
|
228
|
-
typedef struct _DHCP_OPTION_DATA {
|
229
|
-
DWORD NumElements;
|
230
|
-
LPDHCP_OPTION_DATA_ELEMENT Elements;
|
231
|
-
} DHCP_OPTION_DATA, *LPDHCP_OPTION_DATA;
|
232
|
-
=end
|
233
|
-
class DHCP_OPTION_DATA < DHCPS_Struct
|
234
|
-
layout :num_elements, :uint32,
|
235
|
-
:elements, :pointer
|
236
|
-
|
237
|
-
def self.from_array(type, array_of_data)
|
238
|
-
to_return = new
|
239
|
-
to_return.from_array(type, array_of_data)
|
240
|
-
to_return
|
241
|
-
end
|
242
|
-
|
243
|
-
def from_array(type, array_of_data)
|
244
|
-
if array_of_data.size == 0
|
245
|
-
self[:num_elements] = 1
|
246
|
-
self[:elements] = FFI::MemoryPointer.new(DHCP_OPTION_DATA_ELEMENT, 1)
|
247
|
-
DHCP_OPTION_DATA_ELEMENT.new(self[:elements]).initialize_from_data(type, nil)
|
248
|
-
return self
|
249
|
-
end
|
250
|
-
|
251
|
-
self[:num_elements] = array_of_data.size
|
252
|
-
self[:elements] = FFI::MemoryPointer.new(DHCP_OPTION_DATA_ELEMENT, array_of_data.size)
|
253
|
-
0.upto(array_of_data.size-1) do |i|
|
254
|
-
element = DHCP_OPTION_DATA_ELEMENT.new(self[:elements] + DHCP_OPTION_DATA_ELEMENT.size*i)
|
255
|
-
element.initialize_from_data(type, array_of_data[i])
|
256
|
-
end
|
257
|
-
|
258
|
-
self
|
259
|
-
end
|
260
|
-
|
261
|
-
def as_ruby_struct
|
262
|
-
0.upto(self[:num_elements]-1).inject([]) do |all, offset|
|
263
|
-
all << DHCP_OPTION_DATA_ELEMENT.new(self[:elements] + DHCP_OPTION_DATA_ELEMENT.size*offset).as_ruby_struct
|
264
|
-
end
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|
data/lib/dhcpsapi/ffi.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
module DhcpsApi
|
2
|
-
=begin
|
3
|
-
typedef struct _DHCP_SUBNET_ELEMENT_DATA_V4 {
|
4
|
-
DHCP_SUBNET_ELEMENT_TYPE ElementType;
|
5
|
-
union {
|
6
|
-
DHCP_IP_RANGE *IpRange;
|
7
|
-
DHCP_HOST_INFO *SecondaryHost;
|
8
|
-
DHCP_IP_RESERVATION_V4 *ReservedIp;
|
9
|
-
DHCP_IP_RANGE *ExcludeIpRange;
|
10
|
-
DHCP_IP_CLUSTER *IpUsedCluster;
|
11
|
-
} Element;
|
12
|
-
} DHCP_SUBNET_ELEMENT_DATA_V4, *LPDHCP_SUBNET_ELEMENT_DATA_V4;
|
13
|
-
=end
|
14
|
-
class DHCP_SUBNET_ELEMENT < FFI::Union
|
15
|
-
layout :ip_range, :pointer,
|
16
|
-
:secondary_host, :pointer,
|
17
|
-
:reserved_ip, :pointer,
|
18
|
-
:exclude_ip_range, :pointer,
|
19
|
-
:ip_used_cluster, :pointer
|
20
|
-
end
|
21
|
-
|
22
|
-
class DHCP_SUBNET_ELEMENT_DATA_V4 < DHCPS_Struct
|
23
|
-
layout :element_type, :uint32,
|
24
|
-
:element, DHCP_SUBNET_ELEMENT
|
25
|
-
end
|
26
|
-
|
27
|
-
=begin
|
28
|
-
DWORD DhcpAddSubnetElementV4(
|
29
|
-
_In_ DHCP_CONST WCHAR *ServerIpAddress,
|
30
|
-
_In_ DHCP_IP_ADDRESS SubnetAddress,
|
31
|
-
_In_ DHCP_CONST DHCP_SUBNET_ELEMENT_DATA_V4 *AddElementInfo
|
32
|
-
);
|
33
|
-
=end
|
34
|
-
attach_function :DhcpAddSubnetElementV4, [:pointer, :uint32, :pointer], :uint32
|
35
|
-
|
36
|
-
=begin
|
37
|
-
DWORD DHCP_API_FUNCTION DhcpRemoveSubnetElementV4(
|
38
|
-
_In_ DHCP_CONST WCHAR *ServerIpAddress,
|
39
|
-
_In_ DHCP_IP_ADDRESS SubnetAddress,
|
40
|
-
_In_ DHCP_CONST DHCP_SUBNET_ELEMENT_DATA_V4 *RemoveElementInfo,
|
41
|
-
_In_ DHCP_FORCE_FLAG ForceFlag
|
42
|
-
);
|
43
|
-
=end
|
44
|
-
attach_function :DhcpRemoveSubnetElementV4, [:pointer, :uint32, :pointer, :uint32], :uint32
|
45
|
-
end
|
data/lib/dhcpsapi_for_testing.rb
DELETED