From: VMware, Inc <> Date: Wed, 18 Sep 2013 03:43:28 +0000 (-0700) Subject: AsyncSocket: Update AsyncSocket_GetRemoteIPAddress for IPv6 support. X-Git-Tag: 2013.09.16-1328054~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=112e1dfdd1884f189363ce5692c991170b0791fb;p=thirdparty%2Fopen-vm-tools.git AsyncSocket: Update AsyncSocket_GetRemoteIPAddress for IPv6 support. AsyncSocket_GetRemoteIPAddress offered the return of the IP in integer and string formats, none of the callers cared for the integer return so remove it. Update name appropriately AsyncSocket_GetRemoteIPAddress->AsyncSocket_GetRemoteIPStr. AsyncSocket_GetRemoteIPAddress only supported the returning of a IPv4 string, utilize Posix_GetNameInfo that uses getnameinfo which is IPv6 compliant. Signed-off-by: Dmitry Torokhov --- diff --git a/open-vm-tools/lib/asyncsocket/asyncsocket.c b/open-vm-tools/lib/asyncsocket/asyncsocket.c index c97b6d743..7bdb11966 100644 --- a/open-vm-tools/lib/asyncsocket/asyncsocket.c +++ b/open-vm-tools/lib/asyncsocket/asyncsocket.c @@ -376,7 +376,7 @@ AsyncSocket_GetFd(AsyncSocket *s) /* *---------------------------------------------------------------------------- * - * AsyncSocket_GetRemoteIPAddress -- + * AsyncSocket_GetRemoteIPStr -- * * Given an AsyncSocket object, returns the remote IP address associated * with it, or an error if the request is meaningless for the underlying @@ -392,35 +392,32 @@ AsyncSocket_GetFd(AsyncSocket *s) */ int -AsyncSocket_GetRemoteIPAddress(AsyncSocket *asock, // IN - uint32 *ipRet, // OUT - const char **ipRetStr) // OUT +AsyncSocket_GetRemoteIPStr(AsyncSocket *asock, // IN + const char **ipRetStr) // OUT { - uint32 ip; - struct in_addr ipAddr; + int ret = ASOCKERR_SUCCESS; ASSERT(asock); ASSERT(asock->asockType != ASYNCSOCKET_TYPE_NAMEDPIPE); - ASSERT(ipRet != NULL || ipRetStr != NULL); + ASSERT(ipRetStr != NULL); - if ((ipRet == NULL && ipRetStr == NULL) || asock == NULL || + if (ipRetStr == NULL || asock == NULL || asock->state != AsyncSocketConnected || - asock->remoteAddrLen != sizeof (struct sockaddr_in)) { - return ASOCKERR_GENERIC; - } - - ip = ntohl(((struct sockaddr_in *) &asock->remoteAddr)->sin_addr.s_addr); - - if (ipRet != NULL) { - *ipRet = ip; - } + (asock->remoteAddrLen != sizeof (struct sockaddr_in) && + asock->remoteAddrLen != sizeof (struct sockaddr_in6))) { + ret = ASOCKERR_GENERIC; + } else { + char addrBuf[NI_MAXHOST]; - if (ipRetStr != NULL) { - ipAddr.s_addr = htonl(ip); - *ipRetStr = inet_ntoa(ipAddr); + if (Posix_GetNameInfo(&asock->remoteAddr, asock->remoteAddrLen, addrBuf, + sizeof addrBuf, NULL, 0, NI_NUMERICHOST) != 0) { + ret = ASOCKERR_GENERIC; + } else { + *ipRetStr = Util_SafeStrdup(addrBuf); + } } - return ASOCKERR_SUCCESS; + return ret; } diff --git a/open-vm-tools/lib/include/asyncsocket.h b/open-vm-tools/lib/include/asyncsocket.h index 5abcc8305..1bf7a40da 100644 --- a/open-vm-tools/lib/include/asyncsocket.h +++ b/open-vm-tools/lib/include/asyncsocket.h @@ -155,9 +155,8 @@ int AsyncSocket_GetFd(AsyncSocket *asock); /* * Return the remote IP address associated with this socket if applicable */ -int AsyncSocket_GetRemoteIPAddress(AsyncSocket *asock, - unsigned int *ip, - const char **ipStr); +int AsyncSocket_GetRemoteIPStr(AsyncSocket *asock, + const char **ipStr); int AsyncSocket_GetLocalVMCIAddress(AsyncSocket *asock, uint32 *cid, uint32 *port);