Skip to content

Commit 8c35a30

Browse files
Merge pull request #87 from srnym/master
Avoid ephemeral port exhaustion when binding to a specific IP
2 parents c8ed964 + 0c3015d commit 8c35a30

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

socket.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ int socket_connect_one(struct thread *t, int flags)
327327
socket_init_not_established(t, s);
328328
if (t->local_hosts) {
329329
int i = (t->flow_first + t->flow_count) % t->num_local_hosts;
330+
int enable = 1;
331+
setsockopt(s, SOL_IP, IP_BIND_ADDRESS_NO_PORT, &enable,
332+
sizeof(enable));
330333
bind_or_die(s, t->local_hosts[i], t->cb);
331334
}
332335
if (t->fn->fn_pre_connect) {

0 commit comments

Comments
 (0)