Skip to content

Commit 5db16f8

Browse files
author
Stefan Fritsch
committed
Support specifying the local address to use.
PR: 48930. Submitted by: Peter Schuller <scode spotify com> git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1139530 13f79535-47bb-0310-9956-ffa450edef68
1 parent 12c6cd2 commit 5db16f8

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
Changes with Apache 2.3.13
44

5+
*) ab: Support specifying the local address to use. PR 48930.
6+
[Peter Schuller <scode spotify com>]
7+
58
*) core: Add support to ErrorLogFormat for logging the system unique
69
thread id under Linux. [Stefan Fritsch]
710

docs/manual/programs/ab.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<p><code><strong>ab</strong>
3939
[ -<strong>A</strong> <var>auth-username</var>:<var>password</var> ]
4040
[ -<strong>b</strong> <var>windowsize</var> ]
41+
[ -<strong>B</strong> <var>local-address</var> ]
4142
[ -<strong>c</strong> <var>concurrency</var> ]
4243
[ -<strong>C</strong> <var>cookie-name</var>=<var>value</var> ]
4344
[ -<strong>d</strong> ]
@@ -80,6 +81,9 @@
8081
<dt><code>-b <var>windowsize</var></code></dt>
8182
<dd>Size of TCP send/receive buffer, in bytes.</dd>
8283

84+
<dt><code>-B <var>local-address</var></code></dt>
85+
<dd>Address to bind to when making outgoing connections.</dd>
86+
8387
<dt><code>-c <var>concurrency</var></code></dt>
8488
<dd>Number of multiple requests to perform at a time. Default is one
8589
request at a time.</dd>

support/ab.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ apr_port_t port; /* port number */
306306
char proxyhost[1024]; /* proxy host name */
307307
int proxyport = 0; /* proxy port */
308308
const char *connecthost;
309+
const char *myhost;
309310
apr_port_t connectport;
310311
const char *gnuplot; /* GNUplot file */
311312
const char *csvperc; /* CSV Percentile file */
@@ -370,6 +371,7 @@ apr_pool_t *cntxt;
370371

371372
apr_pollset_t *readbits;
372373

374+
apr_sockaddr_t *mysa;
373375
apr_sockaddr_t *destsa;
374376

375377
#ifdef NOT_ASCII
@@ -1201,6 +1203,10 @@ static void start_connect(struct connection * c)
12011203
apr_err("socket", rv);
12021204
}
12031205

1206+
if ((rv = apr_socket_bind(c->aprsock, mysa)) != APR_SUCCESS) {
1207+
apr_err("bind", rv);
1208+
}
1209+
12041210
c->pollfd.desc_type = APR_POLL_SOCKET;
12051211
c->pollfd.desc.s = c->aprsock;
12061212
c->pollfd.reqevents = 0;
@@ -1699,6 +1705,14 @@ static void test(void)
16991705
#endif /* NOT_ASCII */
17001706

17011707
/* This only needs to be done once */
1708+
if ((rv = apr_sockaddr_info_get(&mysa, myhost, APR_UNSPEC, 0, 0, cntxt)) != APR_SUCCESS) {
1709+
char buf[120];
1710+
apr_snprintf(buf, sizeof(buf),
1711+
"apr_sockaddr_info_get() for %s", myhost);
1712+
apr_err(buf, rv);
1713+
}
1714+
1715+
/* This too */
17021716
if ((rv = apr_sockaddr_info_get(&destsa, connecthost, APR_UNSPEC, connectport, 0, cntxt))
17031717
!= APR_SUCCESS) {
17041718
char buf[120];
@@ -1857,6 +1871,7 @@ static void usage(const char *progname)
18571871
fprintf(stderr, " -c concurrency Number of multiple requests to make\n");
18581872
fprintf(stderr, " -t timelimit Seconds to max. wait for responses\n");
18591873
fprintf(stderr, " -b windowsize Size of TCP send/receive buffer, in bytes\n");
1874+
fprintf(stderr, " -B address Address to bind to when making outgoing connections\n");
18601875
fprintf(stderr, " -p postfile File containing data to POST. Remember also to set -T\n");
18611876
fprintf(stderr, " -u putfile File containing data to PUT. Remember also to set -T\n");
18621877
fprintf(stderr, " -T content-type Content-type header for POSTing, eg.\n");
@@ -2051,8 +2066,10 @@ int main(int argc, const char * const argv[])
20512066
}
20522067
#endif
20532068

2069+
myhost = NULL; /* 0.0.0.0 or :: */
2070+
20542071
apr_getopt_init(&opt, cntxt, argc, argv);
2055-
while ((status = apr_getopt(opt, "n:c:t:b:T:p:u:v:rkVhwix:y:z:C:H:P:A:g:X:de:Sq"
2072+
while ((status = apr_getopt(opt, "n:c:t:b:T:p:u:v:rkVhwix:y:z:C:H:P:A:g:X:de:SqB:"
20562073
#ifdef USE_SSL
20572074
"Z:f:"
20582075
#endif
@@ -2212,6 +2229,9 @@ int main(int argc, const char * const argv[])
22122229
case 'V':
22132230
copyright();
22142231
return 0;
2232+
case 'B':
2233+
myhost = apr_pstrdup(cntxt, opt_arg);
2234+
break;
22152235
#ifdef USE_SSL
22162236
case 'Z':
22172237
ssl_cipher = strdup(opt_arg);

0 commit comments

Comments
 (0)