File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -153,6 +153,7 @@ unsafe fn parse_diag_msg(
153153 } ) ,
154154 associated_pids : Vec :: with_capacity ( 0 ) ,
155155 inode : diag_msg. inode ,
156+ uid : diag_msg. uid ,
156157 } ,
157158 IPPROTO_UDP => SocketInfo {
158159 protocol_socket_info : ProtocolSocketInfo :: Udp ( UdpSocketInfo {
@@ -161,6 +162,7 @@ unsafe fn parse_diag_msg(
161162 } ) ,
162163 associated_pids : Vec :: with_capacity ( 0 ) ,
163164 inode : diag_msg. inode ,
165+ uid : diag_msg. uid ,
164166 } ,
165167 _ => return Err ( Error :: UnknownProtocol ( protocol) ) ,
166168 } ;
Original file line number Diff line number Diff line change @@ -9,7 +9,11 @@ pub struct SocketInfo {
99 /// Identifiers of processes associated with this socket.
1010 pub associated_pids : Vec < u32 > ,
1111 #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
12+ /// Inode number of this socket.
1213 pub inode : u32 ,
14+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
15+ /// Owner UID of this socket.
16+ pub uid : u32 ,
1317}
1418
1519/// Protocol-specific socket information.
@@ -37,3 +41,21 @@ pub struct UdpSocketInfo {
3741 pub local_addr : IpAddr ,
3842 pub local_port : u16 ,
3943}
44+
45+ impl SocketInfo {
46+ /// Local address of this socket.
47+ pub fn local_addr ( & self ) -> IpAddr {
48+ match & self . protocol_socket_info {
49+ ProtocolSocketInfo :: Tcp ( s) => s. local_addr ,
50+ ProtocolSocketInfo :: Udp ( s) => s. local_addr ,
51+ }
52+ }
53+
54+ /// Local port of this socket.
55+ pub fn local_port ( & self ) -> u16 {
56+ match & self . protocol_socket_info {
57+ ProtocolSocketInfo :: Tcp ( s) => s. local_port ,
58+ ProtocolSocketInfo :: Udp ( s) => s. local_port ,
59+ }
60+ }
61+ }
You can’t perform that action at this time.
0 commit comments