diff --git a/CHANGES b/CHANGES index e2eea62..83ed6f0 100644 --- a/CHANGES +++ b/CHANGES @@ -107,6 +107,9 @@ Features: Procan tells if char is signed or unsigned + Socat now prints an info message when implicitely setting SO_REUSEADDR. + Thanks to Michael Renner for this suggestion. + Building: Disabling certain features during configure could break build process. diff --git a/xio-socket.c b/xio-socket.c index 2e7a42d..2eaed08 100644 --- a/xio-socket.c +++ b/xio-socket.c @@ -2327,7 +2327,7 @@ int xiobind( Socat option so-reuseaddr: Option not applied: set it to 1 Option applied with a value: set it to the value - Option applied eith empty value "so-reuseaddr=": do not call setsockopt() for + Option applied with empty value "so-reuseaddr=": do not call setsockopt() for SO_REUSEADDR Return 0 on success, or -1 with errno when an error occurred. */ @@ -2335,6 +2335,7 @@ int xiosock_reuseaddr(int fd, int ipproto, struct opt *opts) { union integral val; union integral notnull; + int result; int _errno; val.u_int = 0; @@ -2345,7 +2346,12 @@ int xiosock_reuseaddr(int fd, int ipproto, struct opt *opts) notnull.u_bool = true; } #endif /* WITH_TCP */ - retropt_2integrals(opts, OPT_SO_REUSEADDR, &val, ¬null); + result = retropt_2integrals(opts, OPT_SO_REUSEADDR, &val, ¬null); + if (ipproto == IPPROTO_TCP && result < 0) { + Info("Setting SO_REUSADDR on TCP listen socket implicitly"); + val.u_int = 1; + notnull.u_bool = true; + } if (notnull.u_bool) { if (Setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val.u_int, sizeof(int)) != 0) { diff --git a/xioopts.c b/xioopts.c index 505305d..db77499 100644 --- a/xioopts.c +++ b/xioopts.c @@ -3107,7 +3107,7 @@ int retropt_int(struct opt *opts, int optcode, int *result) { /* Looks for the first option of type <optcode>. If the option is found, this function stores its int value in *result, "consumes" the option, and returns 0. - If the option is not found, *result is not modified, and -1 is returned. */ + If the option is not found, values are not modified, and -1 is returned. */ int retropt_2integrals(struct opt *opts, int optcode, union integral *value1, union integral *value2) {