@@ -76,10 +76,11 @@ pub fn test() {
7676
7777 info ! ( "Reading UDP packet from example service" ) ;
7878
79- let mut src_ip = server_ip;
80- let mut src_port = EXAMPLE_SERVICE_PORT ;
81- let mut dest_ip = base_code. mode ( ) . station_ip ( ) ;
82- let mut dest_port = write_src_port;
79+ // Used as buffers
80+ let mut src_ip = IpAddress :: new_v4 ( [ 0 ; 4 ] ) ;
81+ let mut src_port = 0 ;
82+ let mut dest_ip = IpAddress :: new_v4 ( [ 0 ; 4 ] ) ;
83+ let mut dest_port = 0 ;
8384 let mut header = [ 0 ; 1 ] ;
8485 let mut received = [ 0 ; 4 ] ;
8586
@@ -88,7 +89,12 @@ pub fn test() {
8889 let mut read_result = Ok ( 0 ) ;
8990 for i in 0 ..5 {
9091 read_result = base_code. udp_read (
91- UdpOpFlags :: USE_FILTER ,
92+ // We expect exactly one packet but accept all to catch
93+ // unexpected network traffic.
94+ UdpOpFlags :: ANY_SRC_PORT
95+ | UdpOpFlags :: ANY_SRC_IP
96+ | UdpOpFlags :: ANY_DEST_PORT
97+ | UdpOpFlags :: ANY_DEST_IP ,
9298 Some ( & mut dest_ip) ,
9399 Some ( & mut dest_port) ,
94100 Some ( & mut src_ip) ,
@@ -104,6 +110,14 @@ pub fn test() {
104110 }
105111 read_result. unwrap ( ) ;
106112
113+ // Check that we indeed received the expected packet.
114+ assert_eq ! ( dest_ip, base_code. mode( ) . station_ip( ) ) ;
115+ assert_eq ! ( src_ip, server_ip) ;
116+ assert_eq ! ( src_port, EXAMPLE_SERVICE_PORT ) ;
117+ // We don't know the dst port here, as it is dynamically handled
118+ // by QEMU/the NIC.
119+ debug ! ( "dest UDP port: {dest_port}" ) ;
120+
107121 // Check the header.
108122 assert_eq ! ( header[ 0 ] as usize , payload. len( ) ) ;
109123 // Check that we receive the reversed payload.
0 commit comments