- Timestamp:
- 2010-08-14T13:44:35Z (14 years ago)
- Branches:
- master
- Children:
- e5854a8
- Parents:
- 5848675 (diff), 136c2bb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/misc.c
r5848675 r07874be 505 505 } 506 506 507 struct ns_srv_reply * srv_lookup( char *service, char *protocol, char *domain )507 struct ns_srv_reply **srv_lookup( char *service, char *protocol, char *domain ) 508 508 { 509 struct ns_srv_reply **replies = NULL; 510 #ifdef HAVE_RESOLV_A 509 511 struct ns_srv_reply *reply = NULL; 510 #ifdef HAVE_RESOLV_A511 512 char name[1024]; 512 513 unsigned char querybuf[1024]; … … 514 515 ns_msg nsh; 515 516 ns_rr rr; 516 int i, len, size;517 int i, n, len, size; 517 518 518 519 g_snprintf( name, sizeof( name ), "_%s._%s.%s", service, protocol, domain ); … … 524 525 return NULL; 525 526 526 if( ns_parserr( &nsh, ns_s_an, 0, &rr ) != 0 ) 527 return NULL; 528 529 size = ns_rr_rdlen( rr ); 530 buf = ns_rr_rdata( rr ); 531 532 len = 0; 533 for( i = 6; i < size && buf[i]; i += buf[i] + 1 ) 534 len += buf[i] + 1; 535 536 if( i > size ) 537 return NULL; 538 539 reply = g_malloc( sizeof( struct ns_srv_reply ) + len ); 540 memcpy( reply->name, buf + 7, len ); 541 542 for( i = buf[6]; i < len && buf[7+i]; i += buf[7+i] + 1 ) 543 reply->name[i] = '.'; 544 545 if( i > len ) 546 { 547 g_free( reply ); 548 return NULL; 549 } 550 551 reply->prio = ( buf[0] << 8 ) | buf[1]; 552 reply->weight = ( buf[2] << 8 ) | buf[3]; 553 reply->port = ( buf[4] << 8 ) | buf[5]; 527 n = 0; 528 while( ns_parserr( &nsh, ns_s_an, n, &rr ) == 0 ) 529 { 530 size = ns_rr_rdlen( rr ); 531 buf = ns_rr_rdata( rr ); 532 533 len = 0; 534 for( i = 6; i < size && buf[i]; i += buf[i] + 1 ) 535 len += buf[i] + 1; 536 537 if( i > size ) 538 break; 539 540 reply = g_malloc( sizeof( struct ns_srv_reply ) + len ); 541 memcpy( reply->name, buf + 7, len ); 542 543 for( i = buf[6]; i < len && buf[7+i]; i += buf[7+i] + 1 ) 544 reply->name[i] = '.'; 545 546 if( i > len ) 547 { 548 g_free( reply ); 549 break; 550 } 551 552 reply->prio = ( buf[0] << 8 ) | buf[1]; 553 reply->weight = ( buf[2] << 8 ) | buf[3]; 554 reply->port = ( buf[4] << 8 ) | buf[5]; 555 556 n ++; 557 replies = g_renew( struct ns_srv_reply *, replies, n + 1 ); 558 replies[n-1] = reply; 559 } 560 if( replies ) 561 replies[n] = NULL; 554 562 #endif 555 563 556 return reply; 564 return replies; 565 } 566 567 void srv_free( struct ns_srv_reply **srv ) 568 { 569 int i; 570 571 if( srv == NULL ) 572 return; 573 574 for( i = 0; srv[i]; i ++ ) 575 g_free( srv[i] ); 576 g_free( srv ); 557 577 } 558 578 -
lib/misc.h
r5848675 r07874be 61 61 G_MODULE_EXPORT int bool2int( char *value ); 62 62 63 G_MODULE_EXPORT struct ns_srv_reply *srv_lookup( char *service, char *protocol, char *domain ); 63 G_MODULE_EXPORT struct ns_srv_reply **srv_lookup( char *service, char *protocol, char *domain ); 64 G_MODULE_EXPORT void srv_free( struct ns_srv_reply **srv ); 64 65 65 66 G_MODULE_EXPORT char *word_wrap( const char *msg, int line_len );
Note: See TracChangeset
for help on using the changeset viewer.