TCP Options Flashcards
What three parameters identify a socket option?
- Option level (protocol), 2. Option name (e.g., SO_REUSEADDR), 3. Option value (integer/string/float).
What is the purpose of SOL_SOCKET
?
A socket level for protocol-independent options (e.g., SO_RCVBUF, SO_REUSEADDR).
How do SO_RCVBUF
and SO_SNDBUF
differ from the recv()
buffer?
SO_RCVBUF/SO_SNDBUF set OS-level buffer sizes for receiving/sending data, while recv()
specifies max bytes to read per call.
What does SO_REUSEADDR
enable?
Allows multiple sockets to bind to the same address (useful for restarting servers or bypassing TIME_WAIT). Must be set before binding.
How does SO_EXCLUSIVEADDRUSE
conflict with SO_REUSEADDR
?
SO_EXCLUSIVEADDRUSE prevents address sharing even if SO_REUSEADDR is set. Common on Windows for security.
What does SO_ACCEPTCONN
indicate?
Returns 1 if the socket is in listening mode (via listen()
), 0 otherwise. Read-only.
How does SO_LINGER
affect socket closure?
Controls unsent data during close()
. If enabled, blocks until data is sent or a timeout expires (configurable).
What is the default value of SO_KEEPALIVE
?
Disabled (0). Enables periodic connection checks to detect dead peers. Requires TCP (SOCK_STREAM).
What additional TCP options refine SO_KEEPALIVE
?
TCP_KEEPCNT (probe count), TCP_KEEPIDLE (idle time before probes), TCP_KEEPINTVL (interval between probes).
What does SO_BROADCAST
enable?
Allows UDP sockets to send messages to broadcast addresses (e.g., 255.255.255.255). Disabled by default.
How do SO_RCVTIMEO
and SO_SNDTIMEO
differ from settimeout()
?
They set separate timeouts for receive/send operations, while settimeout()
applies to all blocking methods.
What is TCP_FASTOPEN
(TFO) used for?
Allows data exchange during TCP handshake (SYN packets). Requires a cookie setup. Disabled by default except on macOS.
How does TCP_NODELAY
affect data transmission?
Disables Nagle’s algorithm, reducing latency by sending small packets immediately instead of buffering.
What is the syntax to set SO_REUSEADDR
?
socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
Why might setting SO_RCVBUF
to 262,144 fail on Windows?
Windows limits buffer sizes (tested max is 262,144 bytes). OS may override larger values.
What happens if SO_LINGER
is set with a timeout?
The socket blocks during close()
until data is sent or the timeout expires, then sends RST to force closure.
What protocol family is required for SO_BROADCAST
?
AF_INET (IPv4). Does not work with SOCK_STREAM or IPv6.
How to check if a socket is in listening mode?
Use socket.getsockopt(SOL_SOCKET, SO_ACCEPTCONN)
. Returns 1 if listening.
What is the default buffer size for SO_RCVBUF
on Windows 11?
65,536 bytes (may vary by OS).
Why use TCP_KEEPIDLE
with SO_KEEPALIVE
?
To configure idle time (default 7200s) before sending keepalive probes.
What is the purpose of Nagle’s algorithm?
Reduces network overhead by buffering small packets into larger segments. Disabled via TCP_NODELAY
.
What are the two steps in TCP Fast Open (TFO)?
- Client requests cookie via SYN. 2. Client sends data in SYN with cookie for future connections.
How to enable UDP broadcast in Python?
Set SO_BROADCAST
to 1: s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
.
What happens if SO_EXCLUSIVEADDRUSE
is set on Windows?
Prevents other sockets from binding to the same address, even if they use SO_REUSEADDR
.