Author: Daniel Rench Description: Patch to add -s (source address) option to ab Origin: http://issues.apache.org/bugzilla/show_bug.cgi?id=32524 diff -Naurp httpd-2.2.9/docs/man/ab.8 httpd-2.2.9.oden/docs/man/ab.8 --- httpd-2.2.9/docs/man/ab.8 2004-11-20 21:16:24.000000000 +0100 +++ httpd-2.2.9.oden/docs/man/ab.8 2008-06-11 11:09:06.000000000 +0200 @@ -109,6 +109,9 @@ String to use as attributes for <table>\ -X \fIproxy\fR[:\fIport\fR] Use a proxy server for the requests\&. .TP +-s \fIsrc_address\fR +Set the local source address\&. +.TP -y \fI<tr>-attributes\fR String to use as attributes for <tr>\&. .TP diff -Naurp httpd-2.2.9/support/ab.c httpd-2.2.9.oden/support/ab.c --- httpd-2.2.9/support/ab.c 2008-05-28 14:58:01.000000000 +0200 +++ httpd-2.2.9.oden/support/ab.c 2008-06-11 11:06:25.000000000 +0200 @@ -286,6 +286,7 @@ char proxyhost[1024]; /* proxy host na int proxyport = 0; /* proxy port */ char *connecthost; apr_port_t connectport; +char *src_address; char *gnuplot; /* GNUplot file */ char *csvperc; /* CSV Percentile file */ char url[1024]; @@ -1128,6 +1129,7 @@ static void output_html_results(void) static void start_connect(struct connection * c) { apr_status_t rv; + apr_sockaddr_t *from; if (!(started < requests)) return; @@ -1165,6 +1167,14 @@ static void start_connect(struct connect } } + if (src_address) { + if ((rv = apr_sockaddr_info_get(&from, src_address, destsa->family, + 0, 0, c->ctx)) != APR_SUCCESS) + apr_err("src_address get", rv); + if ((rv = apr_socket_bind(c->aprsock, from)) != APR_SUCCESS) + apr_err("src_address bind", rv); + } + c->start = lasttime = apr_time_now(); #ifdef USE_SSL if (is_ssl) { @@ -1842,6 +1852,7 @@ static void usage(const char *progname) fprintf(stderr, " -P attribute Add Basic Proxy Authentication, the attributes\n"); fprintf(stderr, " are a colon separated username and password.\n"); fprintf(stderr, " -X proxy:port Proxyserver and port number to use\n"); + fprintf(stderr, " -s src_address Set the local source address\n"); fprintf(stderr, " -V Print version number and exit\n"); fprintf(stderr, " -k Use HTTP KeepAlive feature\n"); fprintf(stderr, " -d Do not show percentiles served table.\n"); @@ -2016,7 +2027,7 @@ int main(int argc, const char * const ar #endif apr_getopt_init(&opt, cntxt, argc, argv); - while ((status = apr_getopt(opt, "n:c:t:b:T:p:v:rkVhwix:y:z:C:H:P:A:g:X:de:Sq" + while ((status = apr_getopt(opt, "s:n:c:t:b:T:p:v:rkVhwix:y:z:C:H:P:A:g:X:de:Sq" #ifdef USE_SSL "Z:f:" #endif @@ -2031,6 +2042,9 @@ int main(int argc, const char * const ar case 'k': keepalive = 1; break; + case 's': + src_address = strdup(optarg); + break; case 'q': heartbeatres = 0; break;