summaryrefslogtreecommitdiffstats
path: root/libasyncns
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2008-07-27 23:09:59 +0200
committerLennart Poettering <lennart@poettering.net>2008-07-27 23:09:59 +0200
commit77df58c1028a7dcde5d0c50257cd62ad0e4886db (patch)
treea19f213f62ad933bd084779346e4705e56aa600c /libasyncns
parent709981e01f7d3c1885f7cce08f60ebe016dd7098 (diff)
add complete error checking to example
Diffstat (limited to 'libasyncns')
-rw-r--r--libasyncns/asyncns-test.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/libasyncns/asyncns-test.c b/libasyncns/asyncns-test.c
index b8604e6..053b5bd 100644
--- a/libasyncns/asyncns-test.c
+++ b/libasyncns/asyncns-test.c
@@ -59,6 +59,9 @@ int main(int argc, char *argv[]) {
q1 = asyncns_getaddrinfo(asyncns, argc >= 2 ? argv[1] : "www.heise.de", NULL, &hints);
+ if (!q1)
+ fprintf(stderr, "asyncns_getaddrinfo(): %s\n", strerror(errno));
+
/* Make an address -> name query */
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
@@ -67,15 +70,23 @@ int main(int argc, char *argv[]) {
q2 = asyncns_getnameinfo(asyncns, (struct sockaddr*) &sa, sizeof(sa), 0, 1, 1);
+ if (!q2)
+ fprintf(stderr, "asyncns_getnameinfo(): %s\n", strerror(errno));
+
/* Make a res_query() call */
q3 = asyncns_res_query(asyncns, "_xmpp-client._tcp.gmail.com", C_IN, T_SRV);
+ if (!q3)
+ fprintf(stderr, "asyncns_res_query(): %s\n", strerror(errno));
+
/* Wait until the three queries are completed */
while (!asyncns_isdone(asyncns, q1)
|| !asyncns_isdone(asyncns, q2)
|| !asyncns_isdone(asyncns, q3)) {
- if (asyncns_wait(asyncns, 1) < 0)
+ if (asyncns_wait(asyncns, 1) < 0) {
+ fprintf(stderr, "asyncns_wait(): %s\n", strerror(errno));
goto fail;
+ }
}
/* Interpret the result of the name -> addr query */
@@ -107,7 +118,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);
+ fprintf(stderr, "error: %s %i\n", strerror(errno), ret);
} else if (ret == 0) {
fprintf(stderr, "No reply for SRV lookup\n");
} else {