diff -c -r qmail-1.01/qmail-remote.c qmail/qmail-remote.c
*** qmail-1.01/qmail-remote.c	Fri Oct  3 03:32:24 1997
--- qmail/qmail-remote.c	Tue Aug  5 03:56:59 1997
***************
*** 39,44 ****
--- 39,45 ----
  static stralloc sauninit = {0};
  
  stralloc helohost = {0};
+ stralloc outgoingip = {0};
  stralloc routes = {0};
  struct constmap maproutes;
  stralloc host = {0};
***************
*** 47,52 ****
--- 48,54 ----
  saa reciplist = {0};
  
  struct ip_address partner;
+ struct ip_address outip;
  
  void out(s) char *s; { if (substdio_puts(subfdout,s) == -1) _exit(0); }
  void zero() { if (substdio_put(subfdout,"\0",1) == -1) _exit(0); }
***************
*** 57,62 ****
--- 59,65 ----
  ch = sa->s[i]; if (ch < 33) ch = '?'; if (ch > 126) ch = '?';
  if (substdio_put(subfdout,&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(); }
***************
*** 114,119 ****
--- 117,129 ----
     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_copys(&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();
  }
  
  char smtptobuf[1024];
***************
*** 392,397 ****
--- 402,408 ----
  
   if (!stralloc_copys(&host,argv[1])) temp_nomem();
  
+ 
   relayhost = 0;
   for (i = 0;i <= host.len;++i)
     if ((i == 0) || (i == host.len) || (host.s[i] == '.'))
***************
*** 411,417 ****
    }
  
  
- 
   addrmangle(&sender,argv[2],&flagalias,!relayhost);
  
   if (!saa_readyplus(&reciplist,0)) temp_nomem();
--- 422,427 ----
***************
*** 467,473 ****
     s = socket(AF_INET,SOCK_STREAM,0);
     if (s == -1) temp_oserr();
  
!    if (timeoutconn(s,&ip.ix[i].ip,(unsigned int) port,timeoutconnect) == 0)
      {
       tcpto_err(&ip.ix[i].ip,0);
       partner = ip.ix[i].ip;
--- 477,483 ----
     s = socket(AF_INET,SOCK_STREAM,0);
     if (s == -1) temp_oserr();
  
!    if (timeoutconn(s,&ip.ix[i].ip,&outip,(unsigned int) port,timeoutconnect) == 0)
      {
       tcpto_err(&ip.ix[i].ip,0);
       partner = ip.ix[i].ip;
diff -c -r qmail-1.01/remoteinfo.c qmail/remoteinfo.c
*** qmail-1.01/remoteinfo.c	Fri Oct  3 03:32:26 1997
--- qmail/remoteinfo.c	Tue Aug  5 03:54:30 1997
***************
*** 32,43 ****
    s = socket(AF_INET,SOCK_STREAM,0);
    if (s == -1) return 0;
   
!   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; }
    fcntl(s,F_SETFL,fcntl(s,F_GETFL,0) & ~O_NDELAY);
   
    len = 0;
--- 32,38 ----
    s = socket(AF_INET,SOCK_STREAM,0);
    if (s == -1) 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 -c -r qmail-1.01/timeoutconn.c qmail/timeoutconn.c
*** qmail-1.01/timeoutconn.c	Fri Oct  3 03:32:31 1997
--- qmail/timeoutconn.c	Tue Aug  5 03:15:36 1997
***************
*** 10,18 ****
  #include "byte.h"
  #include "timeoutconn.h"
  
! int timeoutconn(s,ip,port,timeout)
  int s;
  struct ip_address *ip;
  unsigned int port;
  int timeout;
  {
--- 10,19 ----
  #include "byte.h"
  #include "timeoutconn.h"
  
! int timeoutconn(s,ip,outip,port,timeout)
  int s;
  struct ip_address *ip;
+ struct ip_address *outip;
  unsigned int port;
  int timeout;
  {
***************
*** 22,27 ****
--- 23,35 ----
    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;
***************
*** 29,36 ****
    sin.sin_family = AF_INET;
   
    if (ndelay_on(s) == -1) return -1;
-  
-   /* XXX: could bind s */
   
    if (connect(s,(struct sockaddr *) &sin,sizeof(sin)) == 0) {
      ndelay_off(s);
--- 37,42 ----
