--- /dev/null
+commit 055e2cb463e4e4adf2d9292a50ac274938f9a5ac
+Author: Jeremy Harris <jgh146exb@wizmail.org>
+Date: Sat Sep 12 15:00:45 2015 +0100
+
+ New $callout_address variable to record spamd (etc) address. Bug 1652
+
+diff --git a/src/src/expand.c b/src/src/expand.c
+index 1bff521..f9849e6 100644
+--- a/src/src/expand.c
++++ b/src/src/expand.c
+@@ -462,6 +462,7 @@ static var_entry var_table[] = {
+ { "bounce_return_size_limit", vtype_int, &bounce_return_size_limit },
+ { "caller_gid", vtype_gid, &real_gid },
+ { "caller_uid", vtype_uid, &real_uid },
++ { "callout_address", vtype_stringptr, &callout_address },
+ { "compile_date", vtype_stringptr, &version_date },
+ { "compile_number", vtype_stringptr, &version_cnumber },
+ { "config_dir", vtype_stringptr, &config_main_directory },
+diff --git a/src/src/globals.c b/src/src/globals.c
+index f3b6791..55a101f 100644
+--- a/src/src/globals.c
++++ b/src/src/globals.c
+@@ -478,6 +478,7 @@ int bounce_return_size_limit = 100*1024;
+ uschar *bounce_sender_authentication = NULL;
+ int bsmtp_transaction_linecount = 0;
+
++uschar *callout_address = NULL;
+ int callout_cache_domain_positive_expire = 7*24*60*60;
+ int callout_cache_domain_negative_expire = 3*60*60;
+ int callout_cache_positive_expire = 24*60*60;
+diff --git a/src/src/globals.h b/src/src/globals.h
+index 3c69e43..7bfb5aa 100644
+--- a/src/src/globals.h
++++ b/src/src/globals.h
+@@ -255,6 +255,7 @@ extern int bounce_return_size_limit; /* Max amount to return */
+ extern uschar *bounce_sender_authentication; /* AUTH address for bounces */
+ extern int bsmtp_transaction_linecount; /* Start of last transaction */
+
++extern uschar *callout_address; /* Address used for a malware/spamd/verify etc. callout */
+ extern int callout_cache_domain_positive_expire; /* Time for positive domain callout cache records to expire */
+ extern int callout_cache_domain_negative_expire; /* Time for negative domain callout cache records to expire */
+ extern int callout_cache_positive_expire; /* Time for positive callout cache records to expire */
+diff --git a/src/src/ip.c b/src/src/ip.c
+index 2d71705..1e3875a 100644
+--- a/src/src/ip.c
++++ b/src/src/ip.c
+@@ -237,7 +237,11 @@ if (running_in_test_harness && save_errno == ECONNREFUSED && timeout == 999999)
+
+ /* Success */
+
+-if (rc >= 0) return 0;
++if (rc >= 0)
++ {
++ callout_address = string_sprintf("[%s]:%d", address, port);
++ return 0;
++ }
+
+ /* A failure whose error code is "Interrupted system call" is in fact
+ an externally applied timeout if the signal handler has been run. */
+@@ -400,6 +404,7 @@ if (connect(sock, (struct sockaddr *) &server, sizeof(server)) < 0)
+ path, strerror(err));
+ return -1;
+ }
++callout_address = string_copy(path);
+ return sock;
+ }
+
+diff --git a/src/src/smtp_out.c b/src/src/smtp_out.c
+index c704a0b..88dde83 100644
+--- a/src/src/smtp_out.c
++++ b/src/src/smtp_out.c
+@@ -284,6 +284,8 @@ if (host->port != PORT_NONE)
+ }
+ else host->port = port; /* Set the port actually used */
+
++callout_address = string_sprintf("[%s]:%d", host->address, port);
++
+ HDEBUG(D_transport|D_acl|D_v)
+ {
+ uschar * s = US" ";
+@@ -291,8 +293,7 @@ HDEBUG(D_transport|D_acl|D_v)
+ #ifdef EXPERIMENTAL_SOCKS
+ if (ob->socks_proxy) s = string_sprintf("%svia proxy ", s);
+ #endif
+- debug_printf("Connecting to %s [%s]:%d%s... ",
+- host->name, host->address, port, s);
++ debug_printf("Connecting to %s %s%s... ", host->name, callout_address, s);
+ }
+
+ /* Create and connect the socket */
+