Commit 575a975f authored by Ian Craggs's avatar Ian Craggs

Fix for IPv6 support - issue https://github.com/eclipse/paho.mqtt.c/issues/7

Bug: 484496
parent 1c376fe3
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* Contributors: * Contributors:
* Ian Craggs - initial API and implementation and/or initial documentation * Ian Craggs - initial API and implementation and/or initial documentation
* Ian Craggs - async client updates * Ian Craggs - async client updates
* Ian Craggs - fix for bug 484496
*******************************************************************************/ *******************************************************************************/
/** /**
...@@ -73,8 +74,8 @@ int pstopen(void **handle, const char* clientID, const char* serverURI, void* co ...@@ -73,8 +74,8 @@ int pstopen(void **handle, const char* clientID, const char* serverURI, void* co
/* Note that serverURI=address:port, but ":" not allowed in Windows directories */ /* Note that serverURI=address:port, but ":" not allowed in Windows directories */
perserverURI = malloc(strlen(serverURI) + 1); perserverURI = malloc(strlen(serverURI) + 1);
strcpy(perserverURI, serverURI); strcpy(perserverURI, serverURI);
ptraux = strstr(perserverURI, ":"); while ((ptraux = strstr(perserverURI, ":")) != NULL)
*ptraux = '-' ; *ptraux = '-' ;
/* consider '/' + '-' + '\0' */ /* consider '/' + '-' + '\0' */
clientDir = malloc(strlen(dataDir) + strlen(clientID) + strlen(perserverURI) + 3); clientDir = malloc(strlen(dataDir) + strlen(clientID) + strlen(perserverURI) + 3);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* Contributors: * Contributors:
* Ian Craggs - initial implementation and documentation * Ian Craggs - initial implementation and documentation
* Ian Craggs - async client updates * Ian Craggs - async client updates
* Ian Craggs - fix for bug 484496
*******************************************************************************/ *******************************************************************************/
/** /**
...@@ -600,6 +601,7 @@ int Socket_new(char* addr, int port, int* sock) ...@@ -600,6 +601,7 @@ int Socket_new(char* addr, int port, int* sock)
FUNC_ENTRY; FUNC_ENTRY;
*sock = -1; *sock = -1;
memset(&address6, '\0', sizeof(address6));
if (addr[0] == '[') if (addr[0] == '[')
++addr; ++addr;
...@@ -608,14 +610,10 @@ int Socket_new(char* addr, int port, int* sock) ...@@ -608,14 +610,10 @@ int Socket_new(char* addr, int port, int* sock)
{ {
struct addrinfo* res = result; struct addrinfo* res = result;
/* prefer ip4 addresses */
while (res) while (res)
{ { /* prefer ip4 addresses */
if (res->ai_family == AF_INET) if (res->ai_family == AF_INET || res->ai_next == NULL)
{
result = res;
break; break;
}
res = res->ai_next; res = res->ai_next;
} }
...@@ -627,7 +625,7 @@ int Socket_new(char* addr, int port, int* sock) ...@@ -627,7 +625,7 @@ int Socket_new(char* addr, int port, int* sock)
{ {
address6.sin6_port = htons(port); address6.sin6_port = htons(port);
address6.sin6_family = family = AF_INET6; address6.sin6_family = family = AF_INET6;
address6.sin6_addr = ((struct sockaddr_in6*)(result->ai_addr))->sin6_addr; memcpy(&address6.sin6_addr, &((struct sockaddr_in6*)(res->ai_addr))->sin6_addr, sizeof(address6.sin6_addr));
} }
else else
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment