static void finish(AvahiSHostNameResolver *r, AvahiResolverEvent event) {
    assert(r);

    if (r->time_event) {
        avahi_time_event_free(r->time_event);
        r->time_event = NULL;
    }

    switch (event) {
        case AVAHI_RESOLVER_FOUND: {
            AvahiAddress a;

            assert(r->address_record);

            switch (r->address_record->key->type) {
                case AVAHI_DNS_TYPE_A:
                    a.proto = AVAHI_PROTO_INET;
                    a.data.ipv4 = r->address_record->data.a.address;
                    break;

                case AVAHI_DNS_TYPE_AAAA:
                    a.proto = AVAHI_PROTO_INET6;
                    a.data.ipv6 = r->address_record->data.aaaa.address;
                    break;

                default:
                    abort();
            }

            r->callback(r, r->interface, r->protocol, AVAHI_RESOLVER_FOUND, r->address_record->key->name, &a, r->flags, r->userdata);
            break;

        }

        case AVAHI_RESOLVER_FAILURE:

            r->callback(r, r->interface, r->protocol, event, r->host_name, NULL, r->flags, r->userdata);
            break;
    }
}
static void finish(AvahiSHostNameResolver *r, AvahiResolverEvent event) {
    assert(r);

    if (r->time_event) {
        avahi_time_event_free(r->time_event);
        r->time_event = NULL;
    }

    switch (event) {
        case AVAHI_RESOLVER_FOUND: {
            AvahiAddress a;

            assert(r->address_record);

            switch (r->address_record->key->type) {
                case AVAHI_DNS_TYPE_A:
                    a.proto = AVAHI_PROTO_INET;
                    a.data.ipv4 = r->address_record->data.a.address;
                    break;

                case AVAHI_DNS_TYPE_AAAA:
                    a.proto = AVAHI_PROTO_INET6;
                    a.data.ipv6 = r->address_record->data.aaaa.address;
                    break;

                default:
                    abort();
            }

            r->callback(r, r->interface, r->protocol, AVAHI_RESOLVER_FOUND, r->address_record->key->name, &a, r->flags, r->userdata);
            break;

        }

        case AVAHI_RESOLVER_FAILURE:

            r->callback(r, r->interface, r->protocol, event, r->host_name, NULL, r->flags, r->userdata);
            break;
    }
}