Errors:
o names starting with a dot .www or not handled correctly
-o absolute/relative dnames???
Implementation:
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:
--------------
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?
{
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 */
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) {
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) {
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) {
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;
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
#include <ldns/common.h>
#include <ldns/error.h>
+#define MAX_RDFLEN 65535
/**
* The different types of RDATA fields.
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
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 */
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
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
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
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");
}
/* 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);
}
/* 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;
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");
/* 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");
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;
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) {
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) {
}
/**
- * 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;
}
/**
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;
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) {