summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVMware, Inc <>2013-09-17 20:43:28 -0700
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2013-09-22 22:30:01 -0700
commit112e1dfdd1884f189363ce5692c991170b0791fb (patch)
treef5d9e5ae425541fc3367fe91e7d0248a9480169f
parent76713ae5c4d5f7a4616d3005137c276535d654fa (diff)
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 <dtor@vmware.com>
-rw-r--r--open-vm-tools/lib/asyncsocket/asyncsocket.c39
-rw-r--r--open-vm-tools/lib/include/asyncsocket.h5
2 files changed, 20 insertions, 24 deletions
diff --git a/open-vm-tools/lib/asyncsocket/asyncsocket.c b/open-vm-tools/lib/asyncsocket/asyncsocket.c
index c97b6d74..7bdb1196 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 5abcc830..1bf7a40d 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);