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.14/docs/man/ab.8 httpd-2.2.14.oden/docs/man/ab.8 --- httpd-2.2.14/docs/man/ab.8 2009-09-14 21:53:24.000000000 +0200 +++ httpd-2.2.14.oden/docs/man/ab.8 2009-09-26 16:54:32.000000000 +0200 @@ -121,6 +121,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.14/support/ab.c httpd-2.2.14.oden/support/ab.c --- httpd-2.2.14/support/ab.c 2009-09-14 21:43:02.000000000 +0200 +++ httpd-2.2.14.oden/support/ab.c 2009-09-26 16:56:44.000000000 +0200 @@ -292,6 +292,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]; @@ -1140,6 +1141,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; @@ -1177,6 +1179,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) { @@ -1857,6 +1867,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"); @@ -2031,7 +2042,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:u:v:rkVhwix:y:z:C:H:P:A:g:X:de:Sq" + while ((status = apr_getopt(opt, "s:n:c:t:b:T:p:u:v:rkVhwix:y:z:C:H:P:A:g:X:de:Sq" #ifdef USE_SSL "Z:f:" #endif @@ -2046,6 +2057,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;