summaryrefslogtreecommitdiff
path: root/dbus/dbus-transport-socket.c
diff options
context:
space:
mode:
authorDaniel P. Berrange <dan@berrange.com>2007-07-25 02:46:52 +0000
committerDaniel P. Berrange <dan@berrange.com>2007-07-25 02:46:52 +0000
commitee71e1ff6033ad1eb2385f11d4f3678259b8397b (patch)
treeed47c0cc3273361474d746d7b1952a10da4e60fc /dbus/dbus-transport-socket.c
parent79d3004e26f490ef37ae0298495ea66f322ce374 (diff)
downloaddbus-ee71e1ff6033ad1eb2385f11d4f3678259b8397b.tar.gz
Switch over to using getaddrinfo for TCP clients & servers to enable IPv6
Diffstat (limited to 'dbus/dbus-transport-socket.c')
-rw-r--r--dbus/dbus-transport-socket.c45
1 files changed, 21 insertions, 24 deletions
diff --git a/dbus/dbus-transport-socket.c b/dbus/dbus-transport-socket.c
index 8ec69d8d..a31c1597 100644
--- a/dbus/dbus-transport-socket.c
+++ b/dbus/dbus-transport-socket.c
@@ -1204,15 +1204,18 @@ _dbus_transport_new_for_socket (int fd,
/**
* Creates a new transport for the given hostname and port.
+ * If host is NULL, it will default to localhost
*
* @param host the host to connect to
* @param port the port to connect to
+ * @param family the address family to connect to
* @param error location to store reason for failure.
* @returns a new transport, or #NULL on failure.
*/
DBusTransport*
_dbus_transport_new_for_tcp_socket (const char *host,
- dbus_int32_t port,
+ const char *port,
+ const char *family,
DBusError *error)
{
int fd;
@@ -1226,20 +1229,27 @@ _dbus_transport_new_for_tcp_socket (const char *host,
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
return NULL;
}
-
+
+ if (host == NULL)
+ host = "localhost";
+
if (!_dbus_string_append (&address, "tcp:"))
goto error;
- if (host != NULL &&
- (!_dbus_string_append (&address, "host=") ||
- !_dbus_string_append (&address, host)))
+ if (!_dbus_string_append (&address, "host=") ||
+ !_dbus_string_append (&address, host))
goto error;
if (!_dbus_string_append (&address, ",port=") ||
- !_dbus_string_append_int (&address, port))
+ !_dbus_string_append (&address, port))
goto error;
- fd = _dbus_connect_tcp_socket (host, port, error);
+ if (family != NULL &&
+ (!_dbus_string_append (&address, "family=") ||
+ !_dbus_string_append (&address, family)))
+ goto error;
+
+ fd = _dbus_connect_tcp_socket (host, port, family, error);
if (fd < 0)
{
_DBUS_ASSERT_ERROR_IS_SET (error);
@@ -1249,7 +1259,7 @@ _dbus_transport_new_for_tcp_socket (const char *host,
_dbus_fd_set_close_on_exec (fd);
- _dbus_verbose ("Successfully connected to tcp socket %s:%d\n",
+ _dbus_verbose ("Successfully connected to tcp socket %s:%s\n",
host, port);
transport = _dbus_transport_new_for_socket (fd, NULL, &address);
@@ -1293,28 +1303,15 @@ _dbus_transport_open_socket(DBusAddressEntry *entry,
{
const char *host = dbus_address_entry_get_value (entry, "host");
const char *port = dbus_address_entry_get_value (entry, "port");
- DBusString str;
- long lport;
- dbus_bool_t sresult;
-
+ const char *family = dbus_address_entry_get_value (entry, "family");
+
if (port == NULL)
{
_dbus_set_bad_address (error, "tcp", "port", NULL);
return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
}
- _dbus_string_init_const (&str, port);
- sresult = _dbus_string_parse_int (&str, 0, &lport, NULL);
- _dbus_string_free (&str);
-
- if (sresult == FALSE || lport <= 0 || lport > 65535)
- {
- _dbus_set_bad_address (error, NULL, NULL,
- "Port is not an integer between 0 and 65535");
- return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
- }
-
- *transport_p = _dbus_transport_new_for_tcp_socket (host, lport, error);
+ *transport_p = _dbus_transport_new_for_tcp_socket (host, port, family, error);
if (*transport_p == NULL)
{
_DBUS_ASSERT_ERROR_IS_SET (error);