From 9aa998757a8736cef02fd92050eacbb2a6fb5180 Mon Sep 17 00:00:00 2001 From: John Denker Date: Thu, 26 Jul 2012 10:57:13 -0700 Subject: patch to support IPv6 in tcpserver --- ucspi-tcp-0.88/rblsmtpd.c | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) (limited to 'ucspi-tcp-0.88/rblsmtpd.c') diff --git a/ucspi-tcp-0.88/rblsmtpd.c b/ucspi-tcp-0.88/rblsmtpd.c index cc8ba2e..200a345 100644 --- a/ucspi-tcp-0.88/rblsmtpd.c +++ b/ucspi-tcp-0.88/rblsmtpd.c @@ -25,26 +25,58 @@ void usage(void) strerr_die1x(100,"rblsmtpd: usage: rblsmtpd [ -b ] [ -R ] [ -t timeout ] [ -r base ] [ -a base ] smtpd [ arg ... ]"); } +char *tcp_proto; char *ip_env; static stralloc ip_reverse; +static inline char tohex(char c) { + return c>=10?c-10+'a':c+'0'; +} + void ip_init(void) { unsigned int i; unsigned int j; + unsigned char remoteip[16]; + char hexval; + tcp_proto = env_get("PROTO"); + if (!tcp_proto) tcp_proto = ""; ip_env = env_get("TCPREMOTEIP"); if (!ip_env) ip_env = ""; if (!stralloc_copys(&ip_reverse,"")) nomem(); i = str_len(ip_env); - while (i) { - for (j = i;j > 0;--j) if (ip_env[j - 1] == '.') break; - if (!stralloc_catb(&ip_reverse,ip_env + j,i - j)) nomem(); - if (!stralloc_cats(&ip_reverse,".")) nomem(); - if (!j) break; - i = j - 1; + if (str_diff(tcp_proto, "TCP6") != 0) + { + // IPv4 + while (i) { + for (j = i;j > 0;--j) if (ip_env[j - 1] == '.') break; + if (!stralloc_catb(&ip_reverse,ip_env + j,i - j)) nomem(); + if (!stralloc_cats(&ip_reverse,".")) nomem(); + if (!j) break; + i = j - 1; + } + } + else + { + // IPv6 + if ((i=scan_ip6(ip_env, remoteip))==0) + return; + + for (j=16; j>0; j--) + { + hexval=tohex(remoteip[j-1] & 15); + if(!stralloc_catb(&ip_reverse, &hexval, 1)) nomem(); + if(!stralloc_cats(&ip_reverse, ".")) nomem(); + + hexval=tohex(remoteip[j-1] >> 4); + if(!stralloc_catb(&ip_reverse, &hexval, 1)) nomem(); + if(!stralloc_cats(&ip_reverse, ".")) nomem(); + } + + if(!stralloc_cats(&ip_reverse, "ipv6.")) nomem(); } } @@ -190,7 +222,7 @@ main(int argc,char **argv,char **envp) argv += optind; if (!*argv) usage(); - if (flagwantdefaultrbl) rbl("rbl.maps.vix.com"); + if (flagwantdefaultrbl) rbl("zen.spamhaus.org"); if (decision >= 2) rblsmtpd(); pathexec_run(*argv,argv,envp); -- cgit v1.2.3