]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fill in local socket address for regular sockets.
authorVMware, Inc <>
Fri, 12 Apr 2013 19:56:13 +0000 (12:56 -0700)
committerDmitry Torokhov <dtor@vmware.com>
Wed, 17 Apr 2013 19:16:56 +0000 (12:16 -0700)
Call getsockname(2) once the connection has succeeded to record the
local socket address in the AsyncSocket struct so that
AsyncSocket_GetLocalVMCIAddress works for sockets using the kernel vsock
driver as well.

This allows me to print the local socket address in vsockTest, which
is useful for debugging.

Signed-off-by: Dmitry Torokhov <dtor@vmware.com>
open-vm-tools/lib/asyncsocket/asyncsocket.c

index db6c1ad2cadbd4bd36bde80416318642231a2afc..6fec4a1d0a80309700c60fdc6c484b38d8749288 100644 (file)
@@ -3118,6 +3118,16 @@ AsyncSocketConnectInternal(AsyncSocket *s)
       return ASOCKERR_GENERIC;
    }
 
+   s->localAddrLen = sizeof s->localAddr;
+   if (getsockname(s->fd, &s->localAddr, &s->localAddrLen) != 0) {
+      sysErr = ASOCK_LASTERROR();
+      s->genericErrno = sysErr;
+      Warning(ASOCKPREFIX "getsockname for connect on fd %d failed with "
+              "error %d: %s\n", s->fd, sysErr, Err_Errno2String(sysErr));
+
+      return ASOCKERR_GENERIC;
+   }
+
 done:
    s->state = AsyncSocketConnected;
    s->connectFn(s, s->clientData);