Logo Search packages:      
Sourcecode: avahi version File versions  Download package

int avahi_server_add_address ( AvahiServer s,
AvahiSEntryGroup g,
AvahiIfIndex  interface,
AvahiProtocol  protocol,
AvahiPublishFlags  flags,
const char *  name,
AvahiAddress a 
)

Add an IP address mapping to the server. This will add both the host-name-to-address and the reverse mapping to the server. See avahi_server_add() for more information. If adding one of the RRs fails, the function returns with an error, but it is not defined if the other RR is deleted from the server or not. Therefore, you have to free the AvahiSEntryGroup and create a new one before proceeding.

Definition at line 431 of file entry.c.

References AVAHI_DEFAULT_TTL_HOST_NAME, AVAHI_DNS_CLASS_IN, AVAHI_DOMAIN_NAME_MAX, AVAHI_ERR_INVALID_FLAGS, AVAHI_ERR_INVALID_HOST_NAME, AVAHI_ERR_INVALID_INTERFACE, AVAHI_ERR_INVALID_PROTOCOL, AVAHI_ERR_NO_MEMORY, AVAHI_ERR_NOT_SUPPORTED, AVAHI_OK, AVAHI_PUBLISH_NO_ANNOUNCE, AVAHI_PUBLISH_NO_PROBE, avahi_server_errno(), AvahiAddress::data, AvahiRecord::data, and AvahiAddress::proto.

                     {

    char n[AVAHI_DOMAIN_NAME_MAX];
    int ret = AVAHI_OK;
    AvahiEntry *entry = NULL, *reverse = NULL;
    AvahiRecord  *r;

    assert(s);
    assert(a);

    AVAHI_CHECK_VALIDITY(s, AVAHI_IF_VALID(interface), AVAHI_ERR_INVALID_INTERFACE);
    AVAHI_CHECK_VALIDITY(s, AVAHI_PROTO_VALID(protocol) && AVAHI_PROTO_VALID(a->proto), AVAHI_ERR_INVALID_PROTOCOL);
    AVAHI_CHECK_VALIDITY(s, AVAHI_FLAGS_VALID(flags,
                                              AVAHI_PUBLISH_NO_REVERSE|
                                              AVAHI_PUBLISH_NO_ANNOUNCE|
                                              AVAHI_PUBLISH_NO_PROBE|
                                              AVAHI_PUBLISH_UPDATE|
                                              AVAHI_PUBLISH_USE_WIDE_AREA|
                                              AVAHI_PUBLISH_USE_MULTICAST), AVAHI_ERR_INVALID_FLAGS);
    AVAHI_CHECK_VALIDITY(s, !name || avahi_is_valid_fqdn(name), AVAHI_ERR_INVALID_HOST_NAME);

    /* Prepare the host naem */

    if (!name)
        name = s->host_name_fqdn;
    else {
        AVAHI_ASSERT_TRUE(avahi_normalize_name(name, n, sizeof(n)));
        name = n;
    }

    transport_flags_from_domain(s, &flags, name);
    AVAHI_CHECK_VALIDITY(s, flags & AVAHI_PUBLISH_USE_MULTICAST, AVAHI_ERR_NOT_SUPPORTED);

    /* Create the A/AAAA record */

    if (a->proto == AVAHI_PROTO_INET) {

        if (!(r = avahi_record_new_full(name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_A, AVAHI_DEFAULT_TTL_HOST_NAME))) {
            ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
            goto finish;
        }

        r->data.a.address = a->data.ipv4;

    } else {
        assert(a->proto == AVAHI_PROTO_INET6);

        if (!(r = avahi_record_new_full(name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_AAAA, AVAHI_DEFAULT_TTL_HOST_NAME))) {
            ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
            goto finish;
        }

        r->data.aaaa.address = a->data.ipv6;
    }

    entry = server_add_internal(s, g, interface, protocol, (flags & ~ AVAHI_PUBLISH_NO_REVERSE) | AVAHI_PUBLISH_UNIQUE | AVAHI_PUBLISH_ALLOW_MULTIPLE, r);
    avahi_record_unref(r);

    if (!entry) {
        ret = avahi_server_errno(s);
        goto finish;
    }

    /* Create the reverse lookup entry */

    if (!(flags & AVAHI_PUBLISH_NO_REVERSE)) {
        char reverse_n[AVAHI_DOMAIN_NAME_MAX];
        avahi_reverse_lookup_name(a, reverse_n, sizeof(reverse_n));

        if (!(reverse = server_add_ptr_internal(s, g, interface, protocol, flags | AVAHI_PUBLISH_UNIQUE, AVAHI_DEFAULT_TTL_HOST_NAME, reverse_n, name))) {
            ret = avahi_server_errno(s);
            goto finish;
        }
    }

finish:

    if (ret != AVAHI_OK && !(flags & AVAHI_PUBLISH_UPDATE)) {
        if (entry)
            avahi_entry_free(s, entry);
        if (reverse)
            avahi_entry_free(s, reverse);
    }

    return ret;
}


Generated by  Doxygen 1.6.0   Back to index