]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Common source file changes not directly applicable to open-vm-tools.
authorOliver Kurth <okurth@vmware.com>
Tue, 26 May 2020 22:32:57 +0000 (15:32 -0700)
committerOliver Kurth <okurth@vmware.com>
Tue, 26 May 2020 22:32:57 +0000 (15:32 -0700)
open-vm-tools/lib/asyncsocket/asyncSocketInterface.c
open-vm-tools/lib/asyncsocket/asyncSocketVTable.h
open-vm-tools/lib/asyncsocket/asyncsocket.c
open-vm-tools/lib/include/asyncsocket.h

index db2d7b7384d5b8d63b8ba0fc8211fdffb74e9d89..fdf45a930b29db78bf5f15be9d658bdf2538177b 100644 (file)
@@ -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;
+}
+
+
 /*
  *----------------------------------------------------------------------------
  *
index 6c50c2fdfefc82a7ff19738f94e086a4a0085d31..24784ef226621e237ad6755c0a08338eb50c20cd 100644 (file)
@@ -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,
index bc5c9c6eb2ada0dba9fb761e36091414eb9352cc..b043ea4de2f728ca789b2ca9a7d14c926e4877be 100644 (file)
@@ -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;
+}
+
+
 /*
  *----------------------------------------------------------------------------
  *
index 4fb8724595e6a166b683df9c0ff8cf751db74e73..708b1fac17c1614d3feee78e9af2bb6c95685d0c 100644 (file)
@@ -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,