@@ -103,16 +103,16 @@ impl RawConnection {
103
103
}
104
104
}
105
105
106
- pub fn get_protocol ( & self ) -> Protocol {
107
- Protocol :: from_str ( & self . protocol ) . unwrap ( )
106
+ pub fn get_protocol ( & self ) -> Option < Protocol > {
107
+ Protocol :: from_str ( & self . protocol )
108
108
}
109
109
110
- pub fn get_local_ip ( & self ) -> IpAddr {
111
- self . local_ip . parse ( ) . unwrap ( )
110
+ pub fn get_local_ip ( & self ) -> Option < IpAddr > {
111
+ self . local_ip . parse ( ) . ok ( )
112
112
}
113
113
114
- pub fn get_local_port ( & self ) -> u16 {
115
- self . local_port . parse :: < u16 > ( ) . unwrap ( )
114
+ pub fn get_local_port ( & self ) -> Option < u16 > {
115
+ self . local_port . parse :: < u16 > ( ) . ok ( )
116
116
}
117
117
}
118
118
@@ -203,7 +203,7 @@ com.apple 590 etoledom 204u IPv4 0x28ffb9c04111253f 0t0 TCP 192.168.1.
203
203
}
204
204
fn test_raw_connection_parse_local_port ( raw_output : & str ) {
205
205
let connection = RawConnection :: new ( raw_output) . unwrap ( ) ;
206
- assert_eq ! ( connection. get_local_port( ) , 1111 ) ;
206
+ assert_eq ! ( connection. get_local_port( ) , Some ( 1111 ) ) ;
207
207
}
208
208
209
209
#[ test]
@@ -216,7 +216,7 @@ com.apple 590 etoledom 204u IPv4 0x28ffb9c04111253f 0t0 TCP 192.168.1.
216
216
}
217
217
fn test_raw_connection_parse_protocol ( raw_line : & str ) {
218
218
let connection = RawConnection :: new ( raw_line) . unwrap ( ) ;
219
- assert_eq ! ( connection. get_protocol( ) , Protocol :: Udp ) ;
219
+ assert_eq ! ( connection. get_protocol( ) , Some ( Protocol :: Udp ) ) ;
220
220
}
221
221
222
222
#[ test]
0 commit comments