From: Oliver Kurth Date: Tue, 26 May 2020 22:32:57 +0000 (-0700) Subject: Common source file changes not directly applicable to open-vm-tools. X-Git-Tag: stable-11.2.0~197 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34d7c760709cec8938488d1c60831960bc30441d;p=thirdparty%2Fopen-vm-tools.git Common source file changes not directly applicable to open-vm-tools. --- diff --git a/open-vm-tools/lib/asyncsocket/asyncSocketInterface.c b/open-vm-tools/lib/asyncsocket/asyncSocketInterface.c index db2d7b738..fdf45a930 100644 --- a/open-vm-tools/lib/asyncsocket/asyncSocketInterface.c +++ b/open-vm-tools/lib/asyncsocket/asyncSocketInterface.c @@ -242,6 +242,40 @@ AsyncSocket_GetRemoteIPStr(AsyncSocket *asock, // IN } +/* + *---------------------------------------------------------------------------- + * + * AsyncSocket_GetRemotePort -- + * + * Given an AsyncSocket object, returns the remote port associated + * with it, or an error if the request is meaningless for the underlying + * connection. + * + * Results: + * ASOCKERR_SUCCESS or ASOCKERR_INVAL. + * + * Side effects: + * + * + *---------------------------------------------------------------------------- + */ + +int +AsyncSocket_GetRemotePort(AsyncSocket *asock, // IN + uint32 *port) // OUT +{ + int ret; + if (VALID(asock, getRemotePort)) { + AsyncSocketLock(asock); + ret = VT(asock)->getRemotePort(asock, port); + AsyncSocketUnlock(asock); + } else { + ret = ASOCKERR_INVAL; + } + return ret; +} + + /* *---------------------------------------------------------------------------- * diff --git a/open-vm-tools/lib/asyncsocket/asyncSocketVTable.h b/open-vm-tools/lib/asyncsocket/asyncSocketVTable.h index 6c50c2fdf..24784ef22 100644 --- a/open-vm-tools/lib/asyncsocket/asyncSocketVTable.h +++ b/open-vm-tools/lib/asyncsocket/asyncSocketVTable.h @@ -81,6 +81,7 @@ typedef struct AsyncSocketVTable { int (*getGenericErrno)(AsyncSocket *s); int (*getFd)(AsyncSocket *asock); int (*getRemoteIPStr)(AsyncSocket *asock, const char **ipStr); + int (*getRemotePort)(AsyncSocket *asock, uint32 *port); int (*getINETIPStr)(AsyncSocket *asock, int socketFamily, char **ipRetStr); unsigned int (*getPort)(AsyncSocket *asock); int (*setCloseOptions)(AsyncSocket *asock, int flushEnabledMaxWaitMsec, diff --git a/open-vm-tools/lib/asyncsocket/asyncsocket.c b/open-vm-tools/lib/asyncsocket/asyncsocket.c index bc5c9c6eb..b043ea4de 100644 --- a/open-vm-tools/lib/asyncsocket/asyncsocket.c +++ b/open-vm-tools/lib/asyncsocket/asyncsocket.c @@ -309,6 +309,7 @@ static int AsyncTCPSocketWaitForConnection(AsyncSocket *s, int timeoutMS); static int AsyncTCPSocketGetGenericErrno(AsyncSocket *s); static int AsyncTCPSocketGetFd(AsyncSocket *asock); static int AsyncTCPSocketGetRemoteIPStr(AsyncSocket *asock, const char **ipStr); +static int AsyncTCPSocketGetRemotePort(AsyncSocket *asock, uint32 *port); static int AsyncTCPSocketGetINETIPStr(AsyncSocket *asock, int socketFamily, char **ipRetStr); static unsigned int AsyncTCPSocketGetPort(AsyncSocket *asock); @@ -386,6 +387,7 @@ static const AsyncSocketVTable asyncTCPSocketVTable = { AsyncTCPSocketGetGenericErrno, AsyncTCPSocketGetFd, AsyncTCPSocketGetRemoteIPStr, + AsyncTCPSocketGetRemotePort, AsyncTCPSocketGetINETIPStr, AsyncTCPSocketGetPort, AsyncTCPSocketSetCloseOptions, @@ -744,6 +746,46 @@ AsyncTCPSocketGetRemoteIPStr(AsyncSocket *base, // IN } +/* + *---------------------------------------------------------------------------- + * + * AsyncTCPSocketGetRemotePort -- + * + * Given an AsyncTCPSocket object, returns the remote port + * associated with it, or an error if the request is meaningless + * for the underlying connection. + * + * Results: + * ASOCKERR_SUCCESS or ASOCKERR_GENERIC. + * + * Side effects: + * + * + *---------------------------------------------------------------------------- + */ + +static int +AsyncTCPSocketGetRemotePort(AsyncSocket *base, // IN + uint32 *port) // OUT +{ + AsyncTCPSocket *asock = TCPSocket(base); + int ret = ASOCKERR_SUCCESS; + + ASSERT(asock); + + if (asock == NULL || + AsyncTCPSocketGetState(asock) != AsyncSocketConnected || + (asock->remoteAddrLen != sizeof(struct sockaddr_in) && + asock->remoteAddrLen != sizeof(struct sockaddr_in6))) { + ret = ASOCKERR_GENERIC; + } else { + *port = AsyncTCPSocketGetPortFromAddr(&asock->remoteAddr); + } + + return ret; +} + + /* *---------------------------------------------------------------------------- * diff --git a/open-vm-tools/lib/include/asyncsocket.h b/open-vm-tools/lib/include/asyncsocket.h index 4fb872459..708b1fac1 100644 --- a/open-vm-tools/lib/include/asyncsocket.h +++ b/open-vm-tools/lib/include/asyncsocket.h @@ -388,6 +388,12 @@ int AsyncSocket_GetFd(AsyncSocket *asock); int AsyncSocket_GetRemoteIPStr(AsyncSocket *asock, const char **ipStr); +/* + * Return the remote port associated with this socket if applicable + */ +int AsyncSocket_GetRemotePort(AsyncSocket *asock, + uint32 *port); + int AsyncSocket_GetLocalVMCIAddress(AsyncSocket *asock, uint32 *cid, uint32 *port); int AsyncSocket_GetRemoteVMCIAddress(AsyncSocket *asock,