If multiple friend are behind the same NAT, they may use different
source ports.
static struct cache *ucache;
-struct friend *friend_get_by_address(GInetAddress *address)
+struct friend *friend_get_by_address(GInetAddress *address, uint16_t port)
{
GList *l;
for (l = g_list_first(ucache->friends); l != NULL; l = g_list_next(l)) {
struct friend *friend = l->data;
- if (g_inet_address_equal(g_inet_socket_address_get_address(friend->saddr), address))
+ if (g_inet_address_equal(g_inet_socket_address_get_address(friend->saddr), address) &&
+ friend->port == port)
return friend;
}
return NULL;
int store_cache(struct cache *cache, char *fname);
int friend_send_message(struct friend *friend, char *buffer, size_t len);
-struct friend *friend_get_by_address(GInetAddress *address);
+struct friend *friend_get_by_address(GInetAddress *address, uint16_t port);
char *friend_get_name();
command(buffer, len);
} else {
struct friend *friend;
- friend = friend_get_by_address(iaddress);
+ uint16_t port = g_inet_socket_address_get_port(G_INET_SOCKET_ADDRESS(address));
+ friend = friend_get_by_address(iaddress, port);
if (friend) {
printf("got message from %s\n", friend_get_name(friend));
g_source_remove_by_user_data(friend);