Commit 00babc0b authored by Ralf Habacker's avatar Ralf Habacker

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=105489Reviewed-by: Simon McVittie's avatarSimon McVittie <smcv@collabora.com>
parent 4e3bfe0c
......@@ -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;
......
......@@ -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))
......
......@@ -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++)
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment