# File common/lib/symbiosis/host.rb, line 94
    def self.primary_ip(conditions = {})
      interface = self.primary_interface
      
      return nil if interface.nil?

      candidates = []      

      #
      # Select addresses based on conditions
      #
      # We only want the primary interface.
      conditions[:index] = interface.index

      netlink_socket.addr.list(conditions) do |ifaddr|
        next unless 0 == ifaddr.scope

        if ifaddr.respond_to?("local") and ifaddr.local.is_a?(::IPAddr)
          this_ip = IPAddr.new(ifaddr.local.to_s)
        else
          this_ip = IPAddr.new(ifaddr.address.to_s)
        end

        candidates << [this_ip, ifaddr.prefixlen.to_i]
      end

      winner = candidates.inject(nil) do |best, current|
        # If this is the first then return the current  
        if best.nil?
          current
        # IPv4 is preferred to IPv6 
        elsif current[0].ipv4? and best[0].ipv6?
          current 
        # IPv4 is preferred to IPv6 
        elsif current[0].ipv6? and best[0].ipv4?
          best
        # Smaller prefix wins
        elsif current[1] < best[1]
          current
        # Otherwise return the best (This should never happen!)
        else
          best
        end
      end

      return nil if winner.nil? or winner.empty?

      return winner[0]
    end