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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9740f4c12d6acbd2ec1543f1b2df97e2b4ecd80
4
- data.tar.gz: 89ebad17dc6a96c7354a06754dfc79f76d7bde8c
3
+ metadata.gz: 90390bfda1251be29291f1ccc64fae4358333060
4
+ data.tar.gz: e0709a99e9c7996f1de1928226edfa92ff12b6e2
5
5
  SHA512:
6
- metadata.gz: d389e520e1ab8e5e29920b6a29c082f71a4d4b5a42021c4ba201d2ce1a71c7f2c355e9c1b420290d7c8fdd34972d7e25a50dc1e5423a62610133f11f659cc5dd
7
- data.tar.gz: 66f36da0548a51a88bf410f3fb91cce72da8eb5cdf5a8ba0680a051cac1842b7ac04c14b91fc959b4ad0566f5683ebb0842d8233f9ead53a9d88d81db7a3bb9f
6
+ metadata.gz: 8d71ceba9348203e4a045afa1867281575f126430e7473beb40adafee6f3e793ad49dc509dae4875ee54ce3a2c97978339b1ed6d3302e615c02d2050a742127b
7
+ data.tar.gz: 458300694746a914f91580cbcb2ce38f70d931559e69913fef9b237471aacc1821735f1ca1c16da349fef845620664bac9c61a37c5515c876d800a4eabba49fe
@@ -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
- =begin
296
- typedef struct _DHCP_CLIENT_INFO_V4 {
297
- DHCP_IP_ADDRESS ClientIpAddress;
298
- DHCP_IP_MASK SubnetMask;
299
- DHCP_CLIENT_UID ClientHardwareAddress;
300
- LPWSTR ClientName;
301
- LPWSTR ClientComment;
302
- DATE_TIME ClientLeaseExpires;
303
- DHCP_HOST_INFO OwnerHost;
304
- BYTE bClientType;
305
- } DHCP_CLIENT_INFO_V4, *LPDHCP_CLIENT_INFO_V4;
306
- =end
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
- =begin
572
- typedef struct _DHCP_CLIENT_INFO_PB {
573
- DHCP_IP_ADDRESS ClientIpAddress;
574
- DHCP_IP_MASK SubnetMask;
575
- DHCP_CLIENT_UID ClientHardwareAddress;
576
- LPWSTR ClientName;
577
- LPWSTR ClientComment;
578
- DATE_TIME ClientLeaseExpires;
579
- DHCP_HOST_INFO OwnerHost;
580
- BYTE bClientType;
581
- BYTE AddressState;
582
- QuarantineStatus Status;
583
- DATE_TIME ProbationEnds;
584
- BOOL QuarantineCapable;
585
- DWORD FilterStatus;
586
- LPWSTR PolicyName;
587
- } DHCP_CLIENT_INFO_PB, *LPDHCP_CLIENT_INFO_PB;
588
- =end
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,
@@ -1,3 +1,3 @@
1
1
  module DhcpsApi
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -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
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-01 00:00:00.000000000 Z
11
+ date: 2016-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi