]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
another conversion routine
authorMiek Gieben <miekg@NLnetLabs.nl>
Mon, 21 Feb 2005 12:31:56 +0000 (12:31 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Mon, 21 Feb 2005 12:31:56 +0000 (12:31 +0000)
13 files changed:
TODO
host2str.c
host2wire.c
ldns/error.h
ldns/packet.h
ldns/rdata.h
ldns/rr.h
ldns/str2host.h
libdns.vim
net.c
run-test0.c
str2host.c
wire2host.c

diff --git a/TODO b/TODO
index 1b82af5e5b4ef5b8fcebfcaebd0b724fb730383d..f97724692b84a665da2aa1fb97078284fbd22ca7 100644 (file)
--- a/TODO
+++ b/TODO
@@ -2,7 +2,6 @@ Current TODO list
 
 Errors:
 o names starting with a dot .www or not handled correctly
-o absolute/relative dnames???
 
 
 Implementation:
@@ -20,8 +19,6 @@ o network code
          sane default values
 o DNSSEC
 o Make a shared library and test compile some programs
-o Higherlevel functions, like search for this RR with this name in
-  these RRlists. Give me all RR's of this zone with this type. etc.
 
 Documentation:
 --------------
@@ -35,7 +32,8 @@ o Mailing list(s)
 
 To ponder and discuss:
 ----------------------
-o Drop ldns_resolver_set_configured() ?
-o char * <=> uint8_t *
-o Second layer (higher level convenience functions)?
+o char * <=> uint8_t * (partly done? Erik?)
+o Second layer (higher level convenience functions)? (Later)
+  o Higherlevel functions, like search for this RR with this name in
+    these RRlists. Give me all RR's of this zone with this type. etc.
 o Dependency on openSSL?
index 760288a7f812f1d9af1c3228bc333fce7704c5f8..3739868281422fab5fedb008d063eb3721b5e335 100644 (file)
@@ -1008,7 +1008,7 @@ ldns_pkt2str(ldns_pkt *pkt)
 {
        char *result = NULL;
        /* XXX MAXTEXTPACKET?? */
-       ldns_buffer *tmp_buffer = ldns_buffer_new(MAX_PACKET_SIZE);
+       ldns_buffer *tmp_buffer = ldns_buffer_new(MAX_PACKETLEN);
 
        if (ldns_pkt2buffer_str(tmp_buffer, pkt) == LDNS_STATUS_OK) {
                /* export and return string, destroy rest */
index e6a3778eb4665e826f05286218a07b6a8594db5f..9be10a869ea22998a89e10d3799623ae978cd623 100644 (file)
@@ -174,7 +174,7 @@ ldns_pkt2buffer_wire(ldns_buffer *buffer, ldns_pkt *packet)
 uint8_t *
 ldns_rdf2wire(ldns_rdf *rdf, size_t *result_size)
 {
-       ldns_buffer *buffer = ldns_buffer_new(MAX_PACKET_SIZE);
+       ldns_buffer *buffer = ldns_buffer_new(MAX_PACKETLEN);
        uint8_t *result = NULL;
        *result_size = 0;
        if (ldns_rdf2buffer_wire(buffer, rdf) == LDNS_STATUS_OK) {
@@ -199,7 +199,7 @@ ldns_rdf2wire(ldns_rdf *rdf, size_t *result_size)
 uint8_t *
 ldns_rr2wire(ldns_rr *rr, int section, size_t *result_size)
 {
-       ldns_buffer *buffer = ldns_buffer_new(MAX_PACKET_SIZE);
+       ldns_buffer *buffer = ldns_buffer_new(MAX_PACKETLEN);
        uint8_t *result = NULL;
        *result_size = 0;
        if (ldns_rr2buffer_wire(buffer, rr, section) == LDNS_STATUS_OK) {
@@ -221,7 +221,7 @@ ldns_rr2wire(ldns_rr *rr, int section, size_t *result_size)
 uint8_t *
 ldns_pkt2wire(ldns_pkt *packet, size_t *result_size)
 {
-       ldns_buffer *buffer = ldns_buffer_new(MAX_PACKET_SIZE);
+       ldns_buffer *buffer = ldns_buffer_new(MAX_PACKETLEN);
        uint8_t *result = NULL;
        *result_size = 0;
        if (ldns_pkt2buffer_wire(buffer, packet) == LDNS_STATUS_OK) {
index 02bf0fef5feabde4df71d9067e0e456e588c07d9..20d45abce36ab529350fb89a48f07e7056e2f4f5 100644 (file)
@@ -30,7 +30,8 @@ enum ldns_enum_status
        LDNS_STATUS_INVALID_IP4,
        LDNS_STATUS_INVALID_IP6,
        LDNS_STATUS_INVALID_STR,
-       LDNS_STATUS_INVALID_B64
+       LDNS_STATUS_INVALID_B64,
+       LDNS_STATUS_INVALID_HEX
 };
 typedef enum ldns_enum_status ldns_status;
 
index 074517eebf748b8e4e4637d40c220ac05976a009..74441b348b8a83b09a4d56354dea5cd5b01b388d 100644 (file)
@@ -171,7 +171,7 @@ void ldns_pkt_free(ldns_pkt *packet);
 ldns_pkt * ldns_pkt_query_new_frm_str(const char *, ldns_rr_type, ldns_rr_class, uint16_t);
 ldns_pkt * ldns_pkt_query_new(ldns_rdf *, ldns_rr_type, ldns_rr_class, uint16_t);
 
-#define MAX_PACKET_SIZE         65535
+#define MAX_PACKETLEN         65535
 
 /* allow flags to be given to mk_query */
 #define LDNS_QR                1
index c90862e1757d42fee846a6e0dc86267fe5907865..477319b5761623c59da54bc029c61b8163d0deaa 100644 (file)
@@ -17,6 +17,7 @@
 #include <ldns/common.h>
 #include <ldns/error.h>
 
+#define MAX_RDFLEN     65535
 
 /**
  * The different types of RDATA fields.
index 38122892e4c4e5b4e8cabf1813e609d925647dac..37d0341e52fdea76671a66889eaa816b7e68f08d 100644 (file)
--- a/ldns/rr.h
+++ b/ldns/rr.h
@@ -168,11 +168,11 @@ enum ldns_enum_rr_type
 typedef enum ldns_enum_rr_type ldns_rr_type;
 
 /** Maximum length of a dname label */
-#define MAXLABELLEN     63
+#define MAX_LABELLEN     63
 /** Maximum length of a complete dname */
-#define MAXDOMAINLEN    255
+#define MAX_DOMAINLEN    255
 /** Maximum number of pointers in 1 dname */
-#define MAXPOINTERS    65535
+#define MAX_POINTERS   65535
 
 /**
  * \brief Resource Record type
index 3691550f4c5df04c7c5eaa65e668aa40b87d0002..3a5fd65b92c62bb02681097fee57d41510413fb9 100644 (file)
@@ -31,7 +31,7 @@ ldns_status ldns_str2rdf_service(ldns_rdf **, const char *);
 ldns_status ldns_str2rdf_loc(ldns_rdf **, const char *);
 ldns_status ldns_str2rdf_wks(ldns_rdf **, const char *);
 ldns_status ldns_str2rdf_nsap(ldns_rdf **, const char *);
-
+ldns_status ldns_str2rdf_nsap(ldns_rdf **, const char *);
 ldns_status ldns_str2rdf_dname(ldns_rdf **, const char *);
 
-#endif
+#endif /* _LDNS_2HOST_H */
index 5023855b3c6a91f203c9a813d281e9758e34ab15..3b0e77c1b6039b6d729ab5cce7c42a6f21f90839 100644 (file)
@@ -45,6 +45,7 @@ syn keyword  ldnsConstant     LDNS_RDF_TYPE_SERVICE
 syn keyword  ldnsConstant      LDNS_RDF_TYPE_LOC
 syn keyword  ldnsConstant      LDNS_RDF_TYPE_WKS
 syn keyword  ldnsConstant      LDNS_RDF_TYPE_NSAP
+syn keyword  ldnsConstant      MAX_RDFLEN
 
 " ldns/dns.h
 syn keyword  ldnsConstant      LDNS_PORT
@@ -67,6 +68,8 @@ syn keyword  ldnsConstant     LDNS_SECTION_QUESTION
 syn keyword  ldnsConstant      LDNS_SECTION_ANSWER
 syn keyword  ldnsConstant      LDNS_SECTION_AUTHORITY
 syn keyword  ldnsConstant      LDNS_SECTION_ADDITIONAL
+syn keyword  ldnsConstant      MAX_PACKETLEN
+
 
 " dns/error.h
 syn keyword ldnsMacro  LDNS_STATUS_OK
@@ -142,8 +145,8 @@ syn keyword  ldnsConstant LDNS_RR_TYPE_AXFR
 syn keyword  ldnsConstant LDNS_RR_TYPE_MAILB      
 syn keyword  ldnsConstant LDNS_RR_TYPE_MAILA      
 syn keyword  ldnsConstant LDNS_RR_TYPE_ANY        
-syn keyword  ldnsConstant MAXLABELLEN     
-syn keyword  ldnsConstant MAXDOMAINLEN
+syn keyword  ldnsConstant MAX_LABELLEN     
+syn keyword  ldnsConstant MAX_DOMAINLEN
 syn keyword  ldnsConstant LDNS_RR_COMPRESS
 syn keyword  ldnsConstant LDNS_RR_NO_COMPRESS
 
diff --git a/net.c b/net.c
index 13108bb96befbe91772801a7d9a679d73d43218f..57531a16f0897016037e4b84564d2c6ddf1f6aec 100644 (file)
--- a/net.c
+++ b/net.c
@@ -69,7 +69,7 @@ ldns_send(ldns_resolver *r, ldns_pkt *query_pkt)
        ns_array = ldns_resolver_nameservers(r);
        reply = NULL; ns_len = 0;
        
-       qb = ldns_buffer_new(MAX_PACKET_SIZE);
+       qb = ldns_buffer_new(MAX_PACKETLEN);
 
        if (ldns_pkt2buffer_wire(qb, query_pkt) != LDNS_STATUS_OK) {
                printf("could not convert to wire fmt\n");
@@ -166,13 +166,13 @@ ldns_send_udp(ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t to
        }
        
        /* wait for an response*/
-       answer = XMALLOC(uint8_t, MAX_PACKET_SIZE);
+       answer = XMALLOC(uint8_t, MAX_PACKETLEN);
        if (!answer) {
                printf("respons alloc error\n");
                return NULL;
        }
 
-       bytes = recv(sockfd, answer, MAX_PACKET_SIZE, 0);
+       bytes = recv(sockfd, answer, MAX_PACKETLEN, 0);
 
        close(sockfd);
 
@@ -262,7 +262,7 @@ ldns_send_tcp(ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t to
        }
        
        /* wait for an response*/
-       answer = XMALLOC(uint8_t, MAX_PACKET_SIZE);
+       answer = XMALLOC(uint8_t, MAX_PACKETLEN);
        if (!answer) {
                printf("respons alloc error\n");
                return NULL;
@@ -272,7 +272,7 @@ ldns_send_tcp(ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t to
           we must be sure that we receive those */
        total_bytes = 0;
        while (total_bytes < 2) {
-               bytes = recv(sockfd, answer, MAX_PACKET_SIZE, 0);
+               bytes = recv(sockfd, answer, MAX_PACKETLEN, 0);
                if (bytes == -1) {
                        if (errno == EAGAIN) {
                                fprintf(stderr, "socket timeout\n");
@@ -290,7 +290,7 @@ ldns_send_tcp(ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t to
        /* if we did not receive the whole packet in one tcp packet,
           we must recv() on */
        while (total_bytes < (ssize_t) (answer_size + 2)) {
-               bytes = recv(sockfd, answer+total_bytes, (size_t) (MAX_PACKET_SIZE-total_bytes), 0);
+               bytes = recv(sockfd, answer + total_bytes, (size_t) (MAX_PACKETLEN - total_bytes), 0);
                if (bytes == -1) {
                        if (errno == EAGAIN) {
                                fprintf(stderr, "socket timeout\n");
index 11f55cf8da195d9b68c9f475e52a2a7ad93af1dd..b8fb9bdfd5809f0642fc24ed2ccf0f2229714bc1 100644 (file)
@@ -57,7 +57,7 @@ main(void)
        
        rr = ldns_rr_new();
 
-       rdf_data = (uint8_t *) XMALLOC(char, MAXDOMAINLEN);
+       rdf_data = (uint8_t *) XMALLOC(char, MAX_DOMAINLEN);
        rdf_data[0] = 3;
        memcpy(rdf_data+1, "www", 3);
        rdf_data[4] = 4;
index 8d867cdf6785741e32bace3cacbab46dc960f816..0b62e0c45c1c19e7194776ae684a876e7a24cd7d 100644 (file)
@@ -150,10 +150,10 @@ ldns_str2rdf_dname(ldns_rdf **d, const char *str)
        size_t len;
 
        uint8_t *s,*p,*q, *pq, val, label_len;
-       uint8_t buf[MAXDOMAINLEN + 1];
+       uint8_t buf[MAX_DOMAINLEN + 1];
        
        len = strlen((char*)str);
-       if (len > MAXDOMAINLEN) {
+       if (len > MAX_DOMAINLEN) {
                return LDNS_STATUS_DOMAINNAME_OVERFLOW;
        }
        if (0 == len) {
@@ -173,7 +173,7 @@ ldns_str2rdf_dname(ldns_rdf **d, const char *str)
                switch (*s) {
                case '.':
                        /* todo: check length (overflow und <1 */
-                       if (label_len > MAXLABELLEN) {
+                       if (label_len > MAX_LABELLEN) {
                                return LDNS_STATUS_LABEL_OVERFLOW;
                        }
                        if (label_len == 0) {
@@ -309,15 +309,43 @@ ldns_str2rdf_b64(ldns_rdf **rd, const char *str)
 }
 
 /**
- * convert .... into wireformat
+ * convert a hex value into wireformat
  * \param[in] rd the rdf where to put the data
  * \param[in] str the string to be converted
  * \return ldns_status
  */
 ldns_status
-ldns_str2rdf_hex(ldns_rdf **ATTR_UNUSED(rd), const char *ATTR_UNUSED(str))
+ldns_str2rdf_hex(ldns_rdf **rd, const char *str)
 {
-       abort();
+        uint8_t *t;
+        int i;
+       size_t len;
+
+       len = strlen(str);
+
+        if (len % 2 != 0) {
+                return LDNS_STATUS_INVALID_HEX;
+        } else if (len > MAX_RDFLEN * 2) {
+               return LDNS_STATUS_LABEL_OVERFLOW;
+        } else {
+               t = XMALLOC(uint8_t, (len / 2));
+    
+                /* Now process octet by octet... */
+                while (*str) {
+                        *t = 0;
+                        for (i = 16; i >= 1; i -= 15) {
+                                if (isxdigit(*str)) {
+                                        *t += hexdigit_to_int(*str) * i;
+                                } else {
+                                        return LDNS_STATUS_ERR;
+                                }
+                                ++str;
+                        }
+                        ++t;
+                }
+               *rd = ldns_rdf_new_frm_data(len / 2, LDNS_RDF_TYPE_HEX, t);
+        }
+        return LDNS_STATUS_OK;
 }
 
 /**
index 8744edb3a271e030c1cf1063dfe430cff1e5421c..6fb2c5cfa49a7f16f61f8efe0957ac37b021a2d2 100644 (file)
@@ -145,7 +145,7 @@ ldns_wire2dname(ldns_rdf **dname, const uint8_t *wire, size_t max, size_t *pos)
        size_t dname_pos = 0;
        size_t uncompressed_length = 0;
        size_t compression_pos = 0;
-       uint8_t tmp_dname[MAXDOMAINLEN];
+       uint8_t tmp_dname[MAX_DOMAINLEN];
        uint8_t *dname_ar;
        unsigned int pointer_count = 0;
        
@@ -172,13 +172,13 @@ ldns_wire2dname(ldns_rdf **dname, const uint8_t *wire, size_t max, size_t *pos)
                                return LDNS_STATUS_INVALID_POINTER;
                        } else if (pointer_target > max) {
                                return LDNS_STATUS_INVALID_POINTER;
-                       } else if (pointer_count > MAXPOINTERS) {
+                       } else if (pointer_count > MAX_POINTERS) {
                                return LDNS_STATUS_INVALID_POINTER;
                        }
                        *pos = pointer_target;
                        label_size = wire[*pos];
                }
-               if (label_size > MAXLABELLEN) {
+               if (label_size > MAX_LABELLEN) {
                        return LDNS_STATUS_LABEL_OVERFLOW;
                }
                if (*pos + label_size > max) {