masqmail

diff src/resolvtest.c @ 200:116b0269c934

reworked resolvtest; let it build; refactored in lookup.c the resolvtest helper and code test tool was available in the code but did not get built I moved it to resolvtest.c and included it into the build process the define RESOLV_TEST was removed
author meillo@marmaro.de
date Fri, 16 Jul 2010 12:53:07 +0200
parents
children b27f66555ba8
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/resolvtest.c	Fri Jul 16 12:53:07 2010 +0200
     1.3 @@ -0,0 +1,85 @@
     1.4 +/* MasqMail Copyright (C) Oliver Kurth,
     1.5 +/* Copyright (C) 2010 markus schnalke <meillo@marmaro.de>
     1.6 + *
     1.7 + * This program is free software; you can redistribute it and/or modify
     1.8 + * it under the terms of the GNU General Public License as published by
     1.9 + * the Free Software Foundation; either version 2 of the License, or
    1.10 + * (at your option) any later version.
    1.11 + *
    1.12 + * This program is distributed in the hope that it will be useful,
    1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 + * GNU General Public License for more details.
    1.16 + *
    1.17 + * You should have received a copy of the GNU General Public License
    1.18 + * along with this program; if not, write to the Free Software
    1.19 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    1.20 + */
    1.21 +
    1.22 +
    1.23 +#include <sys/types.h>
    1.24 +#include <netinet/in.h>
    1.25 +#include <arpa/nameser.h>
    1.26 +#include <resolv.h>
    1.27 +
    1.28 +#include "masqmail.h"
    1.29 +
    1.30 +
    1.31 +masqmail_conf conf;
    1.32 +
    1.33 +
    1.34 +void
    1.35 +debugf(const char *fmt, ...)
    1.36 +{
    1.37 +	va_list args;
    1.38 +	va_start(args, fmt);
    1.39 +
    1.40 +	vfprintf(stdout, fmt, args);
    1.41 +
    1.42 +	va_end(args);
    1.43 +
    1.44 +}
    1.45 +
    1.46 +
    1.47 +int
    1.48 +main(int argc, char *argv[])
    1.49 +{
    1.50 +	GList *addr_list = NULL, *node;
    1.51 +
    1.52 +	conf.debug_level = -1;  /* no debug messages */
    1.53 +
    1.54 +	if (argc != 2) {
    1.55 +		fprintf(stderr, "usage: resolvtest HOSTNAME\n");
    1.56 +		return 1;
    1.57 +	}
    1.58 +
    1.59 +	if (res_init() != 0) {
    1.60 +		printf("res_init() failed.\n");
    1.61 +		return 1;
    1.62 +	}
    1.63 +
    1.64 +	printf("A:\n");
    1.65 +	addr_list = resolve_dns_a(NULL, argv[1]);
    1.66 +	foreach(addr_list, node) {
    1.67 +		mxip_addr *p_mxip = (mxip_addr *) (node->data);
    1.68 +		printf("%s  \t%s\n", p_mxip->name, inet_ntoa(*(struct in_addr *) &(p_mxip->ip)));
    1.69 +	}
    1.70 +
    1.71 +	printf("\nMX:\n");
    1.72 +	addr_list = resolve_dns_mx(NULL, argv[1]);
    1.73 +	foreach(addr_list, node) {
    1.74 +		mxip_addr *p_mxip = (mxip_addr *) (node->data);
    1.75 +		printf("%s  \t%s  %d\n", p_mxip->name,
    1.76 +		       inet_ntoa(*(struct in_addr *) &(p_mxip->ip)), p_mxip->pref);
    1.77 +	}
    1.78 +
    1.79 +	printf("\nIP resolved directly (assumed FQDN, no default domain added):\n");
    1.80 +	{
    1.81 +		guint32 ip;
    1.82 +		if (dns_look_ip(argv[1], &ip) >= 0) {
    1.83 +			printf("%s\n", inet_ntoa(*((struct in_addr *) (&ip))));
    1.84 +		}
    1.85 +	}
    1.86 +
    1.87 +	return 0;
    1.88 +}