# File lib/ohai/plugins/network.rb, line 29
  def sorted_ips(family = "inet")
    raise "bad family #{family}" unless [ "inet", "inet6" ].include? family

    # going to use that later to sort by scope
    scope_prio = [ "global", "site", "link", "host", "node", nil ]

    ipaddresses = []
    # ipaddresses going to hold #{family} ipaddresses and their scope
    Mash[network['interfaces']].each do |iface, iface_v|
      next if iface_v.nil? or not iface_v.has_key? 'addresses'
      iface_v['addresses'].each do |addr, addr_v|
        next if addr_v.nil? or not addr_v.has_key? "family" or addr_v['family'] != family
        ipaddresses <<  {
          :ipaddress => addr_v["prefixlen"] ? IPAddress("#{addr}/#{addr_v["prefixlen"]}") : IPAddress("#{addr}/#{addr_v["netmask"]}"),
          :scope => addr_v["scope"].nil? ? nil : addr_v["scope"].downcase,
          :iface => iface
        }
      end
    end

    # sort ip addresses by scope, by prefixlen and then by ip address
    # 128 - prefixlen: longest prefixes first
    ipaddresses.sort_by do |v|
      [ ( scope_prio.index(v[:scope]) or 999999 ),
        128 - v[:ipaddress].prefix.to_i,
        ( family == "inet" ? v[:ipaddress].to_u32 : v[:ipaddress].to_u128 )
      ]
    end
  end