From: Lennart Poettering Date: Sun, 24 Apr 2005 21:19:40 +0000 (+0000) Subject: * improve dns.c testing program X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=4c8155fa9c85c7ece92182d0ab53f99a982a4abf;p=catta * improve dns.c testing program * fix some compiler warnings * correct flx_dns_packet_append_name() * fix host name string * fix use of flx_domain_equal() use git-svn-id: file:///home/lennart/svn/public/avahi/trunk@30 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- diff --git a/Makefile b/Makefile index 2a3be76..1e10fb3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -#CC=gcc -CFLAGS=-g -O0 -Wall -W -pipe $(shell pkg-config --cflags glib-2.0) -Wno-unused +#CC=gcc-2.95 +CFLAGS=-g -O1 -Wall -W -pipe $(shell pkg-config --cflags glib-2.0) -Wno-unused LIBS=$(shell pkg-config --libs glib-2.0) all: strlst-test prioq-test domain-test dns-test flexmdns @@ -22,8 +22,7 @@ domain-test: domain-test.o util.o dns-test: dns-test.o util.o dns.o rr.o strlst.o $(CC) -o $@ $^ $(LIBS) - *.o: *.h clean: - rm -f *.o flexmdns prioq-test strlst-test + rm -f *.o flexmdns tprioq-test strlst-test domain-test dns-test diff --git a/announce.c b/announce.c index cd2b1fa..d1b5665 100644 --- a/announce.c +++ b/announce.c @@ -259,12 +259,12 @@ void flx_goodbye_all(flxServer *s, gboolean goodbye) { g_assert(s); - g_message("goodbye all: %p", e); + g_message("goodbye all"); for (e = s->entries; e; e = e->entry_next) flx_goodbye_entry(s, e, goodbye); - g_message("goodbye all done: %p", e); + g_message("goodbye all done"); } diff --git a/dns-test.c b/dns-test.c index 5d09b4a..a6cac23 100644 --- a/dns-test.c +++ b/dns-test.c @@ -2,27 +2,33 @@ #include "util.h" int main(int argc, char *argv[]) { - gchar t[256]; + gchar t[256], *a, *b, *c, *d; flxDnsPacket *p; p = flx_dns_packet_new(8000); - flx_dns_packet_append_name(p, "hello.hello.hello.de."); - flx_dns_packet_append_name(p, "this is a test.hello.de."); - flx_dns_packet_append_name(p, "this\\.is\\.a\\.test\\.with\\.dots.hello.de."); - flx_dns_packet_append_name(p, "this\\\\is another\\ \\test.hello.de."); + flx_dns_packet_append_name(p, a = "hello.hello.hello.de."); + flx_dns_packet_append_name(p, b = "this is a test.hello.de."); + flx_dns_packet_append_name(p, c = "this\\.is\\.a\\.test\\.with\\.dots.hello.de."); + flx_dns_packet_append_name(p, d = "this\\\\is another\\ \\test.hello.de."); flx_hexdump(FLX_DNS_PACKET_DATA(p), p->size); flx_dns_packet_consume_name(p, t, sizeof(t)); g_message(">%s<", t); + g_assert(flx_domain_equal(a, t)); + flx_dns_packet_consume_name(p, t, sizeof(t)); g_message(">%s<", t); + g_assert(flx_domain_equal(b, t)); + flx_dns_packet_consume_name(p, t, sizeof(t)); g_message(">%s<", t); + g_assert(flx_domain_equal(c, t)); + flx_dns_packet_consume_name(p, t, sizeof(t)); g_message(">%s<", t); - + g_assert(flx_domain_equal(d, t)); flx_dns_packet_free(p); return 0; diff --git a/dns.c b/dns.c index f55ae78..d518a30 100644 --- a/dns.c +++ b/dns.c @@ -106,14 +106,15 @@ static gchar *unescape_label(gchar *dest, guint size, const gchar **name) { } guint8* flx_dns_packet_append_name(flxDnsPacket *p, const gchar *name) { - guint8 *d, *f = NULL; + guint8 *d, *saved_ptr = NULL; guint saved_size; g_assert(p); g_assert(name); saved_size = p->size; - + saved_ptr = flx_dns_packet_extend(p, 0); + while (*name) { guint n; guint8* prev; @@ -135,11 +136,8 @@ guint8* flx_dns_packet_append_name(flxDnsPacket *p, const gchar *name) { if (!(t = (guint16*) flx_dns_packet_extend(p, sizeof(guint16)))) return NULL; - if (!f) - f = (guint8*) t; - *t = g_htons((0xC000 | index)); - return f; + return saved_ptr; } } @@ -150,7 +148,7 @@ guint8* flx_dns_packet_append_name(flxDnsPacket *p, const gchar *name) { if (!(d = flx_dns_packet_append_string(p, label))) goto fail; - + if (!p->name_table) p->name_table = g_hash_table_new_full((GHashFunc) flx_domain_hash, (GEqualFunc) flx_domain_equal, g_free, NULL); @@ -162,7 +160,7 @@ guint8* flx_dns_packet_append_name(flxDnsPacket *p, const gchar *name) { *d = 0; - return f; + return saved_ptr; fail: p->size = saved_size; diff --git a/prioq.c b/prioq.c index 9e49b81..40801a6 100644 --- a/prioq.c +++ b/prioq.c @@ -45,7 +45,7 @@ static flxPrioQueueNode* get_node_at_xy(flxPrioQueue *q, guint x, guint y) { } static void exchange_nodes(flxPrioQueue *q, flxPrioQueueNode *a, flxPrioQueueNode *b) { - flxPrioQueueNode *l, *r, *p, *ap, *an, *bp, *bn, *apl, *bpl; + flxPrioQueueNode *l, *r, *p, *ap, *an, *bp, *bn; gint t; g_assert(q); g_assert(a); @@ -128,6 +128,8 @@ static void exchange_nodes(flxPrioQueue *q, flxPrioQueueNode *a, flxPrioQueueNod b->left->parent = b; } } else { + flxPrioQueueNode *apl = NULL, *bpl = NULL; + /* Swap parents */ ap = a->parent; bp = b->parent; diff --git a/psched.c b/psched.c index 661a5f9..105be93 100644 --- a/psched.c +++ b/psched.c @@ -581,7 +581,7 @@ static flxProbeJob* probe_job_new(flxPacketScheduler *s, flxRecord *record) { static guint8* packet_add_probe_query(flxPacketScheduler *s, flxDnsPacket *p, flxProbeJob *pj) { guint size; - guint8 *r; + guint8 *ret; flxKey *k; g_assert(s); @@ -601,7 +601,8 @@ static guint8* packet_add_probe_query(flxPacketScheduler *s, flxDnsPacket *p, fl /* Create the probe query */ k = flx_key_new(pj->record->key->name, pj->record->key->class, FLX_DNS_TYPE_ANY); - r = flx_dns_packet_append_key(p, k); + ret = flx_dns_packet_append_key(p, k); + g_assert(ret); /* Mark this job for addition to the packet */ pj->chosen = TRUE; @@ -625,7 +626,7 @@ static guint8* packet_add_probe_query(flxPacketScheduler *s, flxDnsPacket *p, fl flx_key_unref(k); - return r; + return ret; } static void probe_elapse(flxTimeEvent *e, gpointer data) { @@ -642,7 +643,7 @@ static void probe_elapse(flxTimeEvent *e, gpointer data) { /* Add the import probe */ if (!packet_add_probe_query(s, p, pj)) { - g_warning("Record too large!"); + g_warning("Record too large! ---"); flx_dns_packet_free(p); return; } diff --git a/rr.c b/rr.c index 2c5a044..dddaf9c 100644 --- a/rr.c +++ b/rr.c @@ -163,7 +163,7 @@ gchar *flx_key_to_string(const flxKey *k) { gchar *flx_record_to_string(const flxRecord *r) { gchar *p, *s; - char buf[257], *t, *d = NULL; + char buf[257], *t = NULL, *d = NULL; switch (r->key->type) { case FLX_DNS_TYPE_A: @@ -214,7 +214,7 @@ gboolean flx_key_equal(const flxKey *a, const flxKey *b) { /* g_message("equal: %p %p", a, b); */ - return flx_domain_equal(a->name, b->name) == 0 && + return flx_domain_equal(a->name, b->name) && a->type == b->type && a->class == b->class; } @@ -227,7 +227,7 @@ gboolean flx_key_pattern_match(const flxKey *pattern, const flxKey *k) { g_assert(!flx_key_is_pattern(k)); - return flx_domain_equal(pattern->name, k->name) == 0 && + return flx_domain_equal(pattern->name, k->name) && (pattern->type == k->type || pattern->type == FLX_DNS_TYPE_ANY) && pattern->class == k->class; } diff --git a/server.c b/server.c index cd97262..0b1a123 100644 --- a/server.c +++ b/server.c @@ -302,7 +302,7 @@ flxServer *flx_server_new(GMainContext *c) { hn = flx_get_host_name(); hn[strcspn(hn, ".")] = 0; - s->hostname = g_strdup_printf("%slocal.", hn); + s->hostname = g_strdup_printf("%s.local.", hn); g_free(hn); add_default_entries(s);