Changeset 0fd8559 for lib/misc.c


Ignore:
Timestamp:
2007-02-18T17:48:04Z (17 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
0f4c1bb5
Parents:
8de63c3 (diff), c7d0f41 (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.
Message:

Merging new Jabber module. See the massive changelog for all the cool
improvements. :-)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/misc.c

    r8de63c3 r0fd8559  
    3939#include <glib.h>
    4040#include <time.h>
     41
     42#ifdef HAVE_RESOLV_A
     43#include <arpa/nameser.h>
     44#include <resolv.h>
     45#endif
    4146
    4247void strip_linefeed(gchar *text)
     
    488493        return 0;
    489494}
     495
     496struct 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}
Note: See TracChangeset for help on using the changeset viewer.