]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
added run-test4 (from the documentation)
authorMiek Gieben <miekg@NLnetLabs.nl>
Mon, 24 Jan 2005 13:45:36 +0000 (13:45 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Mon, 24 Jan 2005 13:45:36 +0000 (13:45 +0000)
program will not compile (yet), but should in a few
days

Makefile.in
run-test4.c [new file with mode: 0644]

index d01442f17384183d0e72b12145a223d7d5cdf6c2..65584a2f8b7551d557bd400bc107136bd914776a 100644 (file)
@@ -36,7 +36,7 @@ LIBDNS_HEADERS        =       ldns/error.h            \
                        util.h
 LIBDNS_OBJECTS =       $(LIBDNS_SOURCES:.c=.o)
 
-ALL_SOURCES    =       run-test0.c run-test1.c run-test2.c run-test3.c \
+ALL_SOURCES    =       run-test0.c run-test1.c run-test2.c run-test3.c run-test4.c \
                        $(LIBDNS_SOURCES)
 
 COMPILE                = $(CC) $(CPPFLAGS) $(CFLAGS)
@@ -45,9 +45,9 @@ LINK          = $(CC) $(CFLAGS) $(LDFLAGS)
 %.o:   $(srcdir)/%.c
        $(COMPILE) -c $<
 
-.PHONY:        clean realclean docclean doc lint
+.PHONY:        clean realclean docclean doc lint test all
 
-all:   run-test0 run-test1 run-test2 run-test3
+all:   run-test0 run-test1 run-test2 run-test3 
 
 run-test0:     run-test0.o $(LIBDNS_OBJECTS) $(LIBOBJS)
                $(LINK) ${LIBS} -o $@ $+
@@ -61,6 +61,9 @@ run-test2:    run-test2.o $(LIBDNS_OBJECTS) $(LIBOBJS)
 run-test3:     run-test3.o $(LIBDNS_OBJECTS) $(LIBOBJS)
                $(LINK) ${LIBS} -o $@ $+
 
+run-test4:     run-test4.o $(LIBDNS_OBJECTS) $(LIBOBJS)
+               $(LINK) ${LIBS} -o $@ $+
+
 doc:   
        doxygen libdns.doxygen
 
@@ -87,14 +90,14 @@ docclean:
 
 test0: run-test0
        ./run-test0
-
 test1: run-test1
        ./run-test1
-
 test2: run-test2
        ./run-test2
+test3: run-test3
+       ./run-test3
 
-test: test0 test1 test2
+test: test0 test1 test2 test3
 
 lint:
        for i in $(ALL_SOURCES); do \
diff --git a/run-test4.c b/run-test4.c
new file mode 100644 (file)
index 0000000..71998da
--- /dev/null
@@ -0,0 +1,46 @@
+/**
+ * An example ldns program
+ * In semi-C code
+ *
+ * Setup a resolver
+ * Query a nameserver
+ * Print the result
+ */
+
+#include <config.h>
+#include <ldns/ldns.h>
+        
+int     
+main(void)
+{       
+        ldns_resolver *res;
+        ldns_rdf *default_dom;
+        ldns_rdf *nameserver;
+        ldns_rdf *qname;
+        ldns_pkt *pkt;
+                
+        /* init */
+        res = ldns_resolver_new(); 
+        if (!res)
+                return 1;
+
+        /* create a default domain and add it */
+        default_dom = ldns_rdf_new_frm_str("miek.nl.", LDNS_RDF_TYPE_DNAME);
+        nameserver  = ldns_rdf_new_frm_str("127.0.0.1", LDNS_RDF_TYPE_A);
+                
+        if (ldns_resolver_domain(res, default_dom) != LDNS_STATUS_OK)
+                return 1;
+        if (ldns_resolver_nameserver_push(res, nameserver) != LDNS_STATUS_OK)
+                return 1;
+        
+        /* setup the question */
+        qname = ldns_rdf_new_frm_str("www", LDNS_RDF_TYPE_DNAME);
+        
+        /* fire it off. "miek.nl." will be added */
+        pkt = ldns_resolver_query(res, qname, LDNS_RR_TYPE_MX, NULL);
+        
+        /* print the resulting pkt to stdout */
+        ldns_pkt_print(stdout, pkt);
+
+        return 0;
+}