- Timestamp:
- 2010-08-10T11:18:09Z (14 years ago)
- Branches:
- master
- Children:
- 72176c1
- Parents:
- f32c14c
- Location:
- lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/misc.c
rf32c14c rffdf2e7 508 508 } 509 509 510 struct ns_srv_reply * srv_lookup( char *service, char *protocol, char *domain )510 struct ns_srv_reply **srv_lookup( char *service, char *protocol, char *domain ) 511 511 { 512 struct ns_srv_reply **replies = NULL; 513 #ifdef HAVE_RESOLV_A 512 514 struct ns_srv_reply *reply = NULL; 513 #ifdef HAVE_RESOLV_A514 515 char name[1024]; 515 516 unsigned char querybuf[1024]; … … 517 518 ns_msg nsh; 518 519 ns_rr rr; 519 int i, len, size;520 int i, n, len, size; 520 521 521 522 g_snprintf( name, sizeof( name ), "_%s._%s.%s", service, protocol, domain ); … … 527 528 return NULL; 528 529 529 if( ns_parserr( &nsh, ns_s_an, 0, &rr ) != 0 ) 530 return NULL; 531 532 size = ns_rr_rdlen( rr ); 533 buf = ns_rr_rdata( rr ); 534 535 len = 0; 536 for( i = 6; i < size && buf[i]; i += buf[i] + 1 ) 537 len += buf[i] + 1; 538 539 if( i > size ) 540 return NULL; 541 542 reply = g_malloc( sizeof( struct ns_srv_reply ) + len ); 543 memcpy( reply->name, buf + 7, len ); 544 545 for( i = buf[6]; i < len && buf[7+i]; i += buf[7+i] + 1 ) 546 reply->name[i] = '.'; 547 548 if( i > len ) 549 { 550 g_free( reply ); 551 return NULL; 552 } 553 554 reply->prio = ( buf[0] << 8 ) | buf[1]; 555 reply->weight = ( buf[2] << 8 ) | buf[3]; 556 reply->port = ( buf[4] << 8 ) | buf[5]; 530 n = 0; 531 while( ns_parserr( &nsh, ns_s_an, n, &rr ) == 0 ) 532 { 533 size = ns_rr_rdlen( rr ); 534 buf = ns_rr_rdata( rr ); 535 536 len = 0; 537 for( i = 6; i < size && buf[i]; i += buf[i] + 1 ) 538 len += buf[i] + 1; 539 540 if( i > size ) 541 break; 542 543 reply = g_malloc( sizeof( struct ns_srv_reply ) + len ); 544 memcpy( reply->name, buf + 7, len ); 545 546 for( i = buf[6]; i < len && buf[7+i]; i += buf[7+i] + 1 ) 547 reply->name[i] = '.'; 548 549 if( i > len ) 550 { 551 g_free( reply ); 552 break; 553 } 554 555 reply->prio = ( buf[0] << 8 ) | buf[1]; 556 reply->weight = ( buf[2] << 8 ) | buf[3]; 557 reply->port = ( buf[4] << 8 ) | buf[5]; 558 559 n ++; 560 replies = g_renew( struct ns_srv_reply *, replies, n + 1 ); 561 replies[n-1] = reply; 562 } 563 if( replies ) 564 replies[n] = NULL; 557 565 #endif 558 566 559 return reply; 567 return replies; 568 } 569 570 void srv_free( struct ns_srv_reply **srv ) 571 { 572 int i; 573 574 if( srv == NULL ) 575 return; 576 577 for( i = 0; srv[i]; i ++ ) 578 g_free( srv[i] ); 579 g_free( srv ); 560 580 } 561 581 -
lib/misc.h
rf32c14c rffdf2e7 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.