diff --git a/support/ab.c b/support/ab.c index ce8b209..ec345cd 100644 --- a/support/ab.c +++ b/support/ab.c @@ -299,6 +299,7 @@ char proxyhost[1024]; /* proxy host name */ 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]; @@ -1147,6 +1148,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; @@ -1170,6 +1172,13 @@ static void start_connect(struct connection * c) != APR_SUCCESS) { apr_err("socket nonblock", rv); } + 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); + } if (windowsize != 0) { rv = apr_socket_opt_set(c->aprsock, APR_SO_SNDBUF, @@ -1866,6 +1875,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"); @@ -2040,7 +2050,7 @@ int main(int argc, const char * const argv[]) #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 @@ -2064,6 +2074,9 @@ int main(int argc, const char * const argv[]) case 'b': windowsize = atoi(optarg); break; + case 's': + src_address = strdup(optarg); + break; case 'i': if (posting > 0) err("Cannot mix POST/PUT and HEAD\n");