Ticket #1003: openbsd-ns_parse.diff
File openbsd-ns_parse.diff, 3.0 KB (added by , at 2014-02-04T18:26:41Z) |
---|
-
lib/misc.c
$OpenBSD: patch-lib_misc_c,v 1.2 2014/01/02 13:04:34 landry Exp $ http://bugs.bitlbee.org/bitlbee/ticket/421 needed until ns_parse family of functions are added to lib/libc/asr
old new 44 44 #ifdef HAVE_RESOLV_A 45 45 #include <arpa/nameser.h> 46 46 #include <resolv.h> 47 #if defined (__OpenBSD__) 48 #include <netinet/in.h> 47 49 #endif 50 #endif 48 51 49 52 #include "md5.h" 50 53 #include "ssl_client.h" … … struct ns_srv_reply **srv_lookup( char *service, char 522 525 char name[1024]; 523 526 unsigned char querybuf[1024]; 524 527 const unsigned char *buf; 528 int i, n, len, size; 529 #if defined (__OpenBSD__) 530 char uncomp[MAXDNAME]; 531 int complen = -1; 532 unsigned int qdcount = 0, ancount = 0; 533 534 const unsigned char *comp = NULL; 535 unsigned char *end = NULL; 536 HEADER *head = NULL; 537 538 int ns_c_in = C_IN, ns_t_srv = T_SRV; 539 int prio = -1, weight = -1, port = -1; 540 #else 525 541 ns_msg nsh; 526 542 ns_rr rr; 527 int i, n, len, size; 543 #endif 528 544 529 545 g_snprintf( name, sizeof( name ), "_%s._%s.%s", service, protocol, domain ); 530 546 531 547 if( ( size = res_query( name, ns_c_in, ns_t_srv, querybuf, sizeof( querybuf ) ) ) <= 0 ) 532 548 return NULL; 549 550 n = 0; 551 552 #if defined (__OpenBSD__) 553 head = (HEADER *)querybuf; 554 comp = querybuf + HFIXEDSZ; 555 end = querybuf + size; 556 557 ancount = ntohs(head->ancount); 558 559 /* Skip over the Query part */ 560 for (qdcount = ntohs(head->qdcount); qdcount--; comp += size + QFIXEDSZ) 561 if ((size = dn_skipname(comp, end)) < 0) 562 return NULL; 563 564 565 /* Get the answers */ 566 while (ancount > 0 && comp < end) { 567 /* Skip the owner name, to which this resource record pertains. */ 568 complen = dn_expand(querybuf, end, comp, uncomp, sizeof(uncomp)); 569 if (complen < 0) 570 return NULL; 571 572 comp += complen; 573 574 575 /* Get the useful answers. */ 576 /* GETSHORT(type, comp); */ 577 comp += INT16SZ; 578 /* GETSHORT(class, comp); */ 579 comp += INT16SZ; 580 /* GETLONG(ttl, comp); */ 581 comp += INT32SZ; 582 /* GETSHORT(complen, comp); */ 583 comp += INT16SZ; 584 585 GETSHORT(prio , comp); 586 GETSHORT(weight , comp); 587 GETSHORT(port , comp); 588 complen = dn_expand(querybuf, end, comp, uncomp, sizeof(uncomp)); 589 if (complen < 0) 590 return NULL; 591 592 comp += complen; 593 594 reply = g_malloc( sizeof( struct ns_srv_reply ) + strlen(uncomp) + 1 ); 595 596 reply->prio = prio; 597 reply->weight = weight; 598 reply->port = port; 599 strlcpy( reply->name, uncomp, strlen(uncomp) + 1 ); 600 601 n++; 602 replies = g_renew( struct ns_srv_reply *, replies, n + 1 ); 603 replies[n-1] = reply; 604 605 ancount--; 606 } 607 #else 533 608 534 609 if( ns_initparse( querybuf, size, &nsh ) != 0 ) 535 610 return NULL; 536 611 537 n = 0;538 612 while( ns_parserr( &nsh, ns_s_an, n, &rr ) == 0 ) 539 613 { 540 614 size = ns_rr_rdlen( rr ); … … struct ns_srv_reply **srv_lookup( char *service, char 567 641 replies = g_renew( struct ns_srv_reply *, replies, n + 1 ); 568 642 replies[n-1] = reply; 569 643 } 644 #endif 570 645 if( replies ) 571 646 replies[n] = NULL; 572 647 #endif