You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: network_util.rb
    path of file: ./repos/vagrant-libvirt/lib/vagrant-libvirt/util
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

require 'ipaddr'
require 'nokogiri'
require 'vagrant/util/network_ip'
require 'vagrant/util/scoped_hash_override'

class IPAddr
  def get_mask
    if @addr
      _to_string(@mask_addr)
    end
  end
end

module VagrantPlugins
  module ProviderLibvirt
    module Util
      module NetworkUtil
        include Vagrant::Util::NetworkIP
        include Vagrant::Util::ScopedHashOverride

        def network_interfaces(machine, logger)
          # Setup list of interfaces before creating them.
          adapters = []

          # Vagrant gives you adapter 0 by default
          # Assign interfaces to slots.
          configured_networks(machine, logger).each do |options|
            # don't need to create interface for this type
            next if options[:iface_type] == :forwarded_port

            # TODO: fill first ifaces with adapter option specified.
            if options[:adapter]
              if adapters[options[:adapter]]
                raise Errors::InterfaceSlotNotAvailable
              end

              free_slot = options[:adapter].to_i
              @logger.debug "Using specified adapter slot #{free_slot}"
            else
              free_slot = find_empty(adapters, 0, machine.provider_config.nic_adapter_count)
              @logger.debug "Adapter not specified so found slot #{free_slot}"
              raise Errors::Inte
    
        def libvirt_networks(driver)
          libvirt_networks = []

          # Iterate over all (active and inactive) networks.
          driver.list_all_networks.each do |libvirt_network|

            # Parse ip address and netmask from the network xml description.
            xml = Nokogiri::XML(libvirt_network.xml_desc)
            ip = xml.xpath('/network/ip/@address').first
            ip = ip.value if ip
            netmask = xml.xpath('/network/ip/@netmask').first
            netmask = netmask.value if netmask

            dhcp_enabled = if xml.at_xpath('//network/ip/dhcp')
                             true
                           else
                             false
                           end

            domain_name = xml.at_xpath('/network/domain/@name')
            domain_name = domain_name.value if domain_name

            # Calculate network address of network from ip address and
            # netmask.
            network_address = (network_address(ip, netmask) if ip && netmask)

            libvirt_networks << {
              name:             libvirt_network.name,
              ip_address:       ip,
              netmask:          netmask,
              network_address:  network_address,
              dhcp_enabled:     dhcp_enabled,
              bridge_name:      libvirt_network.bridge_name,
              domain_name:      domain_name,
              created:          true,
              active:           libvirt_network.active?,
              autostart:        libvirt_network.autostart?,
              libvirt_network:  libvirt_network
            }
          end

          libvirt_networks
        end

        def find_empty(array, start, stop)
          (start..stop).each do |i|
            return i unless array[i]
          end
          nil
        end

        # Return network name according to interface options.
        def interface_network(driver, options)
          # no need to get interface network for tcp tunnel config
          return 'tunnel_interface' if options.fetch(:tunnel_type, nil)

          if options[:network_name]
            @logger.debug 'Found network by name'
            return options[:network_name]
          end

          # Get list of all (active and inactive) Libvirt networks.
          available_networks = libvirt_networks(driver)

          return 'public' if options[:iface_type] == :public_network

          if options[:ip]
            address = network_address(options[:ip], options[:netmask])
            available_networks.each do |network|
              if address == network[:network_address]
                @logger.debug 'Found network by ip'
                return network[:name]
              end
            end