Mercurial > masqmail
annotate src/resolvtest.c @ 216:84bf7a6b6ccd
added misc/list-versions
This script helps to check if the versions numbers in the project
are the same as the one for the release. This script is motivated
by the 0.2.27 release in which masqmail introduces itself as being
version 0.2.26.
author | meillo@marmaro.de |
---|---|
date | Mon, 19 Jul 2010 14:01:13 +0200 |
parents | 116b0269c934 |
children | b27f66555ba8 |
rev | line source |
---|---|
200
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
1 /* MasqMail Copyright (C) Oliver Kurth, |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
2 /* Copyright (C) 2010 markus schnalke <meillo@marmaro.de> |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
3 * |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
7 * (at your option) any later version. |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
8 * |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
9 * This program is distributed in the hope that it will be useful, |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
12 * GNU General Public License for more details. |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
13 * |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
14 * You should have received a copy of the GNU General Public License |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
15 * along with this program; if not, write to the Free Software |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
17 */ |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
18 |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
19 |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
20 #include <sys/types.h> |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
21 #include <netinet/in.h> |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
22 #include <arpa/nameser.h> |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
23 #include <resolv.h> |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
24 |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
25 #include "masqmail.h" |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
26 |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
27 |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
28 masqmail_conf conf; |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
29 |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
30 |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
31 void |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
32 debugf(const char *fmt, ...) |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
33 { |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
34 va_list args; |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
35 va_start(args, fmt); |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
36 |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
37 vfprintf(stdout, fmt, args); |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
38 |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
39 va_end(args); |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
40 |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
41 } |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
42 |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
43 |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
44 int |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
45 main(int argc, char *argv[]) |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
46 { |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
47 GList *addr_list = NULL, *node; |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
48 |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
49 conf.debug_level = -1; /* no debug messages */ |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
50 |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
51 if (argc != 2) { |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
52 fprintf(stderr, "usage: resolvtest HOSTNAME\n"); |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
53 return 1; |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
54 } |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
55 |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
56 if (res_init() != 0) { |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
57 printf("res_init() failed.\n"); |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
58 return 1; |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
59 } |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
60 |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
61 printf("A:\n"); |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
62 addr_list = resolve_dns_a(NULL, argv[1]); |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
63 foreach(addr_list, node) { |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
64 mxip_addr *p_mxip = (mxip_addr *) (node->data); |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
65 printf("%s \t%s\n", p_mxip->name, inet_ntoa(*(struct in_addr *) &(p_mxip->ip))); |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
66 } |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
67 |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
68 printf("\nMX:\n"); |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
69 addr_list = resolve_dns_mx(NULL, argv[1]); |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
70 foreach(addr_list, node) { |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
71 mxip_addr *p_mxip = (mxip_addr *) (node->data); |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
72 printf("%s \t%s %d\n", p_mxip->name, |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
73 inet_ntoa(*(struct in_addr *) &(p_mxip->ip)), p_mxip->pref); |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
74 } |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
75 |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
76 printf("\nIP resolved directly (assumed FQDN, no default domain added):\n"); |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
77 { |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
78 guint32 ip; |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
79 if (dns_look_ip(argv[1], &ip) >= 0) { |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
80 printf("%s\n", inet_ntoa(*((struct in_addr *) (&ip)))); |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
81 } |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
82 } |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
83 |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
84 return 0; |
116b0269c934
reworked resolvtest; let it build; refactored in lookup.c
meillo@marmaro.de
parents:
diff
changeset
|
85 } |