[ python-Bugs-1482328 ] socket.getsockopt bug

SourceForge.net noreply at sourceforge.net
Fri May 5 16:26:19 CEST 2006


Bugs item #1482328, was opened at 2006-05-05 12:22
Message generated for change (Comment added) made by gangesmaster
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1482328&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: ganges master (gangesmaster)
Assigned to: Nobody/Anonymous (nobody)
Summary: socket.getsockopt bug

Initial Comment:
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

----------------------------------------------------------------------

>Comment By: ganges master (gangesmaster)
Date: 2006-05-05 17:26

Message:
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

----------------------------------------------------------------------

Comment By: Matt Fleming (splitscreen)
Date: 2006-05-05 16:51

Message:
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 */
};


----------------------------------------------------------------------

Comment By: ganges master (gangesmaster)
Date: 2006-05-05 16:43

Message:
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

----------------------------------------------------------------------

Comment By: Matt Fleming (splitscreen)
Date: 2006-05-05 16:12

Message:
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


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1482328&group_id=5470


More information about the Python-bugs-list mailing list