From cfd3f06e566bc22297df4e04e30735f0a0f34c98 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Wed, 4 Feb 2015 14:56:17 +0100 Subject: [PATCH] _dbus_listen_tcp_socket: Keep windows code to fetch port from tcp listening socket in sync with unix. https://bugs.freedesktop.org/show_bug.cgi?id=87999 --- dbus/dbus-sysdeps-win.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index 1eeb22f..615f852 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -1822,9 +1822,12 @@ _dbus_listen_tcp_socket (const char *host, { mysockaddr_gen addr; socklen_t addrlen = sizeof(addr); - char portbuf[10]; + char portbuf[NI_MAXSERV]; - if (getsockname(fd, &addr.Address, &addrlen) == SOCKET_ERROR) + if (getsockname(fd, &addr.Address, &addrlen) == SOCKET_ERROR || + (res = getnameinfo (&addr.Address, addrlen, NULL, 0, + portbuf, NI_MAXSERV, + NI_NUMERICSERV)) != 0) { DBUS_SOCKET_SET_ERRNO (); dbus_set_error (error, _dbus_error_from_errno (errno), @@ -1832,10 +1835,6 @@ _dbus_listen_tcp_socket (const char *host, host ? host : "*", port, _dbus_strerror_from_errno()); goto failed; } - if (addr.AddressIn.sin_family = AF_INET) - snprintf( portbuf, sizeof( portbuf ) - 1, "%d", ntohs(addr.AddressIn.sin_port) ); - else - snprintf( portbuf, sizeof( portbuf ) - 1, "%d", ntohs(addr.AddressIn6.sin6_port) ); if (!_dbus_string_append(retport, portbuf)) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); -- 1.8.4.5