-#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
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
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");
}
#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;
}
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;
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;
}
}
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);
*d = 0;
- return f;
+ return saved_ptr;
fail:
p->size = saved_size;
}
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);
b->left->parent = b;
}
} else {
+ flxPrioQueueNode *apl = NULL, *bpl = NULL;
+
/* Swap parents */
ap = a->parent;
bp = b->parent;
static guint8* packet_add_probe_query(flxPacketScheduler *s, flxDnsPacket *p, flxProbeJob *pj) {
guint size;
- guint8 *r;
+ guint8 *ret;
flxKey *k;
g_assert(s);
/* 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;
flx_key_unref(k);
- return r;
+ return ret;
}
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;
}
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:
/* 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;
}
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;
}
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);