]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Export local and remote VMCI address info from AsyncSocket.
authorVMware, Inc <>
Fri, 12 Apr 2013 19:54:38 +0000 (12:54 -0700)
committerDmitry Torokhov <dtor@vmware.com>
Wed, 17 Apr 2013 19:16:56 +0000 (12:16 -0700)
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 <dtor@vmware.com>
open-vm-tools/lib/asyncsocket/asyncSocketInt.h
open-vm-tools/lib/asyncsocket/asyncsocket.c
open-vm-tools/lib/include/asyncsocket.h

index b70880b3becdac73d08f4a0a390b60ebc65320f9..6a0732fab58cb5f4de596be77c78cfcbe06472da 100644 (file)
@@ -182,6 +182,8 @@ struct AsyncSocket {
    void *errorClientData;
    VmTimeType drainTimeoutUS;
 
+   struct sockaddr localAddr;
+   socklen_t localAddrLen;
    struct sockaddr remoteAddr;
    socklen_t remoteAddrLen;
 
index e29feeda1bde6609404812819ff75bd25ba6d5f8..8375c8c452a06fc65eeaa7894367553641a7ce32 100644 (file)
@@ -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;
+}
+
+
 /*
  *----------------------------------------------------------------------------
  *
index 86c52e33355d2026ae1a34c625aa1e4f91b2d2e1..6c4c2ba9b4a5aa64376a24ce5215967a4dc21d31 100644 (file)
@@ -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
  */