From 13573c3da0734ac00a523f715115c98e3027f28b Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Fri, 16 Mar 2018 21:36:11 +0100 Subject: [PATCH] Add actual used ip family to --print-address output in case of listening on tcp Specifying a dbus tcp address without a family let dbus-daemon the choice for listen on ipv4 or ipv6, but did not return the real used ip family, which is fixed with this commit. Bug:https://bugs.freedesktop.org/show_bug.cgi?id=105489 --- dbus/dbus-server-socket.c | 8 +++++--- dbus/dbus-sysdeps-win.c | 15 ++++++++++++++- dbus/dbus-sysdeps.h | 1 + 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/dbus/dbus-server-socket.c b/dbus/dbus-server-socket.c index 2da75605..104d31d7 100644 --- a/dbus/dbus-server-socket.c +++ b/dbus/dbus-server-socket.c @@ -429,7 +429,8 @@ _dbus_server_new_for_tcp_socket (const char *host, DBusString host_str; /* Initialized as const later, not freed */ DBusString port_str = _DBUS_STRING_INIT_INVALID; DBusNonceFile *noncefile = NULL; - + const char *family_str = NULL; + _DBUS_ASSERT_ERROR_IS_CLEAR (error); if (!_dbus_string_init (&address)) @@ -457,6 +458,7 @@ _dbus_server_new_for_tcp_socket (const char *host, nlisten_fds =_dbus_listen_tcp_socket (bind, port, family, &port_str, + &family_str, &listen_fds, error); if (nlisten_fds <= 0) { @@ -473,9 +475,9 @@ _dbus_server_new_for_tcp_socket (const char *host, dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); goto failed; } - if (family && + if (family_str && (!_dbus_string_append (&address, ",family=") || - !_dbus_string_append (&address, family))) + !_dbus_string_append (&address, family_str))) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); goto failed; diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index dede8e29..70200e7f 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -1652,16 +1652,17 @@ out: * @param port the port to listen on, if zero a free port will be used * @param family the address family to listen on, NULL for all * @param retport string to return the actual port listened on + * @param retfamily string to return the actual family listened on * @param fds_p location to store returned file descriptors * @param error return location for errors * @returns the number of listening file descriptors or -1 on error */ - int _dbus_listen_tcp_socket (const char *host, const char *port, const char *family, DBusString *retport, + const char **retfamily, DBusSocket **fds_p, DBusError *error) { @@ -1672,6 +1673,8 @@ _dbus_listen_tcp_socket (const char *host, DBusSocket *listen_fd = NULL; struct addrinfo hints; struct addrinfo *ai, *tmp; + dbus_bool_t have_ipv4 = FALSE; + dbus_bool_t have_ipv6 = FALSE; // On Vista, sockaddr_gen must be a sockaddr_in6, and not a sockaddr_in6_old //That's required for family == IPv6(which is the default on Vista if family is not given) @@ -1831,6 +1834,11 @@ _dbus_listen_tcp_socket (const char *host, listen_fd[nlisten_fd] = fd; nlisten_fd++; + if (tmp->ai_addr->sa_family == AF_INET) + have_ipv4 = TRUE; + else if (tmp->ai_addr->sa_family == AF_INET6) + have_ipv6 = TRUE; + if (!_dbus_string_get_length(retport)) { /* If the user didn't specify a port, or used 0, then @@ -1886,6 +1894,11 @@ _dbus_listen_tcp_socket (const char *host, goto failed; } + if (have_ipv4 && !have_ipv6) + *retfamily = "ipv4"; + else if (!have_ipv4 && have_ipv6) + *retfamily = "ipv6"; + sscanf(_dbus_string_get_const_data(retport), "%d", &port_num); for (i = 0 ; i < nlisten_fd ; i++) diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h index 8961c33f..8642dda5 100644 --- a/dbus/dbus-sysdeps.h +++ b/dbus/dbus-sysdeps.h @@ -237,6 +237,7 @@ int _dbus_listen_tcp_socket (const char *host, const char *port, const char *family, DBusString *retport, + const char **retfamily, DBusSocket **fds_p, DBusError *error); DBusSocket _dbus_accept (DBusSocket listen_fd); -- 2.13.6