+ assert (r);
+
+ return r->client;
+}
+
+/* AvahiAddressResolver implementation */
+
+DBusHandlerResult avahi_address_resolver_event (AvahiClient *client, AvahiResolverEvent event, DBusMessage *message) {
+ AvahiAddressResolver *r = NULL;
+ DBusError error;
+ const char *path;
+
+ assert(client);
+ assert(message);
+
+ dbus_error_init (&error);
+
+ if (!(path = dbus_message_get_path(message)))
+ goto fail;
+
+ for (r = client->address_resolvers; r; r = r->address_resolvers_next)
+ if (strcmp (r->path, path) == 0)
+ break;
+
+ if (!r)
+ goto fail;
+
+ switch (event) {
+ case AVAHI_RESOLVER_FOUND: {
+ int32_t interface, protocol, aprotocol;
+ uint32_t flags;
+ char *name, *address;
+ AvahiAddress a;
+
+ if (!dbus_message_get_args(
+ message, &error,
+ DBUS_TYPE_INT32, &interface,
+ DBUS_TYPE_INT32, &protocol,
+ DBUS_TYPE_INT32, &aprotocol,
+ DBUS_TYPE_STRING, &address,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_UINT32, &flags,
+ DBUS_TYPE_INVALID) ||
+ dbus_error_is_set (&error)) {
+ fprintf(stderr, "Failed to parse resolver event.\n");
+ goto fail;
+ }
+
+ assert(address);
+ if (!avahi_address_parse(address, (AvahiProtocol) aprotocol, &a)) {
+ fprintf(stderr, "Failed to parse address\n");
+ goto fail;
+ }
+
+ r->callback(r, (AvahiIfIndex) interface, (AvahiProtocol) protocol, AVAHI_RESOLVER_FOUND, &a, name, (AvahiLookupResultFlags) flags, r->userdata);
+ break;
+ }
+
+ case AVAHI_RESOLVER_FAILURE: {
+ char *etxt;
+
+ if (!dbus_message_get_args(
+ message, &error,
+ DBUS_TYPE_STRING, &etxt,
+ DBUS_TYPE_INVALID) ||
+ dbus_error_is_set (&error)) {
+ fprintf(stderr, "Failed to parse resolver event.\n");
+ goto fail;
+ }
+
+ avahi_client_set_errno(r->client, avahi_error_dbus_to_number(etxt));
+ r->callback(r, r->interface, r->protocol, event, &r->address, NULL, 0, r->userdata);
+ break;
+ }
+ }
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+
+fail:
+ dbus_error_free (&error);
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+AvahiAddressResolver * avahi_address_resolver_new(
+ AvahiClient *client,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ const AvahiAddress *a,
+ AvahiLookupFlags flags,
+ AvahiAddressResolverCallback callback,
+ void *userdata) {
+
+ DBusError error;
+ AvahiAddressResolver *r = NULL;
+ DBusMessage *message = NULL, *reply = NULL;
+ int32_t i_interface, i_protocol;
+ uint32_t u_flags;
+ char *path;
+ char addr[AVAHI_ADDRESS_STR_MAX], *address = addr;
+
+ assert(client);
+ assert(a);
+
+ dbus_error_init (&error);
+
+ if (!avahi_address_snprint (addr, sizeof(addr), a)) {
+ avahi_client_set_errno(client, AVAHI_ERR_INVALID_ADDRESS);
+ return NULL;
+ }