aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2019-11-30 12:29:12 +0100
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2019-11-30 12:29:12 +0100
commit3efdb35480dd6fa656d0728cab5c8dc76eaba24c (patch)
tree77ba48da71c22eba4fd47310e05a313cf6e68583 /src
parent9a8214e0304a1dffe0a321d96d01045cfc34c8e8 (diff)
downloaddns-3efdb35480dd6fa656d0728cab5c8dc76eaba24c.tar.gz
added qname_to_fqdn(), working
Diffstat (limited to 'src')
-rw-r--r--src/dns.c27
-rw-r--r--src/dns.h4
2 files changed, 27 insertions, 4 deletions
diff --git a/src/dns.c b/src/dns.c
index 54ad504..7c94c8a 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -2,7 +2,6 @@
int fqdn_to_qname( char* _source, int _sourcelen, char* _sink ,int _sinklen )
{
- // TODO Opttimize
int i;
int lastdot = 0;
@@ -17,7 +16,7 @@ int fqdn_to_qname( char* _source, int _sourcelen, char* _sink ,int _sinklen )
_sink[i+1] = _source[i];
}
- if( _source[i] ) // _source not terminated
+ if( _source[i] ) // _source not terminated, thus no valid string
return -1;
for (int o = 0; o < i; o++) {
@@ -36,5 +35,27 @@ int fqdn_to_qname( char* _source, int _sourcelen, char* _sink ,int _sinklen )
int qname_to_fqdn( char* _source, int _sourcelen, char* _sink, int _sinklen )
{
- return -1;
+ if ( !_sourcelen || !_sinklen ) {
+ return -1;
+ }
+
+ unsigned int next_dot = _source[0] + 1;
+ int i = 1;
+ for(i = 1; i < _sourcelen; i++) {
+ if( i > _sinklen){ //Output too small. Not >= bc sink[i-1] is used
+ return -1;
+ }
+ if ( !_source[i] ) {
+ _sink[i-1] = '\0';
+ break;
+ } else if (i == next_dot) {
+ _sink[i-1]='.';
+ next_dot = _source[i] + i + 1;
+ } else {
+ _sink[i-1] = _source[i];
+ }
+
+ }
+
+ return i-1;
}
diff --git a/src/dns.h b/src/dns.h
index 9f66367..5d8096e 100644
--- a/src/dns.h
+++ b/src/dns.h
@@ -12,6 +12,8 @@
int fqdn_to_qname( char* _source, int _sourcelen, char* _sink, int _sinklen );
/**
- * Opposite of fqdn_to_qname()
+ * Convert a QNAME back to a FQDN, reversing fqdn_to_qname( )
+ * returns: length of string in _sink, < 0 on failure
+ * _sink may still be altered in failed attempts, but not terminated.
* */
int qname_to_fqdn( char* _source, int _sourcelen, char* _sink, int _sinklen );