Package: ssmtp Version: 2.61 Whereas the IPv6 code seems to already step through all host addresses returned by getaddrinfo(), the IPv4 code unfortunately connects only to the *first* address returned by gethostbyname(). But the name lookup could return multiple IP addresses, corresponding to multiple mail hubs, and ssmtp ought to support that kind of failover. The following patch adds this functionality to ssmtp (you might also want to update the manpage and README to reflect that ssmtp will now do failover):
diff -Bb -U 2 ssmtp.c~ ssmtp.c --- ssmtp.c~ +++ ssmtp.c @@ -999,5 +999,5 @@ struct sockaddr_in name; struct hostent *hent; - int s, namelen; + int i, s, namelen; #endif @@ -1088,13 +1088,19 @@ } + for (i = 0; ; ++i) { + if (!hent->h_addr_list[i]) { + log_event(LOG_ERR, "Unable to connect to %s:%d", host, port); + return(-1); + } + /* This SHOULD already be in Network Byte Order from gethostbyname() */ - name.sin_addr.s_addr = ((struct in_addr *)(hent->h_addr))->s_addr; + name.sin_addr.s_addr = ((struct in_addr *)(hent->h_addr_list[i]))->s_addr; name.sin_family = hent->h_addrtype; name.sin_port = htons(port); namelen = sizeof(struct sockaddr_in); - if(connect(s, (struct sockaddr *)&name, namelen) < 0) { - log_event(LOG_ERR, "Unable to connect to %s:%d", host, port); - return(-1); + if(connect(s, (struct sockaddr *)&name, namelen) < 0) + continue; + break; } #endif In other words, add new variable "i" at top of code for smtp_open() in ssmtp.c, and then use the following loop to try to open the connection: for (i = 0; ; ++i) { if (!hent->h_addr_list[i]) { log_event(LOG_ERR, "Unable to connect to %s:%d", host, port); return(-1); } /* This SHOULD already be in Network Byte Order from gethostbyname() / name.sin_addr.s_addr = ((struct in_addr *)(hent->h_addr_list[i]))->s_addr; name.sin_family = hent->h_addrtype; name.sin_port = htons(port); namelen = sizeof(struct sockaddr_in); if(connect(s, (struct sockaddr *)&name, namelen) < 0) continue; break; } Thanks! Alexander Perlis, Department of Mathematics, The University of Arizona -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]