Changes in lib/misc.c [36e9f62:51fdc45]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/misc.c
r36e9f62 r51fdc45 39 39 #include <glib.h> 40 40 #include <time.h> 41 42 #ifdef HAVE_RESOLV_A43 #include <arpa/nameser.h>44 #include <resolv.h>45 #endif46 41 47 42 void strip_linefeed(gchar *text) … … 493 488 return 0; 494 489 } 495 496 struct ns_srv_reply *srv_lookup( char *service, char *protocol, char *domain )497 {498 struct ns_srv_reply *reply = NULL;499 #ifdef HAVE_RESOLV_A500 char name[1024];501 unsigned char querybuf[1024];502 const unsigned char *buf;503 ns_msg nsh;504 ns_rr rr;505 int i, len, size;506 507 g_snprintf( name, sizeof( name ), "_%s._%s.%s", service, protocol, domain );508 509 if( ( size = res_query( name, ns_c_in, ns_t_srv, querybuf, sizeof( querybuf ) ) ) <= 0 )510 return NULL;511 512 if( ns_initparse( querybuf, size, &nsh ) != 0 )513 return NULL;514 515 if( ns_parserr( &nsh, ns_s_an, 0, &rr ) != 0 )516 return NULL;517 518 size = ns_rr_rdlen( rr );519 buf = ns_rr_rdata( rr );520 521 len = 0;522 for( i = 6; i < size && buf[i]; i += buf[i] + 1 )523 len += buf[i] + 1;524 525 if( i > size )526 return NULL;527 528 reply = g_malloc( sizeof( struct ns_srv_reply ) + len );529 memcpy( reply->name, buf + 7, len );530 531 for( i = buf[6]; i < len && buf[7+i]; i += buf[7+i] + 1 )532 reply->name[i] = '.';533 534 if( i > len )535 {536 g_free( reply );537 return NULL;538 }539 540 reply->prio = ( buf[0] << 8 ) | buf[1];541 reply->weight = ( buf[2] << 8 ) | buf[3];542 reply->port = ( buf[4] << 8 ) | buf[5];543 #endif544 545 return reply;546 }
Note: See TracChangeset
for help on using the changeset viewer.