File tree 2 files changed +9
-7
lines changed
2 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -216,7 +216,6 @@ pub const SOCK_STREAM: c_int = 1;
216
216
pub const SOL_SOCKET : c_int = 0xffff ;
217
217
pub const SO_RCVTIMEO : c_int = 0x1006 ;
218
218
pub const SO_SNDTIMEO : c_int = 0x1005 ;
219
- pub const SO_REUSEADDR : c_int = 0x0004 ;
220
219
pub const IPPROTO_IP : c_int = 0 ;
221
220
pub const IPPROTO_TCP : c_int = 6 ;
222
221
pub const IPPROTO_IPV6 : c_int = 41 ;
Original file line number Diff line number Diff line change @@ -368,12 +368,15 @@ impl TcpListener {
368
368
369
369
let sock = Socket :: new ( addr, c:: SOCK_STREAM ) ?;
370
370
371
- // On platforms with Berkeley-derived sockets, this allows
372
- // to quickly rebind a socket, without needing to wait for
373
- // the OS to clean up the previous one.
374
- if !cfg ! ( windows) {
375
- setsockopt ( & sock, c:: SOL_SOCKET , c:: SO_REUSEADDR , 1 as c_int ) ?;
376
- }
371
+ // On platforms with Berkeley-derived sockets, this allows to quickly
372
+ // rebind a socket, without needing to wait for the OS to clean up the
373
+ // previous one.
374
+ //
375
+ // On Windows, this allows rebinding sockets which are actively in use,
376
+ // which allows “socket hijacking”, so we explicitly don't set it here.
377
+ // https://docs.microsoft.com/en-us/windows/win32/winsock/using-so-reuseaddr-and-so-exclusiveaddruse
378
+ #[ cfg( not( windows) ) ]
379
+ setsockopt ( & sock, c:: SOL_SOCKET , c:: SO_REUSEADDR , 1 as c_int ) ?;
377
380
378
381
// Bind our new socket
379
382
let ( addrp, len) = addr. into_inner ( ) ;
You can’t perform that action at this time.
0 commit comments