Closed jromwu closed 1 year ago
又不是用evutil_sockaddr_cmp方便点?
方便试一下如下改动?
diff --git a/redudp.c b/redudp.c
index d58f9b2..0a851ff 100644
--- a/redudp.c
+++ b/redudp.c
@@ -413,7 +413,10 @@ static void redudp_pkt_from_client(int fd, short what, void *_arg)
// TODO: this lookup may be SLOOOOOW.
list_for_each_entry(tmp, &self->clients, list) {
- if (0 == memcmp(&clientaddr, &tmp->clientaddr, sizeof(clientaddr))) {
+ if (0 == evutil_sockaddr_cmp((struct sockaddr *)&clientaddr,
+ (struct sockaddr *)&tmp->clientaddr,
+ 1)) {
+
client = tmp;
break;
}
Close. Use simplified code.
When comparing the client address, the paddings in the
sockaddr_storage
is also compared as well. Because the paddings are not necessarily zeroed, the comparison can give non-zero result when the addresses are the same. This can cause every single outgoing UDP packet to have different source ports when being proxied.First time contributing to projects, please let me know if I have done anything wrong. Cheers!