mirror of
https://repo.or.cz/socat.git
synced 2025-07-08 13:36:32 +00:00
SO_REUSEADDR per default on TCP LISTEN; so-reuseaddr=
This commit is contained in:
parent
b5640dd707
commit
2a9623d61c
9 changed files with 714 additions and 242 deletions
36
xio-socket.c
36
xio-socket.c
|
@ -97,7 +97,7 @@ const struct optdesc opt_so_debug = { "so-debug", "debug", OPT_SO_DEBUG,
|
|||
const struct optdesc opt_so_acceptconn={ "so-acceptconn","acceptconn",OPT_SO_ACCEPTCONN,GROUP_SOCKET,PH_PASTSOCKET,TYPE_INT, OFUNC_SOCKOPT, SOL_SOCKET, SO_ACCEPTCONN};
|
||||
#endif /* SO_ACCEPTCONN */
|
||||
const struct optdesc opt_so_broadcast= { "so-broadcast", "broadcast", OPT_SO_BROADCAST,GROUP_SOCKET, PH_PASTSOCKET, TYPE_INT, OFUNC_SOCKOPT, SOL_SOCKET, SO_BROADCAST};
|
||||
const struct optdesc opt_so_reuseaddr= { "so-reuseaddr", "reuseaddr", OPT_SO_REUSEADDR,GROUP_SOCKET, PH_PREBIND, TYPE_INT, OFUNC_SOCKOPT, SOL_SOCKET, SO_REUSEADDR};
|
||||
const struct optdesc opt_so_reuseaddr= { "so-reuseaddr", "reuseaddr", OPT_SO_REUSEADDR,GROUP_SOCKET, PH_PREBIND, TYPE_INT_NULL, OFUNC_SOCKOPT, SOL_SOCKET, SO_REUSEADDR};
|
||||
const struct optdesc opt_so_keepalive= { "so-keepalive", "keepalive", OPT_SO_KEEPALIVE,GROUP_SOCKET, PH_FD, TYPE_INT, OFUNC_SOCKOPT, SOL_SOCKET, SO_KEEPALIVE};
|
||||
#if HAVE_STRUCT_LINGER
|
||||
const struct optdesc opt_so_linger = { "so-linger", "linger", OPT_SO_LINGER, GROUP_SOCKET, PH_PASTSOCKET, TYPE_LINGER,OFUNC_SOCKOPT,SOL_SOCKET, SO_LINGER };
|
||||
|
@ -2153,3 +2153,37 @@ int xiobind(
|
|||
applyopts(xfd->fd, opts, PH_PASTBIND);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Handles the SO_REUSEADDR socket option for TCP LISTEN addresses depending on
|
||||
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
|
||||
SO_REUSEADDR
|
||||
Return 0 on success, or -1 with errno when an error occurred.
|
||||
*/
|
||||
int xiosock_reuseaddr(int fd, int ipproto, struct opt *opts)
|
||||
{
|
||||
union integral val;
|
||||
union integral notnull;
|
||||
int _errno;
|
||||
|
||||
val.u_int = 0;
|
||||
notnull.u_bool = false;
|
||||
if (ipproto == IPPROTO_TCP) {
|
||||
val.u_int = 1;
|
||||
notnull.u_bool = true;
|
||||
}
|
||||
retropt_2integrals(opts, OPT_SO_REUSEADDR, &val, ¬null);
|
||||
if (notnull.u_bool) {
|
||||
if (Setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val.u_int, sizeof(int))
|
||||
!= 0) {
|
||||
_errno = errno;
|
||||
Error4("setsockopt(%d, SOL_SOCKET, SO_REUSEADDR, { %d }, "F_Zu"): %s",
|
||||
fd, val.u_int, sizeof(val.u_int), strerror(errno));
|
||||
errno = _errno;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue