Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Mar 1999 13:03:43 +0100
From:      Stefan Bethke <stefan.bethke@hanse.de>
To:        boards yan <boardyan@yahoo.com>
Cc:        freebsd-net@FreeBSD.ORG
Subject:   Re: exhausted
Message-ID:  <652340.3130664623@d225.promo.de>
In-Reply-To: <19990317050858.7049.rocketmail@web704.mail.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
boards yan <boardyan@yahoo.com> wrote:

> I tried to set the tcp socket Option(SO_RCV,TCP_MAXSEG), but failed
> all the time.
> 
> The program seems quite normal.
> However, the supervision using tcpdump shows that
> the option is unchanged. :-(
> 
> Can anybody give me a reason?

[ code deleted ]

TCP_MAXSEG:
Quoting from Steven's TCP/IP Illustrated, Vol. II, pp. 1023:
A process can only decrease the MSS.  When a TCP socket is created,
tcp_newtcpcb initializes t_maxseg to its default of 512.  When a SYN is
received from the other end with an MSS option, tcp_input calls tcp_mss,
and t_maxseg can be set as high as the outgoing interface MTU (minus 40
bytes for the default IP and TCP headers), which is 1460 for an Ethernet.
Therefore, after a call to socket but before a connection is established, =
a
process can only decrease the MSS from its default of 512.  After a
connection is established, the process can decrease the MSS from whatever
value was selected by tcp_mss.

What do you expect from SO_RCVBUF? With the following code it does what it
should:

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

void main(void)
{
    int fd;
    struct sockaddr_in sin;
    int nrbuf;

    if ((fd =3D socket(PF_INET, SOCK_STREAM, 0)) < 0) {
        perror ("socket");
        return;
    }
    nrbuf =3D 65536l;
    if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &nrbuf, sizeof(nrbuf)) < 0) =
{
        perror ("setsockopt(SO_RCVBUF)");
        return;
    }
    sin.sin_len =3D sizeof(sin);
    sin.sin_family =3D AF_INET;
    sin.sin_addr.s_addr =3D htonl(0x7f000001);
    sin.sin_port =3D htons(23);
    if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
        perror ("connect");
        return;
    }
    close (fd);
}



tcpdump output:
12:54:05.561009 localhost.3828 > localhost.telnet: S
3917041307:3917041307(0) win 65535 <mss 16344,nop,wscale
1,nop,nop,timestamp 3761197 0,nop,nop,cc[|tcp]> (DF)

Without the setsockopt, tcpdump shows:
12:49:59.008210 localhost.3783 > localhost.telnet: S
3863968019:3863968019(0) win 16384 <mss 16344,nop,wscale
0,nop,nop,timestamp 3760704 0,nop,nop,cc[|tcp]> (DF)


Stefan

--
M=FChlendamm 12           |  Voice +49-40-256848, +49-177-3504009
D-22089 Hamburg         |  e-mail: stefan.bethke@hanse.de
Germany                 |          stb@freebsd.org



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?652340.3130664623>