masqmail
diff src/lookup.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 | f671821d8222 |
children | 138e66e1a61f |
line diff
1.1 --- a/src/lookup.c Fri Jul 16 12:39:14 2010 +0200 1.2 +++ b/src/lookup.c Fri Jul 16 12:53:07 2010 +0200 1.3 @@ -22,11 +22,6 @@ 1.4 1.5 #include "masqmail.h" 1.6 1.7 -#ifdef RESOLV_TEST 1.8 -#undef DEBUG 1.9 -#define DEBUG(x) if(x > 0) 1.10 -#define debugf g_print 1.11 -#endif 1.12 1.13 #ifdef ENABLE_RESOLVER 1.14 1.15 @@ -198,35 +193,39 @@ 1.16 } 1.17 */ 1.18 1.19 -static int 1.20 +int 1.21 dns_look_ip(gchar * domain, guint32 * ip) 1.22 { 1.23 gchar *n = domain; 1.24 1.25 while (TRUE) { 1.26 - if (dns_resolve(n, T_A, FALSE) == 0) { 1.27 - dns_next(); 1.28 - if (rr_type == T_A) { 1.29 - if (rr_dlen < 4) 1.30 - return -1; /* soft */ 1.31 - *ip = *(guint32 *) (resp_pos); 1.32 + if (dns_resolve(n, T_A, FALSE) != 0) { 1.33 + return -1; 1.34 + } 1.35 1.36 - DEBUG(5) debugf("DNS: dns_look_ip(): ip = %s\n", inet_ntoa(*(struct in_addr *) ip)); 1.37 + dns_next(); 1.38 + if (rr_type == T_A) { 1.39 + if (rr_dlen < 4) { 1.40 + return -1; /* soft */ 1.41 + } 1.42 + *ip = *(guint32 *) (resp_pos); 1.43 1.44 - resp_pos += rr_dlen; 1.45 - return 0; 1.46 - } else if (rr_type == T_CNAME) { 1.47 - if (dn_expand(response.buf, resp_end, resp_pos, name, MAX_DNSNAME) < 0) 1.48 - return -1; 1.49 + DEBUG(5) debugf("DNS: dns_look_ip(): ip = %s\n", inet_ntoa(*(struct in_addr *) ip)); 1.50 1.51 - DEBUG(5) debugf("DNS: (CNAME) dns_look_ip(): name = %s\n", name); 1.52 + resp_pos += rr_dlen; 1.53 + return 0; 1.54 + } else if (rr_type == T_CNAME) { 1.55 + if (dn_expand(response.buf, resp_end, resp_pos, name, MAX_DNSNAME) < 0) { 1.56 + return -1; 1.57 + } 1.58 1.59 - resp_pos += rr_dlen; 1.60 - n = name; 1.61 - } else 1.62 - return -1; 1.63 - } else 1.64 + DEBUG(5) debugf("DNS: (CNAME) dns_look_ip(): name = %s\n", name); 1.65 + 1.66 + resp_pos += rr_dlen; 1.67 + n = name; 1.68 + } else { 1.69 return -1; 1.70 + } 1.71 } 1.72 } 1.73 1.74 @@ -333,35 +332,3 @@ 1.75 } 1.76 return list; 1.77 } 1.78 - 1.79 -#ifdef RESOLV_TEST 1.80 -int 1.81 -main(int argc, char *argv[]) 1.82 -{ 1.83 - GList *addr_list = NULL, *node; 1.84 - 1.85 - g_print("starting res_init()\n"); 1.86 - g_print("retrans = %d, retry = %d\n", _res.retrans, _res.retry); 1.87 - if (res_init() == 0) { 1.88 - addr_list = resolve_dns_a(NULL, argv[1]); 1.89 - g_print("A:\n"); 1.90 - foreach(addr_list, node) { 1.91 - mxip_addr *p_mxip = (mxip_addr *) (node->data); 1.92 - printf("name = %s\n IP = %s\n", p_mxip->name, inet_ntoa(*(struct in_addr *) &(p_mxip->ip))); 1.93 - } 1.94 - addr_list = resolve_dns_mx(NULL, argv[1]); 1.95 - g_print("MX:\n"); 1.96 - foreach(addr_list, node) { 1.97 - mxip_addr *p_mxip = (mxip_addr *) (node->data); 1.98 - printf("name = %s\n IP = %s pref = %d\n", p_mxip->name, 1.99 - inet_ntoa(*(struct in_addr *) &(p_mxip->ip)), p_mxip->pref); 1.100 - } 1.101 - { 1.102 - guint32 ip; 1.103 - dns_look_ip(argv[1], &ip); 1.104 - printf("dns_look_ip: %s\n", inet_ntoa(*((struct in_addr *) (&ip)))); 1.105 - } 1.106 - } else 1.107 - printf("res_init() failed.\n"); 1.108 -} 1.109 -#endif