@@ -2,7 +2,7 @@ use crate::integrations::linux::netlink_iterator::*;
22use crate :: integrations:: linux:: procfs:: * ;
33use crate :: types:: error:: Error ;
44use crate :: types:: * ;
5- use libc :: * ;
5+ use netlink_packet_sock_diag :: { AF_INET , AF_INET6 , IPPROTO_TCP , IPPROTO_UDP } ;
66
77/// Iterate through sockets information.
88pub fn iterate_sockets_info (
@@ -25,22 +25,20 @@ pub fn iterate_sockets_info_without_pids(
2525 let tcp = proto_flags. contains ( ProtocolFlags :: TCP ) ;
2626 let udp = proto_flags. contains ( ProtocolFlags :: UDP ) ;
2727 let mut iterators = Vec :: with_capacity ( 4 ) ;
28- unsafe {
29- if ipv4 {
30- if tcp {
31- iterators. push ( NetlinkIterator :: new ( AF_INET as u8 , IPPROTO_TCP as u8 ) ?) ;
32- }
33- if udp {
34- iterators. push ( NetlinkIterator :: new ( AF_INET as u8 , IPPROTO_UDP as u8 ) ?) ;
35- }
28+ if ipv4 {
29+ if tcp {
30+ iterators. push ( NetlinkIterator :: new ( AF_INET as u8 , IPPROTO_TCP as u8 ) ?) ;
3631 }
37- if ipv6 {
38- if tcp {
39- iterators. push ( NetlinkIterator :: new ( AF_INET6 as u8 , IPPROTO_TCP as u8 ) ?) ;
40- }
41- if udp {
42- iterators. push ( NetlinkIterator :: new ( AF_INET6 as u8 , IPPROTO_UDP as u8 ) ?) ;
43- }
32+ if udp {
33+ iterators. push ( NetlinkIterator :: new ( AF_INET as u8 , IPPROTO_UDP as u8 ) ?) ;
34+ }
35+ }
36+ if ipv6 {
37+ if tcp {
38+ iterators. push ( NetlinkIterator :: new ( AF_INET6 as u8 , IPPROTO_TCP as u8 ) ?) ;
39+ }
40+ if udp {
41+ iterators. push ( NetlinkIterator :: new ( AF_INET6 as u8 , IPPROTO_UDP as u8 ) ?) ;
4442 }
4543 }
4644 Ok ( iterators. into_iter ( ) . flatten ( ) )
0 commit comments