From 83ce0551954e207c7dba125594b25d59ae29e3c1 Mon Sep 17 00:00:00 2001 From: John Denker Date: Sat, 21 Jul 2012 10:45:40 -0700 Subject: doesn't work, don't know why --- tools/greylist.c | 81 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 61 insertions(+), 20 deletions(-) (limited to 'tools/greylist.c') diff --git a/tools/greylist.c b/tools/greylist.c index b64636e..f9a4ebc 100644 --- a/tools/greylist.c +++ b/tools/greylist.c @@ -371,6 +371,45 @@ int whatsit::doit(const int penalty){ return 0; } +typedef vector VU; + +class VUx : public VU { +public: + sa_family_t fam; +}; + +VUx parse_sockaddr(const sockaddr* ai_addr) { + void* numericAddress; + VUx rslt; + int addrsize; + rslt.fam = ((sockaddr *)ai_addr)->sa_family; + switch (rslt.fam) { + case AF_INET: + numericAddress = &(((sockaddr_in *)ai_addr)->sin_addr.s_addr); + addrsize = sizeof(in_addr); + break; + case AF_INET6: + numericAddress = &(((sockaddr_in6 *)ai_addr)->sin6_addr.s6_addr); + addrsize = sizeof(in6_addr); + break; + default: + cerr << "?Unknown address family " << rslt.fam << endl; + return rslt; + } + unsigned char* foo = (unsigned char*) numericAddress; + (VU)rslt = VU(foo, foo+addrsize); + cerr << "asdf " << rslt.size() << " ... " << VU(foo, foo+addrsize).size() << endl; + return rslt; +} + +int diff(const VU aaa, const VU bbb){ + if(aaa.size() != bbb.size()) return 1; + for (unsigned int ii=0; ii < aaa.size(); ii++){ + if (aaa[ii] != bbb[ii]) return 1; + } + return 0; +} + int whatsit::check_dns(){ char* hostvar = getenv("TCPREMOTEHOST"); if (!hostvar) { @@ -392,39 +431,41 @@ int whatsit::check_dns(){ // restrict to TCP only; otherwise we get N records per address hints.ai_protocol = IPPROTO_TCP; #endif - error = getaddrinfo(hostvar, NULL, &hints, &result); + + error = getaddrinfo(ipvar, NULL, &hints, &ipresult); if (error) { - cerr << "error in getaddrinfo for " << hostvar + cerr << "error in getaddrinfo for " << ipvar << " : " << gai_strerror(error) << endl; return ex_syserr; } + if (!ipresult) { + cerr << "should never happen (addr with no addrs?)" << endl; + return ex_syserr; + } - error = getaddrinfo(ipvar, NULL, &hints, &ipresult); + VU ipAddr = parse_sockaddr(ipresult->ai_addr); + error = getaddrinfo(hostvar, NULL, &hints, &result); if (error) { - cerr << "error in getaddrinfo for " << ipvar + cerr << "error in getaddrinfo for " << hostvar << " : " << gai_strerror(error) << endl; return ex_syserr; } // loop over all returned results and check for a match. + vector checked_hosts; for (res = result; res != NULL; res = res->ai_next){ - void *numericAddress; - - sa_family_t fam = ((sockaddr *)res->ai_addr)->sa_family; - int addrsize; - switch (fam) { - case AF_INET: - numericAddress = &(((sockaddr_in *)res->ai_addr)->sin_addr.s_addr); - addrsize = sizeof(in_addr); - break; - case AF_INET6: - numericAddress = &(((sockaddr_in6 *)res->ai_addr)->sin6_addr.s6_addr); - addrsize = sizeof(in6_addr); - break; - default: - cerr << "?Unknown address family " << fam << endl; - return(ex_syserr); + VU hostAddr = parse_sockaddr(res->ai_addr); +#if 0 + char msgbuf[INET6_ADDRSTRLEN]; + const char* rslt = inet_ntop(fam, numericAddress, + msgbuf, sizeof(msgbuf)); +#endif + if (!diff(hostAddr, ipAddr)) { + cerr << "match! " << ipAddr.size() << endl; + goto done; } } + cerr << "no match" << endl; +done: return 0; } -- cgit v1.2.3