aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/record.c46
-rw-r--r--src/record.h1
2 files changed, 41 insertions, 6 deletions
diff --git a/src/record.c b/src/record.c
index 7ba40a3..22b350f 100644
--- a/src/record.c
+++ b/src/record.c
@@ -25,6 +25,9 @@ static ssize_t record_rdata_not_implemented(char* _str, void** _rdata);
/* rdata that does not need conversion from string form */
static ssize_t record_rdata_verbatim(char* _str, void** _rdata);
+/* rdata from fqdn to qname */
+static ssize_t record_rdata_qname(char* _str, void** _rdata);
+
/* IPv4 Addresses */
static ssize_t record_rdata_a(char* _str, void** _rdata);
@@ -53,10 +56,10 @@ static const uint16_t record_types_len = sizeof(record_types) / sizeof(char*);
static ssize_t (*record_rdata_creator[])(char*, void**) = {
&record_rdata_a, /* A */
- &record_rdata_verbatim, /* NS */
+ &record_rdata_qname, /* NS */
&record_rdata_obsolete, /* MD */
&record_rdata_obsolete, /* MF */
- &record_rdata_verbatim, /* CNAME */
+ &record_rdata_qname, /* CNAME */
&record_rdata_soa, /* SOA */
&record_rdata_not_implemented,
@@ -68,7 +71,8 @@ static ssize_t (*record_rdata_creator[])(char*, void**) = {
&record_rdata_not_implemented,
&record_rdata_not_implemented,
&record_rdata_not_implemented,
- &record_rdata_not_implemented,
+
+ &record_rdata_verbatim, /* TXT */
};
static const char* const record_classes[] = {
@@ -109,6 +113,32 @@ static ssize_t record_rdata_verbatim(char* _str, void** _rdata) {
return (signed) len;
}
+static ssize_t record_rdata_qname(char* _str, void** _rdata) {
+ size_t len;
+ size_t qlen;
+
+ if ( !_str || !_rdata )
+ return -1;
+
+ len = strlen(_str); /* Including \0 */
+ qlen = len + 1;
+
+ if (fqdn_check(_str, len) < 0) {
+ LOGPRINTF(_LOG_ERROR, "Not a valid FQDN");
+ return -1;
+ }
+
+ *_rdata = malloc(qlen);
+
+ if ( !*_rdata )
+ return -1;
+
+ /*strncpy(*_rdata, _str, len);*/
+ fqdn_to_qname(_str, len, *_rdata, qlen);
+
+ return (signed) qlen;
+}
+
static ssize_t record_rdata_a(char* _str, void** _rdata) {
char* tok;
char* str;
@@ -131,12 +161,12 @@ static ssize_t record_rdata_a(char* _str, void** _rdata) {
if( !tok )
goto err;
- ((uint8_t*)(*_rdata))[3] = (uint8_t) strtol(tok, &end, 10);
+ ((uint8_t*)(*_rdata))[0] = (uint8_t) strtol(tok, &end, 10);
if( *end != '\0' )
goto err;
- for( i=2; i>=0; i-- ) {
+ for( i=1; i<4; i++) {
tok = strtok(NULL, ".");
if( !tok )
@@ -183,11 +213,15 @@ uint16_t record_type_from_str(char* _str) {
}
ssize_t record_rdata_from_str(void** _rdata, char *_str, uint16_t _rdtype) {
+ uint16_t index;
+
if ( _rdtype >= record_types_len )
return -1;
if ( !_rdata || !_str )
return -1;
- return (*record_rdata_creator)(_str, _rdata);
+ index = _rdtype - 1;
+
+ return (*record_rdata_creator[index])(_str, _rdata);
}
diff --git a/src/record.h b/src/record.h
index ef41ecb..d2acca0 100644
--- a/src/record.h
+++ b/src/record.h
@@ -11,6 +11,7 @@
#include <sys/types.h>
#include "log.h"
+#include "dns.h"
uint16_t record_class_from_str(char* _str);