TCP Options Flashcards

1
Q

What three parameters identify a socket option?

A
  1. Option level (protocol), 2. Option name (e.g., SO_REUSEADDR), 3. Option value (integer/string/float).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the purpose of SOL_SOCKET?

A

A socket level for protocol-independent options (e.g., SO_RCVBUF, SO_REUSEADDR).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do SO_RCVBUF and SO_SNDBUF differ from the recv() buffer?

A

SO_RCVBUF/SO_SNDBUF set OS-level buffer sizes for receiving/sending data, while recv() specifies max bytes to read per call.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does SO_REUSEADDR enable?

A

Allows multiple sockets to bind to the same address (useful for restarting servers or bypassing TIME_WAIT). Must be set before binding.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does SO_EXCLUSIVEADDRUSE conflict with SO_REUSEADDR?

A

SO_EXCLUSIVEADDRUSE prevents address sharing even if SO_REUSEADDR is set. Common on Windows for security.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does SO_ACCEPTCONN indicate?

A

Returns 1 if the socket is in listening mode (via listen()), 0 otherwise. Read-only.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does SO_LINGER affect socket closure?

A

Controls unsent data during close(). If enabled, blocks until data is sent or a timeout expires (configurable).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the default value of SO_KEEPALIVE?

A

Disabled (0). Enables periodic connection checks to detect dead peers. Requires TCP (SOCK_STREAM).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What additional TCP options refine SO_KEEPALIVE?

A

TCP_KEEPCNT (probe count), TCP_KEEPIDLE (idle time before probes), TCP_KEEPINTVL (interval between probes).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does SO_BROADCAST enable?

A

Allows UDP sockets to send messages to broadcast addresses (e.g., 255.255.255.255). Disabled by default.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do SO_RCVTIMEO and SO_SNDTIMEO differ from settimeout()?

A

They set separate timeouts for receive/send operations, while settimeout() applies to all blocking methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is TCP_FASTOPEN (TFO) used for?

A

Allows data exchange during TCP handshake (SYN packets). Requires a cookie setup. Disabled by default except on macOS.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How does TCP_NODELAY affect data transmission?

A

Disables Nagle’s algorithm, reducing latency by sending small packets immediately instead of buffering.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the syntax to set SO_REUSEADDR?

A

socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Why might setting SO_RCVBUF to 262,144 fail on Windows?

A

Windows limits buffer sizes (tested max is 262,144 bytes). OS may override larger values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What happens if SO_LINGER is set with a timeout?

A

The socket blocks during close() until data is sent or the timeout expires, then sends RST to force closure.

17
Q

What protocol family is required for SO_BROADCAST?

A

AF_INET (IPv4). Does not work with SOCK_STREAM or IPv6.

18
Q

How to check if a socket is in listening mode?

A

Use socket.getsockopt(SOL_SOCKET, SO_ACCEPTCONN). Returns 1 if listening.

19
Q

What is the default buffer size for SO_RCVBUF on Windows 11?

A

65,536 bytes (may vary by OS).

20
Q

Why use TCP_KEEPIDLE with SO_KEEPALIVE?

A

To configure idle time (default 7200s) before sending keepalive probes.

21
Q

What is the purpose of Nagle’s algorithm?

A

Reduces network overhead by buffering small packets into larger segments. Disabled via TCP_NODELAY.

22
Q

What are the two steps in TCP Fast Open (TFO)?

A
  1. Client requests cookie via SYN. 2. Client sends data in SYN with cookie for future connections.
23
Q

How to enable UDP broadcast in Python?

A

Set SO_BROADCAST to 1: s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1).

24
Q

What happens if SO_EXCLUSIVEADDRUSE is set on Windows?

A

Prevents other sockets from binding to the same address, even if they use SO_REUSEADDR.