aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Kiszka <jan.kiszka@siemens.com>2009-06-24 14:42:28 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-06-29 08:52:45 -0500
commit2ad82cf9e2c2adad874fbecabd48e1cf699b7c84 (patch)
tree40bb9e99f838c248e941642b4fd970fbb5db3263
parentc92ef6a22d3c71538fcc48fb61ad353f7ba03b62 (diff)
slirp: Fix port comparision in slirp_remove_hostfwd
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 <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r--slirp/slirp.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/slirp/slirp.c b/slirp/slirp.c
index a918232034..ad88121c2c 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++;