]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
added 'raw' 2wire functions, see for an example run-test2.c
authorJelte Jansen <jeltejan@NLnetLabs.nl>
Mon, 31 Jan 2005 09:47:57 +0000 (09:47 +0000)
committerJelte Jansen <jeltejan@NLnetLabs.nl>
Mon, 31 Jan 2005 09:47:57 +0000 (09:47 +0000)
host2wire.c
ldns/host2wire.h
run-test2.c

index f737b09307ed2c7d96ef34399b89def290f9a9de..615a6026997c9e6851dbb328bc435237a6200be3 100644 (file)
@@ -165,4 +165,72 @@ ldns_pkt2buffer_wire(ldns_buffer *buffer, ldns_pkt *packet)
        return LDNS_STATUS_OK;
 }
 
+/**
+ * Allocates an array of uint8_t, and puts the wireformat of the
+ * given rdf in that array. The result_size value contains the
+ * length of the array, if it succeeds, and 0 otherwise (in which case
+ * the function also returns NULL)
+ */
+uint8_t *
+ldns_rdf2wire(ldns_rdf *rdf, size_t *result_size)
+{
+       ldns_buffer *buffer = ldns_buffer_new(MAX_PACKET_SIZE);
+       uint8_t *result = NULL;
+       *result_size = 0;
+       if (ldns_rdf2buffer_wire(buffer, rdf) == LDNS_STATUS_OK) {
+               *result_size =  ldns_buffer_position(buffer);
+               result = (uint8_t *) ldns_buffer_export(buffer);
+       } else {
+               /* TODO: what about the error? */
+       }
+       ldns_buffer_free(buffer);
+       return result;
+}
+
+/**
+ * Allocates an array of uint8_t, and puts the wireformat of the
+ * given rr in that array. The result_size value contains the
+ * length of the array, if it succeeds, and 0 otherwise (in which case
+ * the function also returns NULL)
+ *
+ * If the section argument is LDNS_SECTION_QUESTION, data like ttl and rdata
+ * are not put into the result
+ */
+uint8_t *
+ldns_rr2wire(ldns_rr *rr, int section, size_t *result_size)
+{
+       ldns_buffer *buffer = ldns_buffer_new(MAX_PACKET_SIZE);
+       uint8_t *result = NULL;
+       *result_size = 0;
+       if (ldns_rr2buffer_wire(buffer, rr, section) == LDNS_STATUS_OK) {
+               *result_size =  ldns_buffer_position(buffer);
+               result = (uint8_t *) ldns_buffer_export(buffer);
+       } else {
+               /* TODO: what about the error? */
+       }
+       ldns_buffer_free(buffer);
+       return result;
+}
+
+/**
+ * Allocates an array of uint8_t, and puts the wireformat of the
+ * given packet in that array. The result_size value contains the
+ * length of the array, if it succeeds, and 0 otherwise (in which case
+ * the function also returns NULL)
+ */
+uint8_t *
+ldns_pkt2wire(ldns_pkt *packet, size_t *result_size)
+{
+       ldns_buffer *buffer = ldns_buffer_new(MAX_PACKET_SIZE);
+       uint8_t *result = NULL;
+       *result_size = 0;
+       if (ldns_pkt2buffer_wire(buffer, packet) == LDNS_STATUS_OK) {
+               *result_size =  ldns_buffer_position(buffer);
+               result = (uint8_t *) ldns_buffer_export(buffer);
+       } else {
+               /* TODO: what about the error? */
+       }
+       ldns_buffer_free(buffer);
+       return result;
+}
 
index 3cd0d5e4781dfc8afd1ace8c57305063c03e148e..d17a882ca547d9d4283de424f4cb793937cd998c 100644 (file)
@@ -16,4 +16,8 @@ ldns_status ldns_rdf2buffer_wire(ldns_buffer *buffer, ldns_rdf *rdf);
 ldns_status ldns_rr2buffer_wire(ldns_buffer *buffer, ldns_rr *rr, int section);
 ldns_status ldns_pkt2buffer_wire(ldns_buffer *buffer, ldns_pkt *pkt);
 
+uint8_t *ldns_rdf2wire(ldns_rdf *rdf, size_t *result_size);
+uint8_t *ldns_rr2wire(ldns_rr *rr, int section, size_t *result_size);
+uint8_t *ldns_pkt2wire(ldns_pkt *pkt, size_t *result_size);
+
 #endif
index 94653e0a96e688a0498be92207a1715e1a559200..adb1260da5c93daded3105b0a45173f3dea87a80 100644 (file)
@@ -183,7 +183,6 @@ main(int argc, char **argv)
 {
        const char *file;
        ldns_pkt *pkt;
-       ldns_buffer *buffer;
        uint8_t *target_buf;
        size_t len;
        uint16_t i;
@@ -203,11 +202,8 @@ main(int argc, char **argv)
        }
        
        printf("And back to wire:\n");
-       buffer = ldns_buffer_new(65535);
-       ldns_pkt2buffer_wire(buffer, pkt);
-
-       len = ldns_buffer_position(buffer);
-       target_buf = (uint8_t *) ldns_buffer_export(buffer);
+       /*buffer = ldns_buffer_new(65535);*/
+       target_buf = ldns_pkt2wire(pkt, &len);
 
        printf("Buffer length: %u\n", len);