Date: Sat, 11 Jan 1997 10:28:57 +0700 From: Eka Kelana <eka@werty.wasantara.net.id> To: freebsd-hackers@freebsd.org Cc: freebsd-questions@freebsd.org Subject: bug in setsockopt()... ? Message-ID: <1CA927E5D71@bandung.wasantara.net.id>
next in thread | raw e-mail | index | archive | help
Hi,
I wonder if there is anyone here ever experience a bug in
setsockopt(). I did this when I found the bug:
...skipped
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
err("socket");
mes("socket");
#if defined(SO_SNDBUF) || defined(SO_RCVBUF)
if (sockbufsize) {
if (trans) {
if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF,
(char*) &sockbufsize,sizeof(sockbufsize)) < 0)
err("setsockopt: sndbuf");
mes("sndbuf");
} else {
if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &sockbufsize,
sizeof sockbufsize) < 0)
err("setsockopt: rcvbuf");
mes("rcvbuf");
}
}
#endif
...skipped
optlen = sizeof(sockbufsize);
if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char *) &sockbufsize, &optlen) < 0)
err("getsockopt");
printf("socket send buff before connect: %d\n", sockbufsize);
if(connect(fd, &sinhim, sizeof(sinhim) ) < 0)
err("connect");
mes("connect");
optlen = sizeof(sockbufsize);
if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char *) &sockbufsize, &optlen) < 0)
err("getsockopt");
printf("socket buff size after connect: %d\n", sockbufsize);
The two getsockopt() above produced different value of socket buffer size.
When I didn't try to change the socket buffer size and used the default
value instead, the first getsockopt() would produce 16384 bytes. I think
this is the correct value, since FreeBSD set the default value for socket
buffer size to 16384 bytes.
But the second getsockopt() would produce 17280 bytes. I couldn't find any
reasonable explanation of this behaviour, but I think it is a bug in FreeBSD
networking code. I even couldn't set the socket buffer size to another
value. It still shows 17280 bytes. And another crosscheck using tcpdump
still shows a receive window of 17280 which means that the receive buffer is
set to 17280.
I need a reasonable explanation around this problem. Is there anyone here
who is able to give such explanation to me ?
-Eka Kelana-
STTTelkom
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1CA927E5D71>
