Add linux/unix version of SRV lookup.

Add some extra debugging when SRV lookup fails.
This commit is contained in:
James Canete
2008-07-03 04:32:28 +00:00
parent a1a9328698
commit 561fac842c
3 changed files with 48 additions and 1 deletions

View File

@@ -102,6 +102,8 @@ exenv.Append(LIBS=["strophe", "expat"])
exenv.Append(LIBPATH=["."])
if exenv["PLATFORM"] == "win32":
exenv.Append(LIBS=["ws2_32", "winmm"])
if exenv["PLATFORM"] != "win32":
exenv.Append(LIBS=["resolv"])
for e in path("examples", Examples):
example = exenv.Program(e)
Default(example)

View File

@@ -361,8 +361,10 @@ int xmpp_connect_client(xmpp_conn_t * const conn,
if (!sock_srv_lookup("xmpp-client", "tcp", conn->domain, connectdomain, 2048, &connectport))
{
xmpp_debug(conn->ctx, "xmpp", "SRV lookup failed.");
if (altdomain)
{
xmpp_debug(conn->ctx, "xmpp", "Using alternate domain %s, port %d", altdomain, altport);
strcpy(connectdomain, altdomain);
connectport = altport;
}

View File

@@ -34,6 +34,8 @@
#include <netinet/in.h>
#include <netdb.h>
#include <fcntl.h>
#include <arpa/nameser.h>
#include <resolv.h>
#endif
#include "sock.h"
@@ -858,7 +860,48 @@ int sock_srv_lookup(const char *service, const char *proto, const char *domain,
}
#else
#else
if (!set)
{
char buf[65535];
int len;
if ((len = res_query(fulldomain, C_IN, T_SRV, buf, 65535)) > 0)
{
int offset;
int i;
struct dnsquery_header header;
struct dnsquery_question question;
struct dnsquery_resourcerecord rr;
offset = 0;
netbuf_get_dnsquery_header(buf, 65536, &offset, &header);
for (i = 0; i < header.qdcount; i++)
{
netbuf_get_dnsquery_question(buf, 65536, &offset, &question);
}
for (i = 0; i < header.ancount; i++)
{
netbuf_get_dnsquery_resourcerecord(buf, 65536, &offset, &rr);
if (rr.type == 33)
{
struct dnsquery_srvrdata *srvrdata = &(rr.rdata);
snprintf(resulttarget, resulttargetlength, srvrdata->target);
*resultport = srvrdata->port;
set = 1;
}
}
for (i = 0; i < header.ancount; i++)
{
netbuf_get_dnsquery_resourcerecord(buf, 65536, &offset, &rr);
}
}
}
#endif
if (!set)