aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slirp.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/slirp.c b/slirp.c
index f39e6ff..f3d5824 100644
--- a/slirp.c
+++ b/slirp.c
@@ -763,12 +763,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++;