Fix IpV6 link local address connections

Paho currently successfully resolves IPv6 link-local addresses (of the
form `tcp://[xxxx::xxxx:xxxx:xxxx%eth0]:1883`). But it does not copy
the resolved link information over when attempting to make the
connection.

This is a 3-line fix.

See: https://github.com/eclipse/paho.mqtt.c/issues/1464
This commit is contained in:
Kilian von Pflugk 2024-04-10 19:11:18 +02:00
parent bcbe0f10ae
commit ab2f7373e5
1 changed files with 4 additions and 1 deletions

View File

@ -1131,7 +1131,10 @@ int Socket_new(const char* addr, size_t addr_len, int port, SOCKET* sock)
{
address6.sin6_port = htons(port);
address6.sin6_family = family = AF_INET6;
memcpy(&address6.sin6_addr, &((struct sockaddr_in6*)(res->ai_addr))->sin6_addr, sizeof(address6.sin6_addr));
struct sockaddr_in6* res6 = (struct sockaddr_in6*)(res->ai_addr);
memcpy(&address6.sin6_addr, &res6->sin6_addr, sizeof(address6.sin6_addr));
memcpy(&address6.sin6_scope_id, &res6->sin6_scope_id, sizeof(address6.sin6_scope_id));
memcpy(&address6.sin6_flowinfo, &res6->sin6_flowinfo, sizeof(address6.sin6_flowinfo));
}
else
#endif