Fix monitoring active port logic in forwarder_guest_launcher

Bug: 380785855
Test: Run terminal app and trying port forwarding
Change-Id: I7f08d742ed9eb64fb08dc3c753023d7433374bca
diff --git a/guest/forwarder_guest_launcher/src/main.rs b/guest/forwarder_guest_launcher/src/main.rs
index 16b05b4..545e961 100644
--- a/guest/forwarder_guest_launcher/src/main.rs
+++ b/guest/forwarder_guest_launcher/src/main.rs
@@ -36,6 +36,7 @@
 
 const NON_PREVILEGED_PORT_RANGE_START: i32 = 1024;
 const TCPSTATES_IP_4: i8 = 4;
+const TCPSTATES_STATE_CLOSE: &str = "CLOSE";
 const TCPSTATES_STATE_LISTEN: &str = "LISTEN";
 
 #[derive(Debug, Deserialize)]
@@ -43,7 +44,7 @@
 struct TcpStateRow {
     ip: i8,
     lport: i32,
-    oldstate: String,
+    rport: i32,
     newstate: String,
 }
 
@@ -141,14 +142,17 @@
         if row.lport < NON_PREVILEGED_PORT_RANGE_START {
             continue;
         }
-        match (row.oldstate.as_str(), row.newstate.as_str()) {
-            (_, TCPSTATES_STATE_LISTEN) => {
+        if row.rport > 0 {
+            continue;
+        }
+        match row.newstate.as_str() {
+            TCPSTATES_STATE_LISTEN => {
                 listening_ports.insert(row.lport);
             }
-            (TCPSTATES_STATE_LISTEN, _) => {
+            TCPSTATES_STATE_CLOSE => {
                 listening_ports.remove(&row.lport);
             }
-            (_, _) => continue,
+            _ => continue,
         }
         send_active_ports_report(listening_ports.clone(), &mut client).await?;
     }