@@ -5,7 +5,7 @@ use local_ip_address::list_afinet_netifas;
55use serde:: Serialize ;
66use snafu:: { ResultExt , Snafu } ;
77use std:: {
8- collections:: { BTreeSet , HashMap } ,
8+ collections:: { BTreeMap , BTreeSet } ,
99 net:: IpAddr ,
1010 sync:: LazyLock ,
1111 time:: Duration ,
@@ -42,16 +42,16 @@ static GLOBAL_DNS_RESOLVER: LazyLock<Option<TokioResolver>> = LazyLock::new(|| {
4242/// and the results of reverse and forward DNS lookups.
4343#[ derive( Debug , Serialize ) ]
4444pub struct SystemNetworkInfo {
45- pub interfaces : HashMap < String , Vec < IpAddr > > ,
46- pub reverse_lookups : HashMap < IpAddr , Vec < String > > ,
47- pub forward_lookups : HashMap < String , Vec < IpAddr > > ,
45+ pub interfaces : BTreeMap < String , Vec < IpAddr > > ,
46+ pub reverse_lookups : BTreeMap < IpAddr , Vec < String > > ,
47+ pub forward_lookups : BTreeMap < String , Vec < IpAddr > > ,
4848}
4949
5050impl SystemNetworkInfo {
5151 #[ tracing:: instrument( name = "SystemNetworkInfo::collect" ) ]
5252 pub async fn collect ( ) -> Result < SystemNetworkInfo , Error > {
5353 let netifs = list_afinet_netifas ( ) . context ( ListInterfacesSnafu ) ?;
54- let mut interfaces = HashMap :: new ( ) ;
54+ let mut interfaces = BTreeMap :: new ( ) ;
5555
5656 // Iterate over the network interfaces and group them by name
5757 // An interface may appear multiple times if it has multiple IP addresses (e.g. IPv4 and IPv6)
@@ -73,16 +73,16 @@ impl SystemNetworkInfo {
7373 let Some ( resolver) = GLOBAL_DNS_RESOLVER . as_ref ( ) else {
7474 return Ok ( SystemNetworkInfo {
7575 interfaces,
76- reverse_lookups : HashMap :: new ( ) ,
77- forward_lookups : HashMap :: new ( ) ,
76+ reverse_lookups : BTreeMap :: new ( ) ,
77+ forward_lookups : BTreeMap :: new ( ) ,
7878 } ) ;
7979 } ;
8080
8181 let mut reverse_lookup_tasks = JoinSet :: new ( ) ;
8282 for ip in ips {
8383 reverse_lookup_tasks. spawn ( async move { ( ip, resolver. reverse_lookup ( ip) . await ) } ) ;
8484 }
85- let reverse_lookups: HashMap < IpAddr , Vec < String > > = reverse_lookup_tasks
85+ let reverse_lookups: BTreeMap < IpAddr , Vec < String > > = reverse_lookup_tasks
8686 . join_all ( )
8787 . await
8888 . into_iter ( )
@@ -114,7 +114,7 @@ impl SystemNetworkInfo {
114114 forward_lookup_tasks
115115 . spawn ( async move { ( hostname. clone ( ) , resolver. lookup_ip ( hostname) . await ) } ) ;
116116 }
117- let forward_lookups: HashMap < String , Vec < IpAddr > > = forward_lookup_tasks
117+ let forward_lookups: BTreeMap < String , Vec < IpAddr > > = forward_lookup_tasks
118118 . join_all ( )
119119 . await
120120 . into_iter ( )
0 commit comments