Index: configure
===================================================================
--- configure	(revision 090f1cbe72373b31e753af4a1442ddd53b02791b)
+++ configure	(revision 36e9f62a6e6fdb1217b3b819320ac5a94025c448)
@@ -318,4 +318,12 @@
 
 echo 'SSL_CLIENT=ssl_'$ssl'.o' >> Makefile.settings
+
+for i in /lib /usr/lib /usr/local/lib; do
+	if [ -e $i/libresolv.a ]; then
+		echo '#define HAVE_RESOLV_A' >> config.h
+		echo 'EFLAGS+='$i'/libresolv.a' >> Makefile.settings
+		break
+	fi
+done
 
 STORAGES="text xml"
Index: lib/misc.c
===================================================================
--- lib/misc.c	(revision 090f1cbe72373b31e753af4a1442ddd53b02791b)
+++ lib/misc.c	(revision 36e9f62a6e6fdb1217b3b819320ac5a94025c448)
@@ -39,4 +39,9 @@
 #include <glib.h>
 #include <time.h>
+
+#ifdef HAVE_RESOLV_A
+#include <arpa/nameser.h>
+#include <resolv.h>
+#endif
 
 void strip_linefeed(gchar *text)
@@ -488,2 +493,54 @@
 	return 0;
 }
+
+struct ns_srv_reply *srv_lookup( char *service, char *protocol, char *domain )
+{	
+	struct ns_srv_reply *reply = NULL;
+#ifdef HAVE_RESOLV_A
+	char name[1024];
+	unsigned char querybuf[1024];
+	const unsigned char *buf;
+	ns_msg nsh;
+	ns_rr rr;
+	int i, len, size;
+	
+	g_snprintf( name, sizeof( name ), "_%s._%s.%s", service, protocol, domain );
+	
+	if( ( size = res_query( name, ns_c_in, ns_t_srv, querybuf, sizeof( querybuf ) ) ) <= 0 )
+		return NULL;
+	
+	if( ns_initparse( querybuf, size, &nsh ) != 0 )
+		return NULL;
+	
+	if( ns_parserr( &nsh, ns_s_an, 0, &rr ) != 0 )
+		return NULL;
+	
+	size = ns_rr_rdlen( rr );
+	buf = ns_rr_rdata( rr );
+	
+	len = 0;
+	for( i = 6; i < size && buf[i]; i += buf[i] + 1 )
+		len += buf[i] + 1;
+	
+	if( i > size )
+		return NULL;
+	
+	reply = g_malloc( sizeof( struct ns_srv_reply ) + len );
+	memcpy( reply->name, buf + 7, len );
+	
+	for( i = buf[6]; i < len && buf[7+i]; i += buf[7+i] + 1 )
+		reply->name[i] = '.';
+	
+	if( i > len )
+	{
+		g_free( reply );
+		return NULL;
+	}
+	
+	reply->prio = ( buf[0] << 8 ) | buf[1];
+	reply->weight = ( buf[2] << 8 ) | buf[3];
+	reply->port = ( buf[4] << 8 ) | buf[5];
+#endif
+	
+	return reply;
+}
Index: lib/misc.h
===================================================================
--- lib/misc.h	(revision 090f1cbe72373b31e753af4a1442ddd53b02791b)
+++ lib/misc.h	(revision 36e9f62a6e6fdb1217b3b819320ac5a94025c448)
@@ -30,4 +30,12 @@
 #include <time.h>
 
+struct ns_srv_reply
+{
+	int prio;
+	int weight;
+	int port;
+	char name[];
+};
+
 G_MODULE_EXPORT void strip_linefeed( gchar *text );
 G_MODULE_EXPORT char *add_cr( char *text );
@@ -54,3 +62,5 @@
 G_MODULE_EXPORT int bool2int( char *value );
 
+G_MODULE_EXPORT struct ns_srv_reply *srv_lookup( char *service, char *protocol, char *domain );
+
 #endif
Index: protocols/jabber/jabber.c
===================================================================
--- protocols/jabber/jabber.c	(revision 090f1cbe72373b31e753af4a1442ddd53b02791b)
+++ protocols/jabber/jabber.c	(revision 36e9f62a6e6fdb1217b3b819320ac5a94025c448)
@@ -59,4 +59,6 @@
 	struct gaim_connection *gc = new_gaim_conn( acc );
 	struct jabber_data *jd = g_new0( struct jabber_data, 1 );
+	struct ns_srv_reply *srv = NULL;
+	char *connect_to;
 	
 	jd->gc = gc;
@@ -79,13 +81,27 @@
 	jd->node_cache = xt_new_node( "cache", NULL, NULL );
 	
+	/* Figure out the hostname to connect to. */
+	if( acc->server )
+		connect_to = acc->server;
+	else if( ( srv = srv_lookup( "xmpp-client", "tcp", jd->server ) ) ||
+		 ( srv = srv_lookup( "jabber-client", "tcp", jd->server ) ) )
+		connect_to = srv->name;
+	else
+		connect_to = jd->server;
+	
+	/* For non-SSL connections we can try to use the port # from the SRV
+	   reply, but let's not do that when using SSL, SSL usually runs on
+	   non-standard ports... */
 	if( set_getbool( &acc->set, "ssl" ) )
 	{
-		jd->ssl = ssl_connect( acc->server ? acc->server : jd->server, set_getint( &acc->set, "port" ), jabber_connected_ssl, gc );
+		jd->ssl = ssl_connect( connect_to, set_getint( &acc->set, "port" ), jabber_connected_ssl, gc );
 		jd->fd = ssl_getfd( jd->ssl );
 	}
 	else
 	{
-		jd->fd = proxy_connect( acc->server ? acc->server : jd->server, set_getint( &acc->set, "port" ), jabber_connected_plain, gc );
-	}
+		jd->fd = proxy_connect( connect_to, srv ? srv->port : set_getint( &acc->set, "port" ), jabber_connected_plain, gc );
+	}
+	
+	g_free( srv );
 }
 
Index: protocols/jabber/presence.c
===================================================================
--- protocols/jabber/presence.c	(revision 090f1cbe72373b31e753af4a1442ddd53b02791b)
+++ protocols/jabber/presence.c	(revision 36e9f62a6e6fdb1217b3b819320ac5a94025c448)
@@ -38,4 +38,7 @@
 		*s = 0;
 	
+	/* Will implement better parsing of away states/msgs when we
+	   finally do those API changes. Which will probably be after
+	   merging this module into the main tree. */
 	if( type == NULL )
 		serv_got_update( gc, from, 1, 0, 0, 0, 0, 0 );
@@ -84,11 +87,9 @@
 	
 	node = jabber_make_packet( "presence", NULL, NULL, NULL );
+	xt_add_child( node, xt_new_node( "priority", set_getstr( &gc->acc->set, "priority" ), NULL ) );
 	if( show && *show )
 		xt_add_child( node, xt_new_node( "show", show, NULL ) );
 	if( status )
 		xt_add_child( node, xt_new_node( "status", status, NULL ) );
-	/* if( set_getint( &gc->acc->set, "priority" ) != 0 ) */
-	/* Let's just send this every time... */
-		xt_add_child( node, xt_new_node( "priority", set_getstr( &gc->acc->set, "priority" ), NULL ) );
 	
 	st = jabber_write_packet( gc, node );
