All of lore.kernel.org
 help / color / mirror / Atom feed
From: Raphael Manfredi <Raphael_Manfredi@pobox.com>
To: linux-kernel@vger.kernel.org
Subject: setsockopt(SOL_SOCKET, SO_SNDBUF) broken on 2.4.18?
Date: Mon, 25 Feb 2002 22:08:06 +0100	[thread overview]
Message-ID: <2871.1014671286@nice.ram.loc> (raw)

Hi,

I run:

	Linux nice 2.4.18-pre7 #1 SMP Mon Jan 28 23:12:48 MET 2002 i686 unknown

I noticed that whenever I do:

	setsockopt(fd, SOL_SOCKET, SO_SNDBUF....)

followed by

	getsockopt(fd, SOL_SOCKET, SO_SNDBUF....)

to verify what the kernel has set, I read TWICE as much the amount used
for the set.  That is, if I set 8192, I read 16384.  Therefore, to set
the correct size, I need to half the parameter first.

Is this a known bug?  Is it setsockopt or getsockopt which returns the
wrong size?

Here's sample code demonstrating the problem:

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

static void set_send_buf(int fd, int size)
{
	int new_len;
	int arglen = sizeof(new_len);

	if (-1 == setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)))
		perror("setsockopt");

	if (-1 == getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &new_len, &arglen))
		perror("getsockopt");

	printf("size was %d, but set %d\n", size, new_len);
}

main()
{
	int fd = socket(AF_INET, SOCK_STREAM, 0);

	set_send_buf(fd, 8192);
	set_send_buf(fd, 16384);
}
--------------------------

When run, it displays:

	size was 8192, but set 16384
	size was 16384, but set 32768

Raphael

             reply	other threads:[~2002-02-25 21:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-25 21:08 Raphael Manfredi [this message]
2002-02-25 21:34 ` setsockopt(SOL_SOCKET, SO_SNDBUF) broken on 2.4.18? Richard B. Johnson
2002-02-25 22:19   ` Raphael Manfredi
2002-02-25 23:21     ` Alan Cox
2002-02-25 22:39 ` Alan Cox
2002-02-26  7:46   ` Raphael Manfredi
2002-02-26  9:39     ` Alan Cox
2002-02-26 12:54       ` Raphael Manfredi
2002-02-27 16:17     ` Horst von Brand
     [not found] <E16_Tly-0006Va-00@the-village.bc.nu>
2002-02-26  0:11 ` Ton Hospel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2871.1014671286@nice.ram.loc \
    --to=raphael_manfredi@pobox.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.