aboutsummaryrefslogtreecommitdiffstats
path: root/lib/misc.c
diff options
context:
space:
mode:
authorjcopenha <jcopenha@typedef.org>2014-07-24 00:51:07 -0300
committerdequis <dx@dxzone.com.ar>2014-07-24 00:51:07 -0300
commit632627e1ead19fc7dc07effe441b2d543a675229 (patch)
tree84d8aac19b33ad72e1711a2a88ad6a7958c060ef /lib/misc.c
parent59e66ff766cbef04883c1d7477d66c7e9b515833 (diff)
srv_lookup: Portability fixes, handle compressed responses
srv_lookup works on cygwin and openbsd now. Provide ns_initparse, friends, and types where they aren't provided by platform. Use dn_expandname instead of custom parser so compressed DNS responses are handled correctly.
Diffstat (limited to 'lib/misc.c')
-rw-r--r--lib/misc.c27
1 files changed, 10 insertions, 17 deletions
diff --git a/lib/misc.c b/lib/misc.c
index 2506e291..f1da03cb 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -524,7 +524,7 @@ struct ns_srv_reply **srv_lookup( char *service, char *protocol, char *domain )
const unsigned char *buf;
ns_msg nsh;
ns_rr rr;
- int i, n, len, size;
+ int n, len, size;
g_snprintf( name, sizeof( name ), "_%s._%s.%s", service, protocol, domain );
@@ -537,27 +537,20 @@ struct ns_srv_reply **srv_lookup( char *service, char *protocol, char *domain )
n = 0;
while( ns_parserr( &nsh, ns_s_an, n, &rr ) == 0 )
{
- size = ns_rr_rdlen( rr );
+ char name[NS_MAXDNAME];
+
+ if( ns_rr_rdlen( rr ) < 7)
+ break;
+
buf = ns_rr_rdata( rr );
- len = 0;
- for( i = 6; i < size && buf[i]; i += buf[i] + 1 )
- len += buf[i] + 1;
-
- if( i > size )
+ if( dn_expand(querybuf, querybuf + size, &buf[6], name, NS_MAXDNAME) == -1 )
break;
+
+ len = strlen(name) + 1;
reply = g_malloc( sizeof( struct ns_srv_reply ) + len );
- memcpy( reply->name, buf + 7, len );
-
- for( i = buf[6]; i < len && buf[7+i]; i += buf[7+i] + 1 )
- reply->name[i] = '.';
-
- if( i > len )
- {
- g_free( reply );
- break;
- }
+ memcpy( reply->name, name, len );
reply->prio = ( buf[0] << 8 ) | buf[1];
reply->weight = ( buf[2] << 8 ) | buf[3];