From: Andy Repton <pm-outgoingip@boomerangdomains.com>
To: Russell Nelson <nelson@crynwr.com>
Subject: Re: Changing the IP address used by qmail....
Date: Thu, 18 May 2000 14:56:47 +0100


--aT9PWwzfKXlsBJM1
Content-Type: text/plain; charset=us-ascii

On Thu, May 18, 2000 at 08:54:53AM -0400, Russell Nelson wrote:
> Andy Repton writes:
>  > I have ported the patch to qmail 1.01 from the qmail.org web page to
>  > qmail 1.03 and incorporated it into an RPM for my system (the RPM is
>  > basically the memphis rpm with the patch applied). If you want a copy
>  > then email me and I'll either send you the patch or the RPM - your
>  > choice. It allows you to do just what you requested.
> 
> Can I get the patch, to publish on www.qmail.org?  Or else a URL to it?
> 
Sure, it is attached. I have done no more testing than applying it and
running it on my system. This mail should be from mail.boomerangdomains
- if it is then the patch works :-)

regards
Andy
-- 
BoomerangDomains support - support@boomerangdomains.com 
domain registration, email and web forwarding for just $25 a year

--aT9PWwzfKXlsBJM1
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="outgoingip.patch"

diff -u qmail-1.03-orig/qmail-remote.c qmail-1.03/qmail-remote.c
--- qmail-1.03-orig/qmail-remote.c	Mon Jun 15 06:53:16 1998
+++ qmail-1.03/qmail-remote.c	Tue Apr 25 10:31:48 2000
@@ -39,6 +39,7 @@
 static stralloc sauninit = {0};
 
 stralloc helohost = {0};
+stralloc outgoingip = {0};
 stralloc routes = {0};
 struct constmap maproutes;
 stralloc host = {0};
@@ -47,6 +48,7 @@
 saa reciplist = {0};
 
 struct ip_address partner;
+struct ip_address outip;
 
 void out(s) char *s; { if (substdio_puts(subfdoutsmall,s) == -1) _exit(0); }
 void zero() { if (substdio_put(subfdoutsmall,"\0",1) == -1) _exit(0); }
@@ -56,6 +58,7 @@
 ch = sa->s[i]; if (ch < 33) ch = '?'; if (ch > 126) ch = '?';
 if (substdio_put(subfdoutsmall,&ch,1) == -1) _exit(0); } }
 
+void temp_noip() { out("Zinvalid ipaddr in control/outgoingip (#4.3.0)\n"); zerodie(); }
 void temp_nomem() { out("ZOut of memory. (#4.3.0)\n"); zerodie(); }
 void temp_oserr() { out("Z\
 System resources temporarily unavailable. (#4.3.0)\n"); zerodie(); }
@@ -310,6 +313,7 @@
 
 void getcontrols()
 {
+  int r;
   if (control_init() == -1) temp_control();
   if (control_readint(&timeout,"control/timeoutremote") == -1) temp_control();
   if (control_readint(&timeoutconnect,"control/timeoutconnect") == -1)
@@ -324,6 +328,12 @@
     case 1:
       if (!constmap_init(&maproutes,routes.s,routes.len,1)) temp_nomem(); break;
   }
+ r = control_readline(&outgoingip,"control/outgoingip");
+ if (-1 == r) { if (errno == error_nomem) temp_nomem(); temp_control(); }
+ if (0 == r && !stralloc_copy(&outgoingip, "0.0.0.0")) temp_nomem();
+ if (0 == strcmp(outgoingip.s, "0.0.0.0"))
+   { outip.d[0]=outip.d[1]=outip.d[2]=outip.d[3]=(unsigned long) 0; }
+ else if (!ip_scan(outgoingip.s, &outip)) temp_noip();
 }
 
 void main(argc,argv)
@@ -414,7 +424,7 @@
     smtpfd = socket(AF_INET,SOCK_STREAM,0);
     if (smtpfd == -1) temp_oserr();
  
-    if (timeoutconn(smtpfd,&ip.ix[i].ip,(unsigned int) port,timeoutconnect) == 0) {
+    if (timeoutconn(smtpfd,&ip.ix[i].ip,&outip,(unsigned int) port,timeoutconnect) == 0) {
       tcpto_err(&ip.ix[i].ip,0);
       partner = ip.ix[i].ip;
       smtp(); /* does not return */
diff -u qmail-1.03-orig/remoteinfo.c qmail-1.03/remoteinfo.c
--- qmail-1.03-orig/remoteinfo.c	Mon Jun 15 06:53:16 1998
+++ qmail-1.03/remoteinfo.c	Tue Apr 25 10:24:15 2000
@@ -44,12 +44,12 @@
   s = socket(AF_INET,SOCK_STREAM,0);
   if (s == -1) return 0;
  
-  byte_zero(&sin,sizeof(sin));
+/*  byte_zero(&sin,sizeof(sin));
   sin.sin_family = AF_INET;
   byte_copy(&sin.sin_addr,4,ipl);
   sin.sin_port = 0;
-  if (bind(s,(struct sockaddr *) &sin,sizeof(sin)) == -1) { close(s); return 0; }
-  if (timeoutconn(s,ipr,113,timeout) == -1) { close(s); return 0; }
+  if (bind(s,(struct sockaddr *) &sin,sizeof(sin)) == -1) { close(s); return 0; } */
+  if (timeoutconn(s,ipr,ipl,113,timeout) == -1) { close(s); return 0; }
   fcntl(s,F_SETFL,fcntl(s,F_GETFL,0) & ~O_NDELAY);
  
   len = 0;
diff -u qmail-1.03-orig/timeoutconn.c qmail-1.03/timeoutconn.c
--- qmail-1.03-orig/timeoutconn.c	Mon Jun 15 06:53:16 1998
+++ qmail-1.03/timeoutconn.c	Tue Apr 25 10:28:50 2000
@@ -10,9 +10,10 @@
 #include "byte.h"
 #include "timeoutconn.h"
 
-int timeoutconn(s,ip,port,timeout)
+int timeoutconn(s,ip,outip,port,timeout)
 int s;
 struct ip_address *ip;
+struct ip_address *outip;
 unsigned int port;
 int timeout;
 {
@@ -22,6 +23,13 @@
   fd_set wfds;
   struct timeval tv;
  
+  /* bind() an outgoing ipaddr */
+  byte_zero(&sin,sizeof(sin));
+  byte_copy(&sin.sin_addr.s_addr,4,outip);
+  sin.sin_family = AF_INET;
+
+  if (-1 == bind(s,(struct sockaddr *) &sin,sizeof(sin))) return -1;
+
   byte_zero(&sin,sizeof(sin));
   byte_copy(&sin.sin_addr,4,ip);
   x = (char *) &sin.sin_port;

--aT9PWwzfKXlsBJM1--

