summaryrefslogtreecommitdiff
path: root/ucspi-tcp-0.88/rblsmtpd.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-26 10:57:13 -0700
committerJohn Denker <jsd@av8n.com>2012-07-29 15:32:37 -0700
commit9aa998757a8736cef02fd92050eacbb2a6fb5180 (patch)
tree18ae3d172893279aecaf12df94cb468bf887aa72 /ucspi-tcp-0.88/rblsmtpd.c
parent6e8083ff4ffe3fd2b6d337386637a2b5c1378cf7 (diff)
patch to support IPv6 in tcpserver
Diffstat (limited to 'ucspi-tcp-0.88/rblsmtpd.c')
-rw-r--r--ucspi-tcp-0.88/rblsmtpd.c46
1 files changed, 39 insertions, 7 deletions
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);