dhcpsapi 0.0.7 → 0.0.8
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.rb +1 -0
 - data/lib/dhcpsapi/data_structures.rb +69 -1
 - data/lib/dhcpsapi/reservation.rb +12 -27
 - data/lib/dhcpsapi/server.rb +5 -3
 - data/lib/dhcpsapi/subnet.rb +3 -23
 - data/lib/dhcpsapi/subnet_element.rb +85 -0
 - data/lib/dhcpsapi/version.rb +1 -1
 - data/lib/dhcpsapi/win2008/subnet_element.rb +15 -0
 - metadata +3 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 8aa52005e543e55ac0af399ce937ade44dbfe74a
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: acaade242dcd8c290c26c056a4933f71199d3e05
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: ba5318e348a9936bc493bd711a73ccbcd8df4d7ef76fba6578dd4d0aaad7074d23e5a02b00cbef36ebf9252fa2ff9ceae534bcc329c58d4cb1c6a93788ddee48
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 35894f52b25644e6a9b3795e8fafc17b84b56f175b8552f2f6dcb1c071899d22c9918585e8f149f2ceb151ee00ccc0d4a8cc28ad53f6657363c68307b9191702
         
     | 
    
        data/lib/dhcpsapi.rb
    CHANGED
    
    
| 
         @@ -522,6 +522,11 @@ typedef struct _DHCP_OPTION_ARRAY { 
     | 
|
| 
       522 
522 
     | 
    
         
             
                layout :reserved_ip_address, :uint32,
         
     | 
| 
       523 
523 
     | 
    
         
             
                       :reserved_for_client, :pointer,
         
     | 
| 
       524 
524 
     | 
    
         
             
                       :b_allowed_client_types, :uint8 # see ClientType
         
     | 
| 
      
 525 
     | 
    
         
            +
             
     | 
| 
      
 526 
     | 
    
         
            +
                ruby_struct_attr :uint32_to_ip, :reserved_ip_address
         
     | 
| 
      
 527 
     | 
    
         
            +
                def reserved_for_client_as_ruby_struct_attr
         
     | 
| 
      
 528 
     | 
    
         
            +
                  DHCP_CLIENT_UID.new(self[:reserved_for_client]).as_ruby_struct
         
     | 
| 
      
 529 
     | 
    
         
            +
                end
         
     | 
| 
       525 
530 
     | 
    
         
             
              end
         
     | 
| 
       526 
531 
     | 
    
         | 
| 
       527 
532 
     | 
    
         
             
            =begin
         
     | 
| 
         @@ -547,6 +552,69 @@ typedef struct _DHCP_OPTION_ARRAY { 
     | 
|
| 
       547 
552 
     | 
    
         
             
              class DHCP_SUBNET_ELEMENT_DATA_V4 < DHCPS_Struct
         
     | 
| 
       548 
553 
     | 
    
         
             
                layout :element_type, :uint32,
         
     | 
| 
       549 
554 
     | 
    
         
             
                       :element, DHCP_SUBNET_ELEMENT
         
     | 
| 
      
 555 
     | 
    
         
            +
             
     | 
| 
      
 556 
     | 
    
         
            +
                def self.build_for_reservation(reservation_ip, reservation_mac, client_type = DhcpsApi::ClientType::CLIENT_TYPE_DHCP)
         
     | 
| 
      
 557 
     | 
    
         
            +
                  subnet_element = DhcpsApi::DHCP_SUBNET_ELEMENT_DATA_V4.new
         
     | 
| 
      
 558 
     | 
    
         
            +
                  subnet_element[:element_type] = DhcpsApi::DHCP_SUBNET_ELEMENT_TYPE::DhcpReservedIps
         
     | 
| 
      
 559 
     | 
    
         
            +
                  subnet_element[:element][:reserved_ip] = (reserved_ip = DhcpsApi::DHCP_IP_RESERVATION_V4.new).pointer
         
     | 
| 
      
 560 
     | 
    
         
            +
             
     | 
| 
      
 561 
     | 
    
         
            +
                  reserved_ip[:reserved_ip_address] = reserved_ip.ip_to_uint32(reservation_ip)
         
     | 
| 
      
 562 
     | 
    
         
            +
                  reserved_ip[:reserved_for_client] = DhcpsApi::DHCP_CLIENT_UID.from_mac_address(reservation_mac).pointer
         
     | 
| 
      
 563 
     | 
    
         
            +
                  reserved_ip[:b_allowed_client_types] = client_type
         
     | 
| 
      
 564 
     | 
    
         
            +
             
     | 
| 
      
 565 
     | 
    
         
            +
                  subnet_element
         
     | 
| 
      
 566 
     | 
    
         
            +
                end
         
     | 
| 
      
 567 
     | 
    
         
            +
             
     | 
| 
      
 568 
     | 
    
         
            +
                def self.build_for_subnet_range(start_ip_address, end_ip_address)
         
     | 
| 
      
 569 
     | 
    
         
            +
                  subnet_element = DhcpsApi::DHCP_SUBNET_ELEMENT_DATA_V4.new
         
     | 
| 
      
 570 
     | 
    
         
            +
                  subnet_element[:element_type] = DhcpsApi::DHCP_SUBNET_ELEMENT_TYPE::DhcpIpRanges
         
     | 
| 
      
 571 
     | 
    
         
            +
                  subnet_element[:element][:ip_range] = (ip_range = DhcpsApi::DHCP_IP_RANGE.new).pointer
         
     | 
| 
      
 572 
     | 
    
         
            +
                  ip_range[:start_address] = ip_range.ip_to_uint32(start_ip_address)
         
     | 
| 
      
 573 
     | 
    
         
            +
                  ip_range[:end_address] = ip_range.ip_to_uint32(end_ip_address)
         
     | 
| 
      
 574 
     | 
    
         
            +
             
     | 
| 
      
 575 
     | 
    
         
            +
                  subnet_element
         
     | 
| 
      
 576 
     | 
    
         
            +
                end
         
     | 
| 
      
 577 
     | 
    
         
            +
             
     | 
| 
      
 578 
     | 
    
         
            +
                def element_as_ruby_struct_attr
         
     | 
| 
      
 579 
     | 
    
         
            +
                  case self[:element_type]
         
     | 
| 
      
 580 
     | 
    
         
            +
                    when DHCP_SUBNET_ELEMENT_TYPE::DhcpIpRanges
         
     | 
| 
      
 581 
     | 
    
         
            +
                      DHCP_IP_RANGE.new(self[:element][:ip_range]).as_ruby_struct
         
     | 
| 
      
 582 
     | 
    
         
            +
                    when DHCP_SUBNET_ELEMENT_TYPE::DhcpSecondaryHosts
         
     | 
| 
      
 583 
     | 
    
         
            +
                      DHCP_HOST_INFO.new(self[:element][:secondary_host]).as_ruby_struct
         
     | 
| 
      
 584 
     | 
    
         
            +
                    when DHCP_SUBNET_ELEMENT_TYPE::DhcpReservedIps
         
     | 
| 
      
 585 
     | 
    
         
            +
                      DHCP_IP_RESERVATION_V4.new(self[:element][:reserved_ip]).as_ruby_struct
         
     | 
| 
      
 586 
     | 
    
         
            +
                    when DHCP_SUBNET_ELEMENT_TYPE::DhcpExcludedIpRanges
         
     | 
| 
      
 587 
     | 
    
         
            +
                      DHCP_IP_RANGE.new(self[:element][:exclude_ip_range]).as_ruby_struct
         
     | 
| 
      
 588 
     | 
    
         
            +
                    else
         
     | 
| 
      
 589 
     | 
    
         
            +
                      self[:element]
         
     | 
| 
      
 590 
     | 
    
         
            +
                  end
         
     | 
| 
      
 591 
     | 
    
         
            +
                end
         
     | 
| 
      
 592 
     | 
    
         
            +
              end
         
     | 
| 
      
 593 
     | 
    
         
            +
             
     | 
| 
      
 594 
     | 
    
         
            +
            =begin
         
     | 
| 
      
 595 
     | 
    
         
            +
              typedef struct _DHCP_SUBNET_ELEMENT_INFO_ARRAY_V4 {
         
     | 
| 
      
 596 
     | 
    
         
            +
                DWORD                         NumElements;
         
     | 
| 
      
 597 
     | 
    
         
            +
                LPDHCP_SUBNET_ELEMENT_DATA_V4 Elements;
         
     | 
| 
      
 598 
     | 
    
         
            +
              } DHCP_SUBNET_ELEMENT_INFO_ARRAY_V4, *LPDHCP_SUBNET_ELEMENT_INFO_ARRAY_V4;
         
     | 
| 
      
 599 
     | 
    
         
            +
            =end
         
     | 
| 
      
 600 
     | 
    
         
            +
              #
         
     | 
| 
      
 601 
     | 
    
         
            +
              # DHCP_SUBNET_ELEMENT_INFO_ARRAY_V4 defines a list of DHCP subnet elements.
         
     | 
| 
      
 602 
     | 
    
         
            +
              #
         
     | 
| 
      
 603 
     | 
    
         
            +
              # Available fields:
         
     | 
| 
      
 604 
     | 
    
         
            +
              # :bum_elements [Fixnum], The number of option values in the list
         
     | 
| 
      
 605 
     | 
    
         
            +
              # :values [Array<DHCP_SUBNET_ELEMENT_DATA_V4>], Array of subnet elements
         
     | 
| 
      
 606 
     | 
    
         
            +
              #
         
     | 
| 
      
 607 
     | 
    
         
            +
              # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ee460931(v=vs.85).aspx
         
     | 
| 
      
 608 
     | 
    
         
            +
              #
         
     | 
| 
      
 609 
     | 
    
         
            +
              class DHCP_SUBNET_ELEMENT_INFO_ARRAY_V4 < DHCPS_Struct
         
     | 
| 
      
 610 
     | 
    
         
            +
                layout :num_elements, :uint32,
         
     | 
| 
      
 611 
     | 
    
         
            +
                       :values, :pointer
         
     | 
| 
      
 612 
     | 
    
         
            +
             
     | 
| 
      
 613 
     | 
    
         
            +
                def as_ruby_struct
         
     | 
| 
      
 614 
     | 
    
         
            +
                  0.upto(self[:num_elements]-1).inject([]) do |all, offset|
         
     | 
| 
      
 615 
     | 
    
         
            +
                    all << DhcpsApi::DHCP_SUBNET_ELEMENT_DATA_V4.new(self[:values] + offset*DHCP_SUBNET_ELEMENT_DATA_V4.size).as_ruby_struct
         
     | 
| 
      
 616 
     | 
    
         
            +
                  end
         
     | 
| 
      
 617 
     | 
    
         
            +
                end
         
     | 
| 
       550 
618 
     | 
    
         
             
              end
         
     | 
| 
       551 
619 
     | 
    
         | 
| 
       552 
620 
     | 
    
         
             
            =begin
         
     | 
| 
         @@ -581,7 +649,7 @@ typedef struct _DHCP_OPTION_ARRAY { 
     | 
|
| 
       581 
649 
     | 
    
         
             
                layout :start_address, :uint32,
         
     | 
| 
       582 
650 
     | 
    
         
             
                       :end_address, :uint32
         
     | 
| 
       583 
651 
     | 
    
         | 
| 
       584 
     | 
    
         
            -
                ruby_struct_attr :uint32_to_ip, : 
     | 
| 
      
 652 
     | 
    
         
            +
                ruby_struct_attr :uint32_to_ip, :start_address, :end_address
         
     | 
| 
       585 
653 
     | 
    
         
             
              end
         
     | 
| 
       586 
654 
     | 
    
         | 
| 
       587 
655 
     | 
    
         
             
            #
         
     | 
    
        data/lib/dhcpsapi/reservation.rb
    CHANGED
    
    | 
         @@ -38,24 +38,14 @@ module DhcpsApi 
     | 
|
| 
       38 
38 
     | 
    
         
             
                # @see ClientType ClientType documentation for the list of available client types.
         
     | 
| 
       39 
39 
     | 
    
         
             
                #
         
     | 
| 
       40 
40 
     | 
    
         
             
                def create_reservation(reservation_ip, reservation_subnet_mask, reservation_mac, reservation_name, reservation_comment = '', client_type = DhcpsApi::ClientType::CLIENT_TYPE_DHCP)
         
     | 
| 
       41 
     | 
    
         
            -
                  subnet_element = DhcpsApi::DHCP_SUBNET_ELEMENT_DATA_V4.new
         
     | 
| 
       42 
     | 
    
         
            -
                  subnet_element[:element_type] = DhcpsApi::DHCP_SUBNET_ELEMENT_TYPE::DhcpReservedIps
         
     | 
| 
       43 
     | 
    
         
            -
                  subnet_element[:element][:reserved_ip] = (reserved_ip = DhcpsApi::DHCP_IP_RESERVATION_V4.new).pointer
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
                  reserved_ip[:reserved_ip_address] = ip_to_uint32(reservation_ip)
         
     | 
| 
       46 
     | 
    
         
            -
                  reserved_ip[:reserved_for_client] = DhcpsApi::DHCP_CLIENT_UID.from_mac_address(reservation_mac).pointer
         
     | 
| 
       47 
     | 
    
         
            -
                  reserved_ip[:b_allowed_client_types] = client_type
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
41 
     | 
    
         
             
                  ip_as_octets = reservation_ip.split('.').map {|octet| octet.to_i}
         
     | 
| 
       50 
42 
     | 
    
         
             
                  mask_as_octets = reservation_subnet_mask.split('.').map {|octet| octet.to_i}
         
     | 
| 
       51 
43 
     | 
    
         
             
                  subnet_address = (0..3).inject([]) {|all, i| all << (ip_as_octets[i] & mask_as_octets[i])}.join('.')
         
     | 
| 
       52 
44 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
                   
     | 
| 
       54 
     | 
    
         
            -
                  raise DhcpsApi::Error.new("Error creating reservation.", error) if error != 0
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
      
 45 
     | 
    
         
            +
                  subnet_element = create_reservation_subnet_element(subnet_address, reservation_ip, reservation_mac, client_type)
         
     | 
| 
       56 
46 
     | 
    
         
             
                  modify_client(reservation_ip, reservation_subnet_mask, reservation_mac, reservation_name, reservation_comment, 0, client_type)
         
     | 
| 
       57 
47 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
                  subnet_element 
     | 
| 
      
 48 
     | 
    
         
            +
                  subnet_element
         
     | 
| 
       59 
49 
     | 
    
         
             
                end
         
     | 
| 
       60 
50 
     | 
    
         | 
| 
       61 
51 
     | 
    
         
             
                # Deletes subnet reservations.
         
     | 
| 
         @@ -70,21 +60,9 @@ module DhcpsApi 
     | 
|
| 
       70 
60 
     | 
    
         
             
                #
         
     | 
| 
       71 
61 
     | 
    
         
             
                # @return [void]
         
     | 
| 
       72 
62 
     | 
    
         
             
                #
         
     | 
| 
       73 
     | 
    
         
            -
                def delete_reservation(reservation_ip, subnet_address, reservation_mac)
         
     | 
| 
       74 
     | 
    
         
            -
                   
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
                  to_delete[:element][:reserved_ip] = (reserved_ip = DhcpsApi::DHCP_IP_RESERVATION_V4.new).pointer
         
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
                  reserved_ip[:reserved_ip_address] = ip_to_uint32(reservation_ip)
         
     | 
| 
       79 
     | 
    
         
            -
                  reserved_ip[:reserved_for_client] = DhcpsApi::DHCP_CLIENT_UID.from_mac_address(reservation_mac).pointer
         
     | 
| 
       80 
     | 
    
         
            -
                  reserved_ip[:b_allowed_client_types] = DhcpsApi::ClientType::CLIENT_TYPE_NONE
         
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
                  error = DhcpsApi::Win2008::SubnetElement.DhcpRemoveSubnetElementV4(
         
     | 
| 
       83 
     | 
    
         
            -
                      to_wchar_string(server_ip_address),
         
     | 
| 
       84 
     | 
    
         
            -
                      ip_to_uint32(subnet_address),
         
     | 
| 
       85 
     | 
    
         
            -
                      to_delete.pointer,
         
     | 
| 
       86 
     | 
    
         
            -
                      DhcpsApi::DHCP_FORCE_FLAG::DhcpNoForce)
         
     | 
| 
       87 
     | 
    
         
            -
                  raise DhcpsApi::Error.new("Error deleting reservation.", error) if error != 0
         
     | 
| 
      
 63 
     | 
    
         
            +
                def delete_reservation(reservation_ip, subnet_address, reservation_mac, client_type = DhcpsApi::ClientType::CLIENT_TYPE_DHCP)
         
     | 
| 
      
 64 
     | 
    
         
            +
                  delete_subnet_element(subnet_address, DhcpsApi::DHCP_SUBNET_ELEMENT_DATA_V4.build_for_reservation(
         
     | 
| 
      
 65 
     | 
    
         
            +
                      reservation_ip, reservation_mac, client_type))
         
     | 
| 
       88 
66 
     | 
    
         
             
                end
         
     | 
| 
       89 
67 
     | 
    
         | 
| 
       90 
68 
     | 
    
         
             
                # Sets dns configuration for a reservation.
         
     | 
| 
         @@ -115,6 +93,13 @@ module DhcpsApi 
     | 
|
| 
       115 
93 
     | 
    
         
             
                  set_reserved_option_value(81, reservation_ip, subnet_address, DhcpsApi::DHCP_OPTION_DATA_TYPE::DhcpDWordOption, [value])
         
     | 
| 
       116 
94 
     | 
    
         
             
                end
         
     | 
| 
       117 
95 
     | 
    
         | 
| 
      
 96 
     | 
    
         
            +
                def create_reservation_subnet_element(subnet_address, reservation_ip_address, reservation_mac_address, client_type = DhcpsApi::ClientType::CLIENT_TYPE_DHCP)
         
     | 
| 
      
 97 
     | 
    
         
            +
                  add_subnet_element(subnet_address,
         
     | 
| 
      
 98 
     | 
    
         
            +
                                     DhcpsApi::DHCP_SUBNET_ELEMENT_DATA_V4.build_for_reservation(
         
     | 
| 
      
 99 
     | 
    
         
            +
                                         reservation_ip_address, reservation_mac_address, client_type)
         
     | 
| 
      
 100 
     | 
    
         
            +
                  )
         
     | 
| 
      
 101 
     | 
    
         
            +
                end
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
       118 
103 
     | 
    
         
             
                def dhcp_v4_enum_subnet_reservations(subnet_address, preferred_maximum, resume_handle)
         
     | 
| 
       119 
104 
     | 
    
         
             
                  resume_handle_ptr = FFI::MemoryPointer.new(:uint32).put_uint32(0, resume_handle)
         
     | 
| 
       120 
105 
     | 
    
         
             
                  enum_element_info_ptr_ptr = FFI::MemoryPointer.new(:pointer)
         
     | 
    
        data/lib/dhcpsapi/server.rb
    CHANGED
    
    | 
         @@ -1,8 +1,8 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module DhcpsApi
         
     | 
| 
       2 
2 
     | 
    
         
             
              class Server
         
     | 
| 
       3 
     | 
    
         
            -
                DHCPS_WIN2008_API = Object 
     | 
| 
       4 
     | 
    
         
            -
                DHCPS_WIN2012_API = Object 
     | 
| 
       5 
     | 
    
         
            -
                DHCPS_NONE = Object 
     | 
| 
      
 3 
     | 
    
         
            +
                DHCPS_WIN2008_API = Object.new
         
     | 
| 
      
 4 
     | 
    
         
            +
                DHCPS_WIN2012_API = Object.new
         
     | 
| 
      
 5 
     | 
    
         
            +
                DHCPS_NONE = Object.new
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
                include RubyStructAttrHelpers
         
     | 
| 
       8 
8 
     | 
    
         
             
                include CommonMethods
         
     | 
| 
         @@ -14,6 +14,7 @@ module DhcpsApi 
     | 
|
| 
       14 
14 
     | 
    
         
             
                include OptionValue
         
     | 
| 
       15 
15 
     | 
    
         
             
                include Reservation
         
     | 
| 
       16 
16 
     | 
    
         
             
                include Subnet
         
     | 
| 
      
 17 
     | 
    
         
            +
                include SubnetElement
         
     | 
| 
       17 
18 
     | 
    
         | 
| 
       18 
19 
     | 
    
         
             
                attr_reader :server_ip_address
         
     | 
| 
       19 
20 
     | 
    
         | 
| 
         @@ -32,6 +33,7 @@ module DhcpsApi 
     | 
|
| 
       32 
33 
     | 
    
         
             
                  require 'dhcpsapi/win2008/option_value'
         
     | 
| 
       33 
34 
     | 
    
         
             
                  require 'dhcpsapi/win2008/subnet_element'
         
     | 
| 
       34 
35 
     | 
    
         
             
                  require 'dhcpsapi/win2008/subnet'
         
     | 
| 
      
 36 
     | 
    
         
            +
                  require 'dhcpsapi/win2008/subnet_element'
         
     | 
| 
       35 
37 
     | 
    
         | 
| 
       36 
38 
     | 
    
         
             
                  level = :win2008
         
     | 
| 
       37 
39 
     | 
    
         | 
    
        data/lib/dhcpsapi/subnet.rb
    CHANGED
    
    | 
         @@ -83,17 +83,8 @@ module DhcpsApi 
     | 
|
| 
       83 
83 
     | 
    
         
             
                # @return [Hash]
         
     | 
| 
       84 
84 
     | 
    
         
             
                #
         
     | 
| 
       85 
85 
     | 
    
         
             
                # @see DHCP_SUBNET_ELEMENT_DATA_V4 DHCP_SUBNET_ELEMENT_DATA_V4 documentation for the list of available fields.
         
     | 
| 
       86 
     | 
    
         
            -
                def  
     | 
| 
       87 
     | 
    
         
            -
                   
     | 
| 
       88 
     | 
    
         
            -
                  subnet_element[:element_type] = DhcpsApi::DHCP_SUBNET_ELEMENT_TYPE::DhcpIpRanges
         
     | 
| 
       89 
     | 
    
         
            -
                  subnet_element[:element][:ip_range] = (ip_range = DhcpsApi::DHCP_IP_RANGE.new).pointer
         
     | 
| 
       90 
     | 
    
         
            -
                  ip_range[:start_address] = ip_to_uint32(start_address)
         
     | 
| 
       91 
     | 
    
         
            -
                  ip_range[:end_address] = ip_to_uint32(end_address)
         
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
                  error = DhcpsApi::Win2008::SubnetElement.DhcpAddSubnetElementV4(to_wchar_string(server_ip_address), ip_to_uint32(subnet_address), subnet_element.pointer)
         
     | 
| 
       94 
     | 
    
         
            -
                  raise DhcpsApi::Error.new("Error adding a subnet range to '%s'." % [subnet_address], error) if error != 0
         
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
                  subnet_element.as_ruby_struct
         
     | 
| 
      
 86 
     | 
    
         
            +
                def create_subnet_ip_range(subnet_address, start_address, end_address)
         
     | 
| 
      
 87 
     | 
    
         
            +
                  add_subnet_element(subnet_address, DhcpsApi::DHCP_SUBNET_ELEMENT_DATA_V4.build_for_subnet_range(start_address, end_address))
         
     | 
| 
       97 
88 
     | 
    
         
             
                end
         
     | 
| 
       98 
89 
     | 
    
         | 
| 
       99 
90 
     | 
    
         
             
                # Deletes a subnet ip address range.
         
     | 
| 
         @@ -108,18 +99,7 @@ module DhcpsApi 
     | 
|
| 
       108 
99 
     | 
    
         
             
                #
         
     | 
| 
       109 
100 
     | 
    
         
             
                # @return [void]
         
     | 
| 
       110 
101 
     | 
    
         
             
                def delete_subnet_ip_range(subnet_address, start_address, end_address)
         
     | 
| 
       111 
     | 
    
         
            -
                   
     | 
| 
       112 
     | 
    
         
            -
                  to_delete[:element_type] = DhcpsApi::DHCP_SUBNET_ELEMENT_TYPE::DhcpIpRanges
         
     | 
| 
       113 
     | 
    
         
            -
                  to_delete[:element][:ip_range] = (ip_range = DhcpsApi::DHCP_IP_RANGE.new).pointer
         
     | 
| 
       114 
     | 
    
         
            -
                  ip_range[:start_address] = ip_to_uint32(start_address)
         
     | 
| 
       115 
     | 
    
         
            -
                  ip_range[:end_address] = ip_to_uint32(end_address)
         
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
       117 
     | 
    
         
            -
                  error = DhcpsApi::Win2008::SubnetElement.DhcpRemoveSubnetElementV4(
         
     | 
| 
       118 
     | 
    
         
            -
                      to_wchar_string(server_ip_address),
         
     | 
| 
       119 
     | 
    
         
            -
                      ip_to_uint32(subnet_address),
         
     | 
| 
       120 
     | 
    
         
            -
                      to_delete.pointer,
         
     | 
| 
       121 
     | 
    
         
            -
                      DhcpsApi::DHCP_FORCE_FLAG::DhcpNoForce)
         
     | 
| 
       122 
     | 
    
         
            -
                  raise DhcpsApi::Error.new("Error deleting reservation.", error) if error != 0
         
     | 
| 
      
 102 
     | 
    
         
            +
                  delete_subnet_element(subnet_address, DhcpsApi::DHCP_SUBNET_ELEMENT_DATA_V4.build_for_subnet_range(start_address, end_address))
         
     | 
| 
       123 
103 
     | 
    
         
             
                end
         
     | 
| 
       124 
104 
     | 
    
         | 
| 
       125 
105 
     | 
    
         
             
                private
         
     | 
| 
         @@ -0,0 +1,85 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module DhcpsApi
         
     | 
| 
      
 2 
     | 
    
         
            +
              module SubnetElement
         
     | 
| 
      
 3 
     | 
    
         
            +
                # Returns a a list of subnet elements.
         
     | 
| 
      
 4 
     | 
    
         
            +
                #
         
     | 
| 
      
 5 
     | 
    
         
            +
                # @example List subnet elements
         
     | 
| 
      
 6 
     | 
    
         
            +
                #
         
     | 
| 
      
 7 
     | 
    
         
            +
                # api.list_subnet_elements('192.168.42.0', DhcpsApi::DHCP_SUBNET_ELEMENT_TYPE::DhcpReservedIps)
         
     | 
| 
      
 8 
     | 
    
         
            +
                #
         
     | 
| 
      
 9 
     | 
    
         
            +
                # @param subnet_address [String] Subnet ip address
         
     | 
| 
      
 10 
     | 
    
         
            +
                # @param element_type [DHCP_SUBNET_ELEMENT_TYPE] Subnet element type
         
     | 
| 
      
 11 
     | 
    
         
            +
                #
         
     | 
| 
      
 12 
     | 
    
         
            +
                # @return [Array<Hash>]
         
     | 
| 
      
 13 
     | 
    
         
            +
                #
         
     | 
| 
      
 14 
     | 
    
         
            +
                # @see DHCP_SUBNET_ELEMENT_DATA_V4 DHCP_SUBNET_ELEMENT_DATA_V4 documentation for the list of available fields.
         
     | 
| 
      
 15 
     | 
    
         
            +
                #
         
     | 
| 
      
 16 
     | 
    
         
            +
                def list_subnet_elements(subnet_address, element_type)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  items, _ = retrieve_items(:dhcp_enum_subnet_elements_v4, subnet_address, element_type, 1024, 0)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  items
         
     | 
| 
      
 19 
     | 
    
         
            +
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                # Creates a new subnet element.
         
     | 
| 
      
 22 
     | 
    
         
            +
                #
         
     | 
| 
      
 23 
     | 
    
         
            +
                # @example Create a new subnet element
         
     | 
| 
      
 24 
     | 
    
         
            +
                #
         
     | 
| 
      
 25 
     | 
    
         
            +
                # api.add_subnet_element('192.168.42.0', a_subnet_element)
         
     | 
| 
      
 26 
     | 
    
         
            +
                #
         
     | 
| 
      
 27 
     | 
    
         
            +
                # @param subnet_ip_address [String] Subnet ip address
         
     | 
| 
      
 28 
     | 
    
         
            +
                # @param subnet_element [DHCP_SUBNET_ELEMENT_DATA_V4] Subnet element
         
     | 
| 
      
 29 
     | 
    
         
            +
                #
         
     | 
| 
      
 30 
     | 
    
         
            +
                # @return [Hash]
         
     | 
| 
      
 31 
     | 
    
         
            +
                #
         
     | 
| 
      
 32 
     | 
    
         
            +
                # @see DHCP_SUBNET_ELEMENT_DATA_V4 DHCP_SUBNET_ELEMENT_DATA_V4 documentation for the list of available fields.
         
     | 
| 
      
 33 
     | 
    
         
            +
                #
         
     | 
| 
      
 34 
     | 
    
         
            +
                def add_subnet_element(subnet_address, subnet_element)
         
     | 
| 
      
 35 
     | 
    
         
            +
                  error = DhcpsApi::Win2008::SubnetElement.DhcpAddSubnetElementV4(to_wchar_string(server_ip_address), ip_to_uint32(subnet_address), subnet_element.pointer)
         
     | 
| 
      
 36 
     | 
    
         
            +
                  raise DhcpsApi::Error.new("Error creating subnet element.", error) if error != 0
         
     | 
| 
      
 37 
     | 
    
         
            +
                  subnet_element.as_ruby_struct
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                # Deletes subnet element.
         
     | 
| 
      
 41 
     | 
    
         
            +
                #
         
     | 
| 
      
 42 
     | 
    
         
            +
                # @example Delete a subnet element
         
     | 
| 
      
 43 
     | 
    
         
            +
                #
         
     | 
| 
      
 44 
     | 
    
         
            +
                # api.delete_subnet_element('192.168.42.0', an_existing_subnet_element)
         
     | 
| 
      
 45 
     | 
    
         
            +
                #
         
     | 
| 
      
 46 
     | 
    
         
            +
                # @param subnet_ip_address [String] Subnet ip address
         
     | 
| 
      
 47 
     | 
    
         
            +
                # @param subnet_element [DHCP_SUBNET_ELEMENT_DATA_V4] Subnet element
         
     | 
| 
      
 48 
     | 
    
         
            +
                #
         
     | 
| 
      
 49 
     | 
    
         
            +
                # @return [void]
         
     | 
| 
      
 50 
     | 
    
         
            +
                #
         
     | 
| 
      
 51 
     | 
    
         
            +
                def delete_subnet_element(subnet_address, subnet_element)
         
     | 
| 
      
 52 
     | 
    
         
            +
                  error = DhcpsApi::Win2008::SubnetElement.DhcpRemoveSubnetElementV4(
         
     | 
| 
      
 53 
     | 
    
         
            +
                      to_wchar_string(server_ip_address),
         
     | 
| 
      
 54 
     | 
    
         
            +
                      ip_to_uint32(subnet_address),
         
     | 
| 
      
 55 
     | 
    
         
            +
                      subnet_element.pointer,
         
     | 
| 
      
 56 
     | 
    
         
            +
                      DhcpsApi::DHCP_FORCE_FLAG::DhcpNoForce)
         
     | 
| 
      
 57 
     | 
    
         
            +
                  raise DhcpsApi::Error.new("Error deleting subnet element.", error) if error != 0
         
     | 
| 
      
 58 
     | 
    
         
            +
                end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                def dhcp_enum_subnet_elements_v4(subnet_address, element_type, preferred_maximum, resume_handle)
         
     | 
| 
      
 61 
     | 
    
         
            +
                  resume_handle_ptr = FFI::MemoryPointer.new(:uint32).put_uint32(0, resume_handle)
         
     | 
| 
      
 62 
     | 
    
         
            +
                  subnet_element_info_ptr_ptr = FFI::MemoryPointer.new(:pointer)
         
     | 
| 
      
 63 
     | 
    
         
            +
                  elements_read_ptr = FFI::MemoryPointer.new(:uint32).put_uint32(0, 0)
         
     | 
| 
      
 64 
     | 
    
         
            +
                  elements_total_ptr = FFI::MemoryPointer.new(:uint32).put_uint32(0, 0)
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                  error = DhcpsApi::Win2008::SubnetElement.DhcpEnumSubnetElementsV4(
         
     | 
| 
      
 67 
     | 
    
         
            +
                      to_wchar_string(server_ip_address), ip_to_uint32(subnet_address), element_type, resume_handle_ptr, preferred_maximum,
         
     | 
| 
      
 68 
     | 
    
         
            +
                      subnet_element_info_ptr_ptr, elements_read_ptr, elements_total_ptr)
         
     | 
| 
      
 69 
     | 
    
         
            +
                  return empty_response if error == 259
         
     | 
| 
      
 70 
     | 
    
         
            +
                  if is_error?(error)
         
     | 
| 
      
 71 
     | 
    
         
            +
                    unless (subnet_element_info_ptr_ptr.null? || (to_free = subnet_element_info_ptr_ptr.read_pointer).null?)
         
     | 
| 
      
 72 
     | 
    
         
            +
                      free_memory(DhcpsApi::DHCP_SUBNET_ELEMENT_INFO_ARRAY_V4.new(to_free))
         
     | 
| 
      
 73 
     | 
    
         
            +
                    end
         
     | 
| 
      
 74 
     | 
    
         
            +
                    raise DhcpsApi::Error.new("Error retrieving subnet elements for subnet '%s'." % [subnet_address], error)
         
     | 
| 
      
 75 
     | 
    
         
            +
                  end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                  subnet_elements_array = DhcpsApi::DHCP_SUBNET_ELEMENT_INFO_ARRAY_V4.new(subnet_element_info_ptr_ptr.read_pointer)
         
     | 
| 
      
 78 
     | 
    
         
            +
                  subnet_elements = subnet_elements_array.as_ruby_struct
         
     | 
| 
      
 79 
     | 
    
         
            +
                  free_memory(subnet_elements_array)
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                  [subnet_elements, resume_handle_ptr.get_uint32(0), elements_read_ptr.get_uint32(0), elements_total_ptr.get_uint32(0)]
         
     | 
| 
      
 82 
     | 
    
         
            +
                end
         
     | 
| 
      
 83 
     | 
    
         
            +
              end
         
     | 
| 
      
 84 
     | 
    
         
            +
            end
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
    
        data/lib/dhcpsapi/version.rb
    CHANGED
    
    
| 
         @@ -22,5 +22,20 @@ module DhcpsApi::Win2008 
     | 
|
| 
       22 
22 
     | 
    
         
             
              );
         
     | 
| 
       23 
23 
     | 
    
         
             
            =end
         
     | 
| 
       24 
24 
     | 
    
         
             
                attach_function :DhcpRemoveSubnetElementV4, [:pointer, :uint32, :pointer, :uint32], :uint32
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
            =begin
         
     | 
| 
      
 27 
     | 
    
         
            +
            DWORD DHCP_API_FUNCTION DhcpEnumSubnetElementsV4(
         
     | 
| 
      
 28 
     | 
    
         
            +
              _In_    DHCP_CONST WCHAR                    *ServerIpAddress,
         
     | 
| 
      
 29 
     | 
    
         
            +
              _In_    DHCP_IP_ADDRESS                     SubnetAddress,
         
     | 
| 
      
 30 
     | 
    
         
            +
              _In_    DHCP_SUBNET_ELEMENT_TYPE            EnumElementType,
         
     | 
| 
      
 31 
     | 
    
         
            +
              _Inout_ DHCP_RESUME_HANDLE                  *ResumeHandle,
         
     | 
| 
      
 32 
     | 
    
         
            +
              _In_    DWORD                               PreferredMaximum,
         
     | 
| 
      
 33 
     | 
    
         
            +
              _Out_   LPDHCP_SUBNET_ELEMENT_INFO_ARRAY_V4 *EnumElementInfo,
         
     | 
| 
      
 34 
     | 
    
         
            +
              _Out_   DWORD                               *ElementsRead,
         
     | 
| 
      
 35 
     | 
    
         
            +
              _Out_   DWORD                               *ElementsTotal
         
     | 
| 
      
 36 
     | 
    
         
            +
            );
         
     | 
| 
      
 37 
     | 
    
         
            +
            =end
         
     | 
| 
      
 38 
     | 
    
         
            +
                attach_function :DhcpEnumSubnetElementsV4, [:pointer, :uint32, :uint32, :pointer, :uint32, :pointer, :pointer, :pointer], :uint32
         
     | 
| 
       25 
39 
     | 
    
         
             
              end
         
     | 
| 
       26 
40 
     | 
    
         
             
            end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
    
        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.8
         
     | 
| 
       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-10- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2016-10-13 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: ffi
         
     | 
| 
         @@ -88,6 +88,7 @@ files: 
     | 
|
| 
       88 
88 
     | 
    
         
             
            - lib/dhcpsapi/reservation.rb
         
     | 
| 
       89 
89 
     | 
    
         
             
            - lib/dhcpsapi/server.rb
         
     | 
| 
       90 
90 
     | 
    
         
             
            - lib/dhcpsapi/subnet.rb
         
     | 
| 
      
 91 
     | 
    
         
            +
            - lib/dhcpsapi/subnet_element.rb
         
     | 
| 
       91 
92 
     | 
    
         
             
            - lib/dhcpsapi/version.rb
         
     | 
| 
       92 
93 
     | 
    
         
             
            - lib/dhcpsapi/win2008/class.rb
         
     | 
| 
       93 
94 
     | 
    
         
             
            - lib/dhcpsapi/win2008/client.rb
         
     |