1278 Chapter 61
These three segments are the SYN, SYN/ACK, and ACK segments exchanged for
the three-way handshake (see Figure 61-5).
In the following output, the client sends the server two messages, containing
16 and 32 bytes, respectively, and the server responds in each case with a 4-byte
message:
IP pukaki.60391 > tekapo.55555: P 1:17(16) ack 1 win 5840
IP tekapo.55555 > pukaki.60391:. ack 17 win 1448
IP tekapo.55555 > pukaki.60391: P 1:5(4) ack 17 win 1448
IP pukaki.60391 > tekapo.55555:. ack 5 win 5840
IP pukaki.60391 > tekapo.55555: P 17:49(32) ack 5 win 5840
IP tekapo.55555 > pukaki.60391:. ack 49 win 1448
IP tekapo.55555 > pukaki.60391: P 5:9(4) ack 49 win 1448
IP pukaki.60391 > tekapo.55555:. ack 9 win 5840
For each of the data segments, we see an ACK sent in the opposite direction.
Lastly, we show the segments exchanged during connection termination (first,
the client closes its end of the connection, and then the server closes the other end):
IP pukaki.60391 > tekapo.55555: F 49:49(0) ack 9 win 5840
IP tekapo.55555 > pukaki.60391:. ack 50 win 1448
IP tekapo.55555 > pukaki.60391: F 9:9(0) ack 50 win 1448
IP pukaki.60391 > tekapo.55555:. ack 10 win 5840
The above output shows the four segments exchanged during connection termina-
tion (see Figure 61-6).
61.9 Socket Options
Socket options affect various features of the operation of a socket. In this book, we
describe just a couple of the many socket options that are available. An extensive
discussion covering most standard socket options is provided in [Stevens et al.,
2004]. See the tcp(7), udp(7), ip(7), socket(7), and unix(7) manual pages for addi-
tional Linux-specific details.
The setsockopt() and getsockopt() system calls set and retrieve socket options.
For both setsockopt() and getsockopt(), sockfd is a file descriptor referring to a socket.
The level argument specifies the protocol to which the socket option applies—
for example, IP or TCP. For most of the socket options that we describe in this
book, level is set to SOL_SOCKET, which indicates an option that applies at the sockets
API level.
#include <sys/socket.h>
int getsockopt(int sockfd, int level, int optname, void *optval,
socklen_t *optlen);
int setsockopt(int sockfd, int level, int optname, const void *optval,
socklen_t optlen);
Both return 0 on success, or –1 on error