From: VMware, Inc <> Date: Fri, 12 Apr 2013 19:54:38 +0000 (-0700) Subject: Export local and remote VMCI address info from AsyncSocket. X-Git-Tag: 2013.04.16-1098359~17 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3729c475fd7bef4ed27679b0e34c4ea790fbdc4e;p=thirdparty%2Fopen-vm-tools.git Export local and remote VMCI address info from AsyncSocket. I need this information to look up vSocket IDs after a resume, but this will also be necessary to determine if the peer is a privileged socket (bound to a port less than 1024). Signed-off-by: Dmitry Torokhov --- diff --git a/open-vm-tools/lib/asyncsocket/asyncSocketInt.h b/open-vm-tools/lib/asyncsocket/asyncSocketInt.h index b70880b3b..6a0732fab 100644 --- a/open-vm-tools/lib/asyncsocket/asyncSocketInt.h +++ b/open-vm-tools/lib/asyncsocket/asyncSocketInt.h @@ -182,6 +182,8 @@ struct AsyncSocket { void *errorClientData; VmTimeType drainTimeoutUS; + struct sockaddr localAddr; + socklen_t localAddrLen; struct sockaddr remoteAddr; socklen_t remoteAddrLen; diff --git a/open-vm-tools/lib/asyncsocket/asyncsocket.c b/open-vm-tools/lib/asyncsocket/asyncsocket.c index e29feeda1..8375c8c45 100644 --- a/open-vm-tools/lib/asyncsocket/asyncsocket.c +++ b/open-vm-tools/lib/asyncsocket/asyncsocket.c @@ -395,6 +395,88 @@ AsyncSocket_GetRemoteIPAddress(AsyncSocket *asock, // IN } +/* + *---------------------------------------------------------------------------- + * + * AsyncSocket_GetLocalVMCIAddress -- + * + * Given an AsyncSocket object, returns the local VMCI context ID and + * port number associated with it, or an error if the request is + * meaningless for the underlying connection. + * + * Results: + * ASOCKERR_SUCCESS or ASOCKERR_GENERIC. + * + * Side effects: + * + * + *---------------------------------------------------------------------------- + */ + +int +AsyncSocket_GetLocalVMCIAddress(AsyncSocket *asock, // IN + uint32 *cid, // OUT: optional + uint32 *port) // OUT: optional +{ + ASSERT(asock); + + if (asock->localAddrLen != sizeof(struct sockaddr_vm)) { + return ASOCKERR_GENERIC; + } + + if (cid != NULL) { + *cid = ((struct sockaddr_vm *)&asock->localAddr)->svm_cid; + } + + if (port != NULL) { + *port = ((struct sockaddr_vm *)&asock->localAddr)->svm_port; + } + + return ASOCKERR_SUCCESS; +} + + +/* + *---------------------------------------------------------------------------- + * + * AsyncSocket_GetRemoteVMCIAddress -- + * + * Given an AsyncSocket object, returns the remote VMCI context ID and + * port number associated with it, or an error if the request is + * meaningless for the underlying connection. + * + * Results: + * ASOCKERR_SUCCESS or ASOCKERR_GENERIC. + * + * Side effects: + * + * + *---------------------------------------------------------------------------- + */ + +int +AsyncSocket_GetRemoteVMCIAddress(AsyncSocket *asock, // IN + uint32 *cid, // OUT: optional + uint32 *port) // OUT: optional +{ + ASSERT(asock); + + if (asock->remoteAddrLen != sizeof(struct sockaddr_vm)) { + return ASOCKERR_GENERIC; + } + + if (cid != NULL) { + *cid = ((struct sockaddr_vm *)&asock->remoteAddr)->svm_cid; + } + + if (port != NULL) { + *port = ((struct sockaddr_vm *)&asock->remoteAddr)->svm_port; + } + + return ASOCKERR_SUCCESS; +} + + /* *---------------------------------------------------------------------------- * diff --git a/open-vm-tools/lib/include/asyncsocket.h b/open-vm-tools/lib/include/asyncsocket.h index 86c52e333..6c4c2ba9b 100644 --- a/open-vm-tools/lib/include/asyncsocket.h +++ b/open-vm-tools/lib/include/asyncsocket.h @@ -165,6 +165,11 @@ int AsyncSocket_GetRemoteIPAddress(AsyncSocket *asock, unsigned int *ip, const char **ipStr); +int AsyncSocket_GetLocalVMCIAddress(AsyncSocket *asock, + uint32 *cid, uint32 *port); +int AsyncSocket_GetRemoteVMCIAddress(AsyncSocket *asock, + uint32 *cid, uint32 *port); + /* * Recv callback fires once previously requested data has been received */