]> Pileus Git - ~andy/fetchmail/blob - contrib/gai.c
Add new gai.c debug source.
[~andy/fetchmail] / contrib / gai.c
1 /*
2  * File:   gai.c
3  * Author: Matthias Andree
4  *
5  * Created on 3. Februar 2013, 15:03
6  * A short file to call getaddrinfo with the same arguments as checkalias.
7  */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 #include <netdb.h>
14
15 /*
16  *
17  */
18 int main(int argc, char** argv) {
19     struct addrinfo hints;
20     struct addrinfo *res;
21
22     if (argc != 2 || 0 == strcmp("-h", argv[1])) {
23         fprintf(stderr, "Usage: %s hostname\n", argv[0]);
24         exit(EXIT_FAILURE);
25     }
26
27     memset(&hints, 0, sizeof hints);
28     hints.ai_family=AF_UNSPEC;
29     hints.ai_protocol=PF_UNSPEC;
30     hints.ai_socktype=SOCK_STREAM;
31     hints.ai_flags=AI_CANONNAME;
32
33     int result = getaddrinfo(argv[1], NULL, &hints, &res);
34     if (result) {
35         fprintf(stderr, "getaddrinfo(\"%s\", ...AI_CANONNAME...) failed: %d (%s)\n", argv[1], result, gai_strerror(result));
36         exit(EXIT_FAILURE);
37     }
38
39     freeaddrinfo(res);
40     return (EXIT_SUCCESS);
41 }
42