From 2c3182c8233b5b12a42fd3850732ad3978b89de9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 27 Jul 2008 19:08:17 +0200 Subject: free srv data --- libasyncns/asyncns-test.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/libasyncns/asyncns-test.c b/libasyncns/asyncns-test.c index 46e7d5a..0ef1a7f 100644 --- a/libasyncns/asyncns-test.c +++ b/libasyncns/asyncns-test.c @@ -2,17 +2,17 @@ /*** This file is part of libasyncns. - + libasyncns is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + libasyncns is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with libasyncns; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -44,7 +44,7 @@ int main(int argc, char *argv[]) { char host[NI_MAXHOST] = "", serv[NI_MAXSERV] = ""; unsigned char *srv; - if (!(asyncns = asyncns_new(10))) { + if (!(asyncns = asyncns_new(1))) { fprintf(stderr, "asyncns_new() failed\n"); goto fail; } @@ -61,14 +61,14 @@ int main(int argc, char *argv[]) { sa.sin_family = AF_INET; sa.sin_addr.s_addr = inet_addr(argc >= 3 ? argv[2] : "193.99.144.71"); sa.sin_port = htons(80); - - q2 = asyncns_getnameinfo(asyncns, (struct sockaddr*) &sa, sizeof(sa), 0, 1, 1); + + 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); + q3 = asyncns_res_query(asyncns, "_xmpp-client._tcp.gmail.com", C_IN, T_SRV); /* Wait until the three queries are completed */ - while (!asyncns_isdone(asyncns, q1) + while (!asyncns_isdone(asyncns, q1) || !asyncns_isdone(asyncns, q2) || !asyncns_isdone(asyncns, q3)) { if (asyncns_wait(asyncns, 1) < 0) @@ -85,11 +85,11 @@ int main(int argc, char *argv[]) { char t[256]; const char *p = NULL; - if (i->ai_family == PF_INET) + if (i->ai_family == PF_INET) p = inet_ntop(AF_INET, &((struct sockaddr_in*) i->ai_addr)->sin_addr, t, sizeof(t)); else if (i->ai_family == PF_INET6) p = inet_ntop(AF_INET6, &((struct sockaddr_in6*) i->ai_addr)->sin6_addr, t, sizeof(t)); - + printf("%s\n", p); } @@ -105,7 +105,7 @@ int main(int argc, char *argv[]) { /* Interpret the result of the SRV lookup */ if ((ret = asyncns_res_done(asyncns, q3, &srv)) < 0) { fprintf(stderr, "error: %s %i\n", strerror(ret), ret); - } else if (ret == 0) { + } else if (ret == 0) { fprintf(stderr, "No reply for SRV lookup\n"); } else { int qdcount; @@ -135,24 +135,26 @@ int main(int argc, char *argv[]) { 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); + len = dn_expand(srv, end, pos, name, 255); printf("\tpreference: %2d weight: %2d port: %d host: %s\n", pref, weight, port, name); pos += len; } + + asyncns_freeanswer(srv); } - + r = 0; fail: if (asyncns) asyncns_free(asyncns); - + return r; } -- cgit