X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fsrc%2Fsmtp_out.c;h=d4aed373538cab8ed073546e57eaf5a81e8c1fee;hb=ec95d1a6a6c015844e412572b6e5a185b072e01e;hp=2c63275c24c691211db29e4228deec48a3867581;hpb=c988f1f4faa9f679f79beddf3c14676c5dcb8e28;p=exim.git diff --git a/src/src/smtp_out.c b/src/src/smtp_out.c index 2c63275c2..d4aed3735 100644 --- a/src/src/smtp_out.c +++ b/src/src/smtp_out.c @@ -1,10 +1,10 @@ -/* $Cambridge: exim/src/src/smtp_out.c,v 1.3 2005/01/04 10:00:42 ph10 Exp $ */ +/* $Cambridge: exim/src/src/smtp_out.c,v 1.9 2007/01/30 15:10:59 ph10 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * *************************************************/ -/* Copyright (c) University of Cambridge 1995 - 2005 */ +/* Copyright (c) University of Cambridge 1995 - 2007 */ /* See the file NOTICE for conditions of use and distribution. */ /* A number of functions for driving outgoing SMTP calls. */ @@ -155,12 +155,13 @@ non-IPv6 systems, to enable the code to be less messy. However, on such systems host->address will always be an IPv4 address. The port field in the host item is used if it is set (usually router from SRV -records). In other cases, the default passed as an argument is used. +records or elsewhere). In other cases, the default passed as an argument is +used, and the host item is updated with its value. Arguments: host host item containing name and address (and sometimes port) host_af AF_INET or AF_INET6 - port default, remote port to connect to, in host byte order for those + port default remote port to connect to, in host byte order, for those hosts whose port setting is PORT_NONE interface outgoing interface address or NULL timeout timeout value or 0 @@ -184,6 +185,7 @@ if (host->port != PORT_NONE) host->port); port = host->port; } +else host->port = port; /* Set the port actually used */ HDEBUG(D_transport|D_acl|D_v) { @@ -223,14 +225,14 @@ else if (ip_connect(sock, host_af, host->address, port, timeout) < 0) if (save_errno != 0) { - HDEBUG(D_transport|D_acl|D_v) + HDEBUG(D_transport|D_acl|D_v) { debug_printf("failed: %s", CUstrerror(save_errno)); - if (save_errno == ETIMEDOUT) + if (save_errno == ETIMEDOUT) debug_printf(" (timeout=%s)", readconf_printtime(timeout)); - debug_printf("\n"); - } - close(sock); + debug_printf("\n"); + } + (void)close(sock); errno = save_errno; return -1; } @@ -239,7 +241,18 @@ if (save_errno != 0) else { + union sockaddr_46 interface_sock; + EXIM_SOCKLEN_T size = sizeof(interface_sock); HDEBUG(D_transport|D_acl|D_v) debug_printf("connected\n"); + if (getsockname(sock, (struct sockaddr *)(&interface_sock), &size) == 0) + sending_ip_address = host_ntoa(-1, &interface_sock, NULL, &sending_port); + else + { + log_write(0, LOG_MAIN | ((errno == ECONNRESET)? 0 : LOG_PANIC), + "getsockname() failed: %s", strerror(errno)); + close(sock); + return -1; + } if (keepalive) ip_keepalive(sock, host->address, TRUE); return sock; }