qemu-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-commits] [COMMIT 2ad82cf] slirp: Fix port comparision in slirp_rem


From: Anthony Liguori
Subject: [Qemu-commits] [COMMIT 2ad82cf] slirp: Fix port comparision in slirp_remove_hostfwd
Date: Tue, 30 Jun 2009 00:57:28 -0000

From: Jan Kiszka <address@hidden>

For UDP host forwardings, fport is not stable, every outgoing packet of
the redirection can modify it. Use getsockname instead to look up the
port that is actually used on the host side.

Signed-off-by: Jan Kiszka <address@hidden>
Signed-off-by: Anthony Liguori <address@hidden>

diff --git a/slirp/slirp.c b/slirp/slirp.c
index a918232..ad88121 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -761,12 +761,16 @@ int slirp_remove_hostfwd(int is_udp, int host_port)
 {
     struct socket *so;
     struct socket *head = (is_udp ? &udb : &tcb);
-    int fport = htons(host_port);
+    struct sockaddr_in addr;
+    int port = htons(host_port);
+    socklen_t addr_len;
     int n = 0;
 
  loop_again:
     for (so = head->so_next; so != head; so = so->so_next) {
-        if (so->so_fport == fport) {
+        addr_len = sizeof(addr);
+        if (getsockname(so->s, (struct sockaddr *)&addr, &addr_len) == 0 &&
+            addr.sin_port == port) {
             close(so->s);
             sofree(so);
             n++;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]