diff options
author | Alban Crequy <alban.crequy@collabora.co.uk> | 2012-06-13 13:00:19 +0000 |
---|---|---|
committer | Rodrigo Moya <rodrigo@gnome-db.org> | 2012-06-13 15:56:39 +0200 |
commit | 80f476d7446eb58aa8cce0fca6239e7baf9b4ff5 (patch) | |
tree | 9bcde9249b904c05c8c682f61c55bb7ef28a54a3 | |
parent | fc9d22622957609ff434aa57c1c8eecd95ee740e (diff) | |
download | dbus-80f476d7446eb58aa8cce0fca6239e7baf9b4ff5.tar.gz |
cache the peer address
-rw-r--r-- | bus/connection.c | 31 | ||||
-rw-r--r-- | bus/connection.h | 7 |
2 files changed, 34 insertions, 4 deletions
diff --git a/bus/connection.c b/bus/connection.c index 084bc376..89111d90 100644 --- a/bus/connection.c +++ b/bus/connection.c @@ -98,6 +98,9 @@ typedef struct char *cached_loginfo_string; BusSELinuxID *selinux_id; + dbus_bool_t peer_address_set; + struct sockaddr_storage peer_address; + socklen_t peer_addrlen; DBusConnection *proxy_connection; /**< If this is a compat connection, proxy_connection is the proxy connection to AF_BUS */ @@ -689,8 +692,6 @@ bus_connections_setup_connection (BusConnections *connections, BusConnectionData *d; dbus_bool_t retval; DBusError error; - struct sockaddr_storage addr; - long addrlen = sizeof(addr); d = dbus_new0 (BusConnectionData, 1); @@ -718,11 +719,15 @@ bus_connections_setup_connection (BusConnections *connections, retval = FALSE; dbus_error_init (&error); + d->peer_addrlen = sizeof(d->peer_address); + d->peer_address_set = dbus_connection_get_peer_address (connection, + &d->peer_address, (long int *)&d->peer_addrlen); + /* If this connection is not AF_BUS, and we have a AF_BUS * server, we are in compat mode and we need to setup a * new connection */ - if (!dbus_connection_get_peer_address (connection, &addr, &addrlen) || - ((struct sockaddr *)&addr)->sa_family != AF_BUS) + if (d->peer_address_set && + ((struct sockaddr *)&d->peer_address)->sa_family != AF_BUS) { const char *main_address; main_address = bus_context_get_main_address (connections->context); @@ -2495,3 +2500,21 @@ bus_connection_get_peak_bus_names (DBusConnection *connection) return d->peak_bus_names; } #endif /* DBUS_ENABLE_STATS */ + +int +bus_connection_get_peer_address (DBusConnection *connection, + struct sockaddr **peer_address, + socklen_t *peer_addrlen) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + + if (!d->peer_address_set) + return FALSE; + + *peer_address = (struct sockaddr *) &d->peer_address; + *peer_addrlen = d->peer_addrlen; + + return TRUE; +} diff --git a/bus/connection.h b/bus/connection.h index ca93d8a3..95856f30 100644 --- a/bus/connection.h +++ b/bus/connection.h @@ -24,6 +24,8 @@ #ifndef BUS_CONNECTION_H #define BUS_CONNECTION_H +#include <sys/types.h> +#include <sys/socket.h> #include <dbus/dbus.h> #include <dbus/dbus-list.h> #include "bus.h" @@ -152,4 +154,9 @@ int bus_connections_get_peak_bus_names_per_conn (BusConnections *connections); int bus_connection_get_peak_match_rules (DBusConnection *connection); int bus_connection_get_peak_bus_names (DBusConnection *connection); +/* called by driver-afbus.c */ +int bus_connection_get_peer_address (DBusConnection *connection, + struct sockaddr **peer_address, + socklen_t *peer_addrlen); + #endif /* BUS_CONNECTION_H */ |