- Timestamp:
- 2006-10-07T17:46:28Z (18 years ago)
- Branches:
- master
- Children:
- 038d17f
- Parents:
- 090f1cb
- Location:
- lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/misc.c
r090f1cb r36e9f62 39 39 #include <glib.h> 40 40 #include <time.h> 41 42 #ifdef HAVE_RESOLV_A 43 #include <arpa/nameser.h> 44 #include <resolv.h> 45 #endif 41 46 42 47 void strip_linefeed(gchar *text) … … 488 493 return 0; 489 494 } 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_A 500 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 #endif 544 545 return reply; 546 } -
lib/misc.h
r090f1cb r36e9f62 30 30 #include <time.h> 31 31 32 struct ns_srv_reply 33 { 34 int prio; 35 int weight; 36 int port; 37 char name[]; 38 }; 39 32 40 G_MODULE_EXPORT void strip_linefeed( gchar *text ); 33 41 G_MODULE_EXPORT char *add_cr( char *text ); … … 54 62 G_MODULE_EXPORT int bool2int( char *value ); 55 63 64 G_MODULE_EXPORT struct ns_srv_reply *srv_lookup( char *service, char *protocol, char *domain ); 65 56 66 #endif
Note: See TracChangeset
for help on using the changeset viewer.