From 5d93f3bb4cd305969a97167de32132f2c7eee3e9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 16 Feb 2007 13:51:03 +0000 Subject: minor code cleanusp: * reindent * add missing config.h inclusion to asyncns-test.c * add few missing consts in casting git-svn-id: file:///home/lennart/svn/public/libasyncns/trunk@27 cc0fb855-19ed-0310-866e-8c1d96e4abae --- libasyncns/asyncns-test.c | 82 +++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 39 deletions(-) (limited to 'libasyncns/asyncns-test.c') diff --git a/libasyncns/asyncns-test.c b/libasyncns/asyncns-test.c index a59ee30..46e7d5a 100644 --- a/libasyncns/asyncns-test.c +++ b/libasyncns/asyncns-test.c @@ -19,6 +19,10 @@ USA. ***/ +#if HAVE_CONFIG_H +#include +#endif + #include #include #include @@ -60,9 +64,10 @@ int main(int argc, char *argv[]) { q2 = asyncns_getnameinfo(asyncns, (struct sockaddr*) &sa, sizeof(sa), 0, 1, 1); + /* Make a res_query() call */ q3 = asyncns_res_query(asyncns, "_xmpp-client._tcp.gmail.com", C_IN, T_SRV); - /* Wait until the two queries are completed */ + /* Wait until the three queries are completed */ while (!asyncns_isdone(asyncns, q1) || !asyncns_isdone(asyncns, q2) || !asyncns_isdone(asyncns, q3)) { @@ -101,46 +106,45 @@ int main(int argc, char *argv[]) { if ((ret = asyncns_res_done(asyncns, q3, &srv)) < 0) { fprintf(stderr, "error: %s %i\n", strerror(ret), ret); } else if (ret == 0) { - fprintf(stderr, "No reply for SRV lookup\n"); + fprintf(stderr, "No reply for SRV lookup\n"); } else { - int qdcount; - int ancount; - int len; - const unsigned char *pos = srv + sizeof(HEADER); - unsigned char *end = srv + ret; - HEADER *head = (HEADER *)srv; - - qdcount = ntohs(head->qdcount); - ancount = ntohs(head->ancount); - - char name[256]; - - printf("%d answers for srv lookup:\n", ancount); - - /* Ignore the questions */ - while (qdcount-- > 0 && (len = dn_expand(srv, end, pos, name, 255)) >= 0) { - assert(len >= 0); - pos += len + QFIXEDSZ; - } - - /* Parse the answers */ - while (ancount-- > 0 && (len = dn_expand(srv, end, pos, name, 255)) >= 0) { - /* Ignore the initial string */ - uint16_t pref, weight, port; - assert(len >= 0); - pos += len; - /* Ignore type, ttl, class and dlen */ - pos += 10; + int qdcount; + int ancount; + int len; + const unsigned char *pos = srv + sizeof(HEADER); + unsigned char *end = srv + ret; + HEADER *head = (HEADER *)srv; + char name[256]; + + qdcount = ntohs(head->qdcount); + ancount = ntohs(head->ancount); + + printf("%d answers for srv lookup:\n", ancount); + + /* Ignore the questions */ + while (qdcount-- > 0 && (len = dn_expand(srv, end, pos, name, 255)) >= 0) { + assert(len >= 0); + pos += len + QFIXEDSZ; + } + + /* Parse the answers */ + while (ancount-- > 0 && (len = dn_expand(srv, end, pos, name, 255)) >= 0) { + /* Ignore the initial string */ + uint16_t pref, weight, port; + assert(len >= 0); + pos += len; + /* Ignore type, ttl, class and dlen */ + pos += 10; - GETSHORT(pref, pos); - GETSHORT(weight, pos); - GETSHORT(port, pos); - len = dn_expand(srv, end, pos, name, 255); - printf("\tpreference: %2d weight: %2d port: %d host: %s\n", - pref, weight, port, name); - - pos += len; - } + GETSHORT(pref, pos); + GETSHORT(weight, pos); + GETSHORT(port, pos); + len = dn_expand(srv, end, pos, name, 255); + printf("\tpreference: %2d weight: %2d port: %d host: %s\n", + pref, weight, port, name); + + pos += len; + } } r = 0; -- cgit