From: VMware, Inc <> Date: Fri, 12 Apr 2013 19:56:13 +0000 (-0700) Subject: Fill in local socket address for regular sockets. X-Git-Tag: 2013.04.16-1098359~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=032f106b5f2cff5b44dae1f4acf42cff3fb7dcd8;p=thirdparty%2Fopen-vm-tools.git Fill in local socket address for regular sockets. 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 --- diff --git a/open-vm-tools/lib/asyncsocket/asyncsocket.c b/open-vm-tools/lib/asyncsocket/asyncsocket.c index db6c1ad2c..6fec4a1d0 100644 --- a/open-vm-tools/lib/asyncsocket/asyncsocket.c +++ b/open-vm-tools/lib/asyncsocket/asyncsocket.c @@ -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);