@@ -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,11 @@ 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 look if we really just receive the expected package.
93+ UdpOpFlags :: ANY_SRC_PORT
94+ | UdpOpFlags :: ANY_SRC_IP
95+ | UdpOpFlags :: ANY_DEST_PORT
96+ | UdpOpFlags :: ANY_DEST_IP ,
9297 Some ( & mut dest_ip) ,
9398 Some ( & mut dest_port) ,
9499 Some ( & mut src_ip) ,
@@ -104,6 +109,14 @@ pub fn test() {
104109 }
105110 read_result. unwrap ( ) ;
106111
112+ // Check that we indeed received the expected packet.
113+ assert_eq ! ( dest_ip, base_code. mode( ) . station_ip( ) ) ;
114+ assert_eq ! ( src_ip, server_ip) ;
115+ assert_eq ! ( src_port, EXAMPLE_SERVICE_PORT ) ;
116+ // We don't know the dst port here, as it is dynamically handled
117+ // by QEMU/the NIC.
118+ debug ! ( "dest UDP port: {dest_port}" ) ;
119+
107120 // Check the header.
108121 assert_eq ! ( header[ 0 ] as usize , payload. len( ) ) ;
109122 // Check that we receive the reversed payload.
0 commit comments