summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-sysdeps-unix.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2007-06-13 20:52:58 +0000
committerHavoc Pennington <hp@redhat.com>2007-06-13 20:52:58 +0000
commit72697649524238bd8389670e71c9faa55b7b4a1a (patch)
treee6c3ad0d6b7070e8f0cfd00231a5bbad739bb363 /dbus/dbus-sysdeps-unix.c
parente3d30a03225dd1d26012ecd39b09e4ccf91befb5 (diff)
2007-06-13 Havoc Pennington <hp@redhat.com>
* dbus/dbus-server-socket.c (_dbus_server_listen_socket): support all_interfaces=true|false for tcp servers * dbus/dbus-sysdeps-unix.c (_dbus_listen_tcp_socket): support inaddr_any flag * bus/selinux.c: fix some missing includes * dbus/dbus-server-socket.c (_dbus_server_listen_socket): allow port to simply be omitted in addition to specifying 0
Diffstat (limited to 'dbus/dbus-sysdeps-unix.c')
-rw-r--r--dbus/dbus-sysdeps-unix.c54
1 files changed, 32 insertions, 22 deletions
diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c
index f1c133fd..b3ffe04f 100644
--- a/dbus/dbus-sysdeps-unix.c
+++ b/dbus/dbus-sysdeps-unix.c
@@ -807,30 +807,28 @@ _dbus_connect_tcp_socket (const char *host,
}
/**
- * Creates a socket and binds it to the given path,
- * then listens on the socket. The socket is
- * set to be nonblocking.
- * In case of port=0 a random free port is used and
- * returned in the port parameter.
+ * Creates a socket and binds it to the given path, then listens on
+ * the socket. The socket is set to be nonblocking. In case of port=0
+ * a random free port is used and returned in the port parameter.
+ * If inaddr_any is specified, the hostname is ignored.
*
* @param host the host name to listen on
- * @param port the prot to listen on, if zero a free port will be used
+ * @param port the prot to listen on, if zero a free port will be used
+ * @param inaddr_any TRUE to listen on all local interfaces instead of on the host name
* @param error return location for errors
* @returns the listening file descriptor or -1 on error
*/
int
_dbus_listen_tcp_socket (const char *host,
dbus_uint32_t *port,
+ dbus_bool_t inaddr_any,
DBusError *error)
{
int listen_fd;
struct sockaddr_in addr;
- struct hostent *he;
- struct in_addr *haddr;
socklen_t len = (socklen_t) sizeof (struct sockaddr);
- _DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
+ _DBUS_ASSERT_ERROR_IS_CLEAR (error);
if (!_dbus_open_tcp_socket (&listen_fd, error))
{
@@ -839,21 +837,33 @@ _dbus_listen_tcp_socket (const char *host,
}
_DBUS_ASSERT_ERROR_IS_CLEAR(error);
- he = gethostbyname (host);
- if (he == NULL)
+ _DBUS_ZERO (addr);
+
+ if (inaddr_any)
{
- dbus_set_error (error,
- _dbus_error_from_errno (errno),
- "Failed to lookup hostname: %s",
- host);
- _dbus_close (listen_fd, NULL);
- return -1;
+ addr.sin_addr.s_addr = INADDR_ANY;
}
-
- haddr = ((struct in_addr *) (he->h_addr_list)[0]);
+ else
+ {
+ struct hostent *he;
+ struct in_addr *haddr;
- _DBUS_ZERO (addr);
- memcpy (&addr.sin_addr, haddr, sizeof (struct in_addr));
+ he = gethostbyname (host);
+ if (he == NULL)
+ {
+ dbus_set_error (error,
+ _dbus_error_from_errno (errno),
+ "Failed to lookup hostname: %s",
+ host);
+ _dbus_close (listen_fd, NULL);
+ return -1;
+ }
+
+ haddr = ((struct in_addr *) (he->h_addr_list)[0]);
+
+ memcpy (&addr.sin_addr, haddr, sizeof (struct in_addr));
+ }
+
addr.sin_family = AF_INET;
addr.sin_port = htons (*port);