diff options
author | Ralf Habacker <ralf.habacker@freenet.de> | 2018-03-16 21:36:11 +0100 |
---|---|---|
committer | Ralf Habacker <ralf.habacker@freenet.de> | 2018-03-19 22:24:09 +0100 |
commit | 00babc0bae7bdd4dcf7489ec80dc010c272323b6 (patch) | |
tree | fd08025c86bbff40c94ce1f1c80b654adee31279 | |
parent | 4e3bfe0c97c9133b8fd856300e4c2072f4785d8c (diff) |
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
Reviewed-by: Simon McVittie <smcv@collabora.com>
-rw-r--r-- | dbus/dbus-server-socket.c | 8 | ||||
-rw-r--r-- | dbus/dbus-sysdeps-unix.c | 14 | ||||
-rw-r--r-- | dbus/dbus-sysdeps-win.c | 15 | ||||
-rw-r--r-- | dbus/dbus-sysdeps.h | 1 |
4 files changed, 34 insertions, 4 deletions
diff --git a/dbus/dbus-server-socket.c b/dbus/dbus-server-socket.c index 2da75605..e51e946e 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_used = 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_used, &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_used && (!_dbus_string_append (&address, ",family=") || - !_dbus_string_append (&address, family))) + !_dbus_string_append (&address, family_used))) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); goto failed; diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 249cf77e..f802cace 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -1492,6 +1492,7 @@ 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 @@ -1501,6 +1502,7 @@ _dbus_listen_tcp_socket (const char *host, const char *port, const char *family, DBusString *retport, + const char **retfamily, DBusSocket **fds_p, DBusError *error) { @@ -1512,6 +1514,8 @@ _dbus_listen_tcp_socket (const char *host, struct addrinfo hints; struct addrinfo *ai, *tmp; unsigned int reuseaddr; + dbus_bool_t have_ipv4 = FALSE; + dbus_bool_t have_ipv6 = FALSE; *fds_p = NULL; _DBUS_ASSERT_ERROR_IS_CLEAR (error); @@ -1648,6 +1652,11 @@ _dbus_listen_tcp_socket (const char *host, listen_fd[nlisten_fd].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 @@ -1707,6 +1716,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"; + for (i = 0 ; i < nlisten_fd ; i++) { if (!_dbus_set_fd_nonblocking (listen_fd[i].fd, error)) 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); |