Changeset 632627e for lib/misc.c


Ignore:
Timestamp:
2014-07-24T03:51:07Z (6 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
f93fd2d
Parents:
59e66ff
git-author:
jcopenha <jcopenha@…> (24-07-14 03:51:07)
git-committer:
dequis <dx@…> (24-07-14 03:51:07)
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/misc.c

    r59e66ff r632627e  
    525525        ns_msg nsh;
    526526        ns_rr rr;
    527         int i, n, len, size;
     527        int n, len, size;
    528528       
    529529        g_snprintf( name, sizeof( name ), "_%s._%s.%s", service, protocol, domain );
     
    538538        while( ns_parserr( &nsh, ns_s_an, n, &rr ) == 0 )
    539539        {
    540                 size = ns_rr_rdlen( rr );
     540                char name[NS_MAXDNAME];
     541
     542                if( ns_rr_rdlen( rr ) < 7)
     543                    break;
     544
    541545                buf = ns_rr_rdata( rr );
    542546               
    543                 len = 0;
    544                 for( i = 6; i < size && buf[i]; i += buf[i] + 1 )
    545                         len += buf[i] + 1;
    546                
    547                 if( i > size )
     547                if( dn_expand(querybuf, querybuf + size, &buf[6], name, NS_MAXDNAME) == -1 )
    548548                        break;
     549
     550                len = strlen(name) + 1;
    549551               
    550552                reply = g_malloc( sizeof( struct ns_srv_reply ) + len );
    551                 memcpy( reply->name, buf + 7, len );
    552                
    553                 for( i = buf[6]; i < len && buf[7+i]; i += buf[7+i] + 1 )
    554                         reply->name[i] = '.';
    555                
    556                 if( i > len )
    557                 {
    558                         g_free( reply );
    559                         break;
    560                 }
     553                memcpy( reply->name, name, len );
    561554               
    562555                reply->prio = ( buf[0] << 8 ) | buf[1];
Note: See TracChangeset for help on using the changeset viewer.