This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: socket.getsockopt bug
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: gangesmaster, splitscreen
Priority: normal Keywords:

Created on 2006-05-05 09:22 by gangesmaster, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg28426 - (view) Author: ganges master (gangesmaster) Date: 2006-05-05 09:22
i tested this on windows xp. the installed python
version is the 2.4.3 from the windows MSI.

when doing socket.getsockopt with buffer_size > 0, for
options like SO_LINGER or SO_SNDTIMEO, i get only 4 bytes. 
although the man pages state these options hold 8
bytes. is this a bug in the pythonic version of
getsockopt or winsock?

-tomer
msg28427 - (view) Author: Matt Fleming (splitscreen) Date: 2006-05-05 13:12
Logged In: YES 
user_id=1126061

According to http://www.sockets.com/winsock.htm#GetSockOpt

"The integer pointed to by optlen should originally contain
the size of this buffer; on return, it will be set to the
size of the value returned. For SO_LINGER, this will be the
size of a struct linger; for all other options it will be
the size of an integer." 

The size of a linger struct is 4 bytes. 

I would agree that the Python documentation for
socket.getsockopt is a little confusing.

"Get a socket option.  See the Unix manual for level and
option. If a nonzero buffersize argument is given, the
return value is a string of that length; otherwise it is an
integer."

Perhaps just refer users to the OSes documentation on its
implementation of sockets?

Matt
msg28428 - (view) Author: ganges master (gangesmaster) Date: 2006-05-05 13:43
Logged In: YES 
user_id=1406776

i don't think so:

according to http://www.sockets.com/winsock.htm#GetSockOpt
and
http://www.gnu.org/software/libc/manual/html_node/Socket_002dLevel-Options.html

struct linger is defined this way:

struct linger {
	int	l_onoff;
	int	l_linger;
}

which means 8 bytes, and the same goes for struct timeval:

struct timeval {
        long    tv_sec;
        long    tv_usec;
};

still, the getsockopt returns only 4. i looked at the python
source but i can't find the bug... perhaps its a bug with
how they use winsock?

-tomer
msg28429 - (view) Author: Matt Fleming (splitscreen) Date: 2006-05-05 13:51
Logged In: YES 
user_id=1126061

Visual Studio .NET 2003 comes with WinSock.h and defines the
linger struct as,

struct  linger {
        u_short l_onoff;                /* option on/off */
        u_short l_linger;               /* linger time */
};

However, on my NetBSD machine the linger struct is defined as,

struct  linger {
        int     l_onoff;                /* option on/off */
        int     l_linger;               /* linger time in
seconds */
};
msg28430 - (view) Author: ganges master (gangesmaster) Date: 2006-05-05 14:26
Logged In: YES 
user_id=1406776

lovely. i hate windows. i guess it's not a bug then -- it's
a feature. arghh.

and i now found that SNDTIMEO doesn't take a timeval, rather
an integer. just great. so i'll close the bug.

-tomer
History
Date User Action Args
2022-04-11 14:56:17adminsetgithub: 43322
2006-05-05 09:22:38gangesmastercreate