diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2021-09-19 23:15:27 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2021-09-19 23:16:48 +0200 |
commit | 839a9de688f0a3c09ab8ef00337ca03c32c44796 (patch) | |
tree | 6d3734e5b2349c8503c27f6f1d5fe8d48b5160f4 /src/dns.c | |
parent | 2909e565636dd10eb322a3b2bd3296b8292240f9 (diff) | |
download | dns-839a9de688f0a3c09ab8ef00337ca03c32c44796.tar.gz |
add fqdn_check()
Diffstat (limited to 'src/dns.c')
-rw-r--r-- | src/dns.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -228,6 +228,35 @@ int fqdn_to_qname( char* _source, int _sourcelen, char* _sink ,int _sinklen ) return i+2; } +int fqdn_check ( char* _source, int _sourcelen ) { + int i; + char c; + + if ( !_source || _sourcelen <= 0 ) + return -1; + + for( i=0; i<_sourcelen; i++ ) { + c = _source[i]; + if (!c) + break; + if ( + !(c>='0' && c<='9') && + !(c>='A' && c<='Z') && + !(c>='a' && c<='z') && + !(c== '-') && !(c=='_') && !(c=='.') + ) { + return i+1; + } + } + + if ( _source[ i-1 ] != '.' ) + return i; + if ( _source[ 0 ] == '-' ) + return 1; + + return 0; +} + int qname_to_fqdn( char* _source, int _sourcelen, char* _sink, int _sinklen ) { unsigned int next_dot; |