NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

getsockopt() with TCP_INFO vs TCP_MAXSEG



It looks like getsockopt() with TCP_INFO on NetBSD-8 may be somewhat
buggy/broken. I'm using it to get TCP MSS (Max Segment Size) for TCP
socket, but instead of correct values I get some nonsense. Could
anyone familiar with this code review examples below and let me know
your thoughts.

There are two ways to get MSS:

1) call getsockopt() with TCP_INFO:
struct tcp_info tcpi;
socklen_t tcpi_len = sizeof(tcpi);
getsockopt(sock_fd, IPPROTO_TCP, TCP_INFO, (void *)&tcpi, &tcpi_len);

2) call getsockopt() with TCP_MAXSEG:
int sockopt_int;
socklen_t sockopt_int_len = sizeof(sockopt_int);
getsockopt(conn_fd, IPPROTO_TCP, TCP_MAXSEG, &sockopt_int, &sockopt_int_len);

Client socket when sending data to server:
snd_mss=33572,  rcv_mss=33572,  mss=33584

Server socket when receiving data from client:
snd_mss=16384,  rcv_mss=16384,  mss=33584

The values for snd_mss and rcv_mss were obtained with TCP_INFO, the
value for mss was obtained with TCP_MAXSEG.

Socket I/O was done on 127.0.0.1 with MTU of 33624:
lo0: flags=0x8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33624

It would seem that mss value obtained with getsockopt() and TCP_MAXSEG
is correct (33624 byte MTU - 40 byte for IP plus TCP headers = 33584
bytes), however snd_mss and rcv_mss values obtained with getsockopt
and TCP_INFO appear to be incorrect. Also why server socket reports
them as 16384 bytes when client reports them as 33572 bytes?

Any ideas?



Home | Main Index | Thread Index | Old Index