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

char* avahi_record_to_string ( const AvahiRecord r )

Create a textual representation of the specified record, similar in style to BIND zone file data. avahi_free() the result!

Definition at line 248 of file rr.c.

References AvahiRecord::key, AvahiRecord::ref, AvahiRecord::ttl, and AvahiKey::type.

                                                   {
    char *p, *s;
    char buf[1024], *t = NULL, *d = NULL;

    assert(r);
    assert(r->ref >= 1);

    switch (r->key->type) {
        case AVAHI_DNS_TYPE_A:
            inet_ntop(AF_INET, &r->data.a.address.address, t = buf, sizeof(buf));
            break;

        case AVAHI_DNS_TYPE_AAAA:
            inet_ntop(AF_INET6, &r->data.aaaa.address.address, t = buf, sizeof(buf));
            break;

        case AVAHI_DNS_TYPE_PTR:
        case AVAHI_DNS_TYPE_CNAME:
        case AVAHI_DNS_TYPE_NS:

            t = r->data.ptr.name;
            break;

        case AVAHI_DNS_TYPE_TXT:
            t = d = avahi_string_list_to_string(r->data.txt.string_list);
            break;

        case AVAHI_DNS_TYPE_HINFO:

            snprintf(t = buf, sizeof(buf), "\"%s\" \"%s\"", r->data.hinfo.cpu, r->data.hinfo.os);
            break;

        case AVAHI_DNS_TYPE_SRV:

            snprintf(t = buf, sizeof(buf), "%u %u %u %s",
                     r->data.srv.priority,
                     r->data.srv.weight,
                     r->data.srv.port,
                     r->data.srv.name);

            break;

        default: {

            uint8_t *c;
            uint16_t n;
            int i;
            char *e;

            /* According to RFC3597 */

            snprintf(t = buf, sizeof(buf), "\\# %u", r->data.generic.size);

            e = strchr(t, 0);

            for (c = r->data.generic.data, n = r->data.generic.size, i = 0;
                 n > 0 && i < 20;
                 c ++, n --, i++) {

                sprintf(e, " %02X", *c);
                e = strchr(e, 0);
            }

            break;
        }
    }

    p = avahi_key_to_string(r->key);
    s = avahi_strdup_printf("%s %s ; ttl=%u", p, t, r->ttl);
    avahi_free(p);
    avahi_free(d);

    return s;
}

Generated by  Doxygen 1.6.0   Back to index