]> Pileus Git - ~andy/fetchmail/commitdiff
Add new gai.c debug source.
authorMatthias Andree <matthias.andree@gmx.de>
Sun, 3 Feb 2013 14:12:07 +0000 (15:12 +0100)
committerMatthias Andree <matthias.andree@gmx.de>
Sun, 3 Feb 2013 14:12:07 +0000 (15:12 +0100)
contrib/README
contrib/gai.c [new file with mode: 0644]

index 7c6e6e8f859c0d88369c5c8c4c3634aba0fa317c..5eaa51e95b8f7ad38ad2b416e49dc10d3bff1211 100644 (file)
@@ -202,3 +202,8 @@ It probably needs to be adjusted for use on other systems.
 A MySQL/Tcl/Expect-based client-side script to remove messages at a
 certain age.  See delete-later.README for details.
 (By Carsten Ralle, Yoo GmbH, Germany.)
+
+### gai (added 2013-02-03, --ma)
+
+A trivial getaddrinfo() program to check the getaddrinfo() call from the
+system, as a research tool for the fetchmail developers.
diff --git a/contrib/gai.c b/contrib/gai.c
new file mode 100644 (file)
index 0000000..2896138
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * File:   gai.c
+ * Author: Matthias Andree
+ *
+ * Created on 3. Februar 2013, 15:03
+ * A short file to call getaddrinfo with the same arguments as checkalias.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <netdb.h>
+
+/*
+ *
+ */
+int main(int argc, char** argv) {
+    struct addrinfo hints;
+    struct addrinfo *res;
+
+    if (argc != 2 || 0 == strcmp("-h", argv[1])) {
+       fprintf(stderr, "Usage: %s hostname\n", argv[0]);
+       exit(EXIT_FAILURE);
+    }
+
+    memset(&hints, 0, sizeof hints);
+    hints.ai_family=AF_UNSPEC;
+    hints.ai_protocol=PF_UNSPEC;
+    hints.ai_socktype=SOCK_STREAM;
+    hints.ai_flags=AI_CANONNAME;
+
+    int result = getaddrinfo(argv[1], NULL, &hints, &res);
+    if (result) {
+        fprintf(stderr, "getaddrinfo(\"%s\", ...AI_CANONNAME...) failed: %d (%s)\n", argv[1], result, gai_strerror(result));
+        exit(EXIT_FAILURE);
+    }
+
+    freeaddrinfo(res);
+    return (EXIT_SUCCESS);
+}
+