2 This file is part of catta.
4 catta is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
9 catta is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
12 Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with catta; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 #include <sys/types.h>
26 #include <sys/socket.h>
27 #include <netinet/in.h>
28 #include <arpa/inet.h>
30 #include <catta/domain.h>
31 #include <catta/defs.h>
32 #include <catta/malloc.h>
33 #include <catta/log.h>
35 #include "../src/dns.h"
36 #include "../src/util.h"
38 int main(CATTA_GCC_UNUSED int argc, CATTA_GCC_UNUSED char *argv[]) {
39 char t[CATTA_DOMAIN_NAME_MAX], *m;
40 const char *a, *b, *c, *d;
43 uint8_t rdata[CATTA_DNS_RDATA_MAX];
46 p = catta_dns_packet_new(0);
48 assert(catta_dns_packet_append_name(p, a = "Ahello.hello.hello.de."));
49 assert(catta_dns_packet_append_name(p, b = "Bthis is a test.hello.de."));
50 assert(catta_dns_packet_append_name(p, c = "Cthis\\.is\\.a\\.test\\.with\\.dots.hello.de."));
51 assert(catta_dns_packet_append_name(p, d = "Dthis\\\\is another test.hello.de."));
53 catta_hexdump(CATTA_DNS_PACKET_DATA(p), p->size);
55 assert(catta_dns_packet_consume_name(p, t, sizeof(t)) == 0);
56 catta_log_debug(">%s<", t);
57 assert(catta_domain_equal(a, t));
59 assert(catta_dns_packet_consume_name(p, t, sizeof(t)) == 0);
60 catta_log_debug(">%s<", t);
61 assert(catta_domain_equal(b, t));
63 assert(catta_dns_packet_consume_name(p, t, sizeof(t)) == 0);
64 catta_log_debug(">%s<", t);
65 assert(catta_domain_equal(c, t));
67 assert(catta_dns_packet_consume_name(p, t, sizeof(t)) == 0);
68 catta_log_debug(">%s<", t);
69 assert(catta_domain_equal(d, t));
71 catta_dns_packet_free(p);
73 /* RDATA PARSING AND SERIALIZATION */
75 /* Create an CattaRecord with some usful data */
76 r = catta_record_new_full("foobar.local", CATTA_DNS_CLASS_IN, CATTA_DNS_TYPE_HINFO, CATTA_DEFAULT_TTL);
78 r->data.hinfo.cpu = catta_strdup("FOO");
79 r->data.hinfo.os = catta_strdup("BAR");
81 /* Serialize it into a blob */
82 assert((l = catta_rdata_serialize(r, rdata, sizeof(rdata))) != (size_t) -1);
85 catta_hexdump(rdata, l);
87 /* Create a new record and fill in the data from the blob */
88 r2 = catta_record_new(r->key, CATTA_DEFAULT_TTL);
90 assert(catta_rdata_parse(r2, rdata, l) >= 0);
92 /* Compare both versions */
93 assert(catta_record_equal_no_ttl(r, r2));
95 /* Free the records */
96 catta_record_unref(r);
97 catta_record_unref(r2);
99 r = catta_record_new_full("foobar", 77, 77, CATTA_DEFAULT_TTL);
102 assert(r->data.generic.data = catta_memdup("HALLO", r->data.generic.size = 5));
104 m = catta_record_to_string(r);
107 catta_log_debug(">%s<", m);
110 catta_record_unref(r);