dhcpsapi 0.0.4 → 0.0.5
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/client.rb +53 -0
- data/lib/dhcpsapi/data_structures.rb +53 -30
- data/lib/dhcpsapi/version.rb +1 -1
- data/lib/dhcpsapi/win2008/client.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90390bfda1251be29291f1ccc64fae4358333060
|
4
|
+
data.tar.gz: e0709a99e9c7996f1de1928226edfa92ff12b6e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d71ceba9348203e4a045afa1867281575f126430e7473beb40adafee6f3e793ad49dc509dae4875ee54ce3a2c97978339b1ed6d3302e615c02d2050a742127b
|
7
|
+
data.tar.gz: 458300694746a914f91580cbcb2ce38f70d931559e69913fef9b237471aacc1821735f1ca1c16da349fef845620664bac9c61a37c5515c876d800a4eabba49fe
|
data/lib/dhcpsapi/client.rb
CHANGED
@@ -1,5 +1,34 @@
|
|
1
1
|
module DhcpsApi
|
2
2
|
module Client
|
3
|
+
# Returns a a list of subnet clients (Windows 2008-compatible version).
|
4
|
+
#
|
5
|
+
# @example List subnet clients
|
6
|
+
#
|
7
|
+
# api.list_clients_2008('192.168.42.0')
|
8
|
+
#
|
9
|
+
# @param subnet_address [String] Subnet ip address
|
10
|
+
#
|
11
|
+
# @return [Array<Hash>]
|
12
|
+
#
|
13
|
+
# @see DHCP_CLIENT_INFO_V4 DHCP_CLIENT_INFO_V4 documentation for the list of available fields.
|
14
|
+
#
|
15
|
+
def list_clients_2008(subnet_address)
|
16
|
+
items, _ = retrieve_items(:dhcp_enum_subnet_clients_v4, subnet_address, 1024, 0)
|
17
|
+
items
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns a a list of subnet clients (Windows 2012-compatible version).
|
21
|
+
#
|
22
|
+
# @example List subnet clients
|
23
|
+
#
|
24
|
+
# api.list_clients('192.168.42.0')
|
25
|
+
#
|
26
|
+
# @param subnet_address [String] Subnet ip address
|
27
|
+
#
|
28
|
+
# @return [Array<Hash>]
|
29
|
+
#
|
30
|
+
# @see DHCP_CLIENT_INFO_PB DHCP_CLIENT_INFO_PB documentation for the list of available fields.
|
31
|
+
#
|
3
32
|
def list_clients(subnet_address)
|
4
33
|
items, _ = retrieve_items(:dhcp_v4_enum_subnet_clients, subnet_address, 1024, 0)
|
5
34
|
items
|
@@ -121,6 +150,30 @@ module DhcpsApi
|
|
121
150
|
to_return
|
122
151
|
end
|
123
152
|
|
153
|
+
def dhcp_enum_subnet_clients_v4(subnet_address, preferred_maximum, resume_handle)
|
154
|
+
resume_handle_ptr = FFI::MemoryPointer.new(:uint32).put_uint32(0, resume_handle)
|
155
|
+
client_info_ptr_ptr = FFI::MemoryPointer.new(:pointer)
|
156
|
+
elements_read_ptr = FFI::MemoryPointer.new(:uint32).put_uint32(0, 0)
|
157
|
+
elements_total_ptr = FFI::MemoryPointer.new(:uint32).put_uint32(0, 0)
|
158
|
+
|
159
|
+
error = DhcpsApi::Win2008::Client.DhcpEnumSubnetClientsV4(
|
160
|
+
to_wchar_string(server_ip_address), ip_to_uint32(subnet_address), resume_handle_ptr, preferred_maximum,
|
161
|
+
client_info_ptr_ptr, elements_read_ptr, elements_total_ptr)
|
162
|
+
return empty_response if error == 259
|
163
|
+
if is_error?(error)
|
164
|
+
unless (client_info_ptr_ptr.null? || (to_free = client_info_ptr_ptr.read_pointer).null?)
|
165
|
+
free_memory(DhcpsApi::DHCP_CLIENT_INFO_ARRAY_V4.new(to_free))
|
166
|
+
end
|
167
|
+
raise DhcpsApi::Error.new("Error retrieving clients from subnet '%s'." % [subnet_address], error)
|
168
|
+
end
|
169
|
+
|
170
|
+
leases_array = DhcpsApi::DHCP_CLIENT_INFO_ARRAY_V4.new(client_info_ptr_ptr.read_pointer)
|
171
|
+
leases = leases_array.as_ruby_struct
|
172
|
+
free_memory(leases_array)
|
173
|
+
|
174
|
+
[leases, resume_handle_ptr.get_uint32(0), elements_read_ptr.get_uint32(0), elements_total_ptr.get_uint32(0)]
|
175
|
+
end
|
176
|
+
|
124
177
|
def dhcp_v4_enum_subnet_clients(subnet_address, preferred_maximum, resume_handle)
|
125
178
|
resume_handle_ptr = FFI::MemoryPointer.new(:uint32).put_uint32(0, resume_handle)
|
126
179
|
client_info_ptr_ptr = FFI::MemoryPointer.new(:pointer)
|
@@ -292,18 +292,21 @@ module DhcpsApi
|
|
292
292
|
:classes, :pointer
|
293
293
|
end
|
294
294
|
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
295
|
+
#
|
296
|
+
# DHCP_CLIENT_INFO_V4 defines a client information record used by the DHCP server.
|
297
|
+
#
|
298
|
+
# Available fields:
|
299
|
+
# :client_ip_address [String],
|
300
|
+
# :subnet_mask [String],
|
301
|
+
# :client_hardware_address [String],
|
302
|
+
# :client_name [String],
|
303
|
+
# :client_comment [String],
|
304
|
+
# :client_lease_expires [Date],
|
305
|
+
# :owner_host [DHCP_HOST_INFO],
|
306
|
+
# :client_type, [Fixnum]
|
307
|
+
#
|
308
|
+
# @see https://msdn.microsoft.com/en-us/library/windows/desktop/dd897579(v=vs.85).aspx
|
309
|
+
#
|
307
310
|
class DHCP_CLIENT_INFO_V4 < DHCPS_Struct
|
308
311
|
layout :client_ip_address, :uint32,
|
309
312
|
:subnet_mask, :uint32,
|
@@ -319,6 +322,23 @@ module DhcpsApi
|
|
319
322
|
ruby_struct_attr :to_string, :client_name, :client_comment
|
320
323
|
end
|
321
324
|
|
325
|
+
=begin
|
326
|
+
typedef struct _DHCP_CLIENT_INFO_ARRAY_V4 {
|
327
|
+
DWORD NumElements;
|
328
|
+
LPDHCP_CLIENT_INFO_V4 *Clients;
|
329
|
+
} DHCP_CLIENT_INFO_ARRAY_V4, *LPDHCP_CLIENT_INFO_ARRAY_V4;
|
330
|
+
=end
|
331
|
+
class DHCP_CLIENT_INFO_ARRAY_V4 < DHCPS_Struct
|
332
|
+
layout :num_elements, :uint32,
|
333
|
+
:clients, :pointer
|
334
|
+
|
335
|
+
def as_ruby_struct
|
336
|
+
0.upto(self[:num_elements]-1).inject([]) do |all, offset|
|
337
|
+
all << DHCP_CLIENT_INFO_V4.new((self[:clients] + offset*FFI::Pointer.size).read_pointer).as_ruby_struct
|
338
|
+
end
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
322
342
|
=begin
|
323
343
|
typedef struct _DHCP_CLIENT_SEARCH_INFO {
|
324
344
|
DHCP_SEARCH_INFO_TYPE SearchType;
|
@@ -568,24 +588,27 @@ typedef struct _DHCP_OPTION_ARRAY {
|
|
568
588
|
# Data structures available in Win2012
|
569
589
|
#
|
570
590
|
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
591
|
+
#
|
592
|
+
# DHCP_CLIENT_INFO_V4 defines a client information record used by the DHCP server.
|
593
|
+
#
|
594
|
+
# Available fields:
|
595
|
+
# :client_ip_address [String],
|
596
|
+
# :subnet_mask [String],
|
597
|
+
# :client_hardware_address [String],
|
598
|
+
# :client_name [String],
|
599
|
+
# :client_comment [String],
|
600
|
+
# :client_lease_expires [Date],
|
601
|
+
# :owner_host [DHCP_HOST_INFO],
|
602
|
+
# :client_type, [Fixnum]
|
603
|
+
# :address_state, [Fixnum]
|
604
|
+
# :status, [Fixnum]
|
605
|
+
# :probation_ends, [Date]
|
606
|
+
# :quarantine_capable, [Boolean]
|
607
|
+
# :filter_status, [Fixnum]
|
608
|
+
# :policy_name, [String]
|
609
|
+
#
|
610
|
+
# @see https://msdn.microsoft.com/en-us/library/windows/desktop/hh404371(v=vs.85).aspx
|
611
|
+
#
|
589
612
|
class DHCP_CLIENT_INFO_PB < DhcpsApi::DHCPS_Struct
|
590
613
|
layout :client_ip_address, :uint32,
|
591
614
|
:subnet_mask, :uint32,
|
data/lib/dhcpsapi/version.rb
CHANGED
@@ -4,6 +4,19 @@ module DhcpsApi::Win2008
|
|
4
4
|
ffi_lib 'dhcpsapi'
|
5
5
|
ffi_convention :stdcall
|
6
6
|
|
7
|
+
=begin
|
8
|
+
DWORD DHCP_API_FUNCTION DhcpEnumSubnetClientsV4(
|
9
|
+
_In_ DHCP_CONST WCHAR *ServerIpAddress,
|
10
|
+
_In_ DHCP_IP_ADDRESS SubnetAddress,
|
11
|
+
_Inout_ DHCP_RESUME_HANDLE *ResumeHandle,
|
12
|
+
_In_ DWORD PreferredMaximum,
|
13
|
+
_Out_ LPDHCP_CLIENT_INFO_ARRAY_V4 *ClientInfo,
|
14
|
+
_Out_ DWORD *ClientsRead,
|
15
|
+
_Out_ DWORD *ClientsTotal
|
16
|
+
);
|
17
|
+
=end
|
18
|
+
attach_function :DhcpEnumSubnetClientsV4, [:pointer, :uint32, :pointer, :uint32, :pointer, :pointer, :pointer], :uint32
|
19
|
+
|
7
20
|
=begin
|
8
21
|
DWORD DhcpCreateClientInfoV4(
|
9
22
|
_In_ DHCP_CONST WCHAR *ServerIpAddress,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dhcpsapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitri Dolguikh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|