Commit Graph

375 Commits

Author SHA1 Message Date
Martin v. Löwis 02cbf4ae4b More unconsting. 2006-02-27 17:20:04 +00:00
Guido van Rossum 668a94a34f NETLINK_TCPDIAG and NETLINK_NFLOG aren't defined on older Linux
systems; define these conditionally.
2006-02-21 01:07:27 +00:00
Georg Brandl dbd8339a01 Bug #854823: socketmodule now builds on Sun platforms even when
INET_ADDRSTRLEN is not defined.
2006-02-20 09:42:33 +00:00
Martin v. Löwis f84d1b9375 Introduce Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE.
Proposed by Tim Peters.
2006-02-11 09:27:05 +00:00
Neal Norwitz 082b2df33f Bug #876637, prevent stack corruption when socket descriptor
is larger than FD_SETSIZE.

This can only be acheived with ulimit -n SOME_NUMBER_BIGGER_THAN_FD_SETSIZE
which is typically only available to root.  Since this wouldn't normally
be run in a test (ie, run as root), it doesn't seem too worthwhile to
add a normal test.  The bug report has one version of a test.  I've
written another.  Not sure what the best thing to do is.

Do the check before calling internal_select() because we can't set
an error in between Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS.
This seemed the clearest solution, ie handle before calling internal_select()
rather than inside.  Plus there is at least one place outside
of internal_select() that needed to be handled.

Will backport.
2006-02-07 07:04:46 +00:00
Neal Norwitz 1ac754fa10 Check return result from Py_InitModule*(). This API can fail.
Probably should be backported.
2006-01-19 06:09:39 +00:00
Neal Norwitz 658516617c Get socketmodule to build after adding netlink support. 2006-01-16 04:31:40 +00:00
Martin v. Löwis d056005482 Change build format of netlink addresses. 2006-01-15 07:49:20 +00:00
Martin v. Löwis 11017b172d Patch #1103116: AF_NETLINK sockets basic support. 2006-01-14 18:12:57 +00:00
Neal Norwitz 30b5c5d011 Fix SF bug #1072182, problems with signed characters.
Most of these can be backported.
2005-12-19 06:05:18 +00:00
Jeremy Hylton af68c874a6 Add const to several API functions that take char *.
In C++, it's an error to pass a string literal to a char* function
without a const_cast().  Rather than require every C++ extension
module to put a cast around string literals, fix the API to state the
const-ness.

I focused on parts of the API where people usually pass literals:
PyArg_ParseTuple() and friends, Py_BuildValue(), PyMethodDef, the type
slots, etc.  Predictably, there were a large set of functions that
needed to be fixed as a result of these changes.  The most pervasive
change was to make the keyword args list passed to
PyArg_ParseTupleAndKewords() to be a const char *kwlist[].

One cast was required as a result of the changes:  A type object
mallocs the memory for its tp_doc slot and later frees it.
PyTypeObject says that tp_doc is const char *; but if the type was
created by type_new(), we know it is safe to cast to char *.
2005-12-10 18:50:16 +00:00
Hye-Shik Chang 9ceebd5445 Patch #1288833: Removed thread lock from socket.getaddrinfo on
FreeBSD 5.3 and later versions which got thread-safe getaddrinfo(3).
(Reported by Maxim Sobolev)
2005-09-24 14:58:47 +00:00
Guido van Rossum 8ee3e5aa93 - Changes donated by Elemental Security to make it work on AIX 5.3
with IBM's 64-bit compiler (SF patch #1284289).  This also closes SF
  bug #105470: test_pwd fails on 64bit system (Opteron).
2005-09-14 18:09:42 +00:00
Georg Brandl d2e3ba7a35 patch [ 756021 ] Allow socket.inet_aton("255.255.255.255") on Windows 2005-08-26 08:34:00 +00:00
Jeremy Hylton 80961f3ca9 Fix apparently trivial buffer overflow (SF bug 1060396).
memset() wrote one past the end of the buffer, which was likely to be unused padding or a yet-to-be-initialized local variable.  This routine is already tested by test_socket.
2004-11-07 14:24:25 +00:00
Michael W. Hudson 3079391b8d Just remove the #include of signal.h. That it was C++-commented out
was a mistake of mine in updating patch #975056 (I think).
2004-10-14 13:27:14 +00:00
Neal Norwitz f7c8d9320b Use C89 style comment for old compilers 2004-10-14 03:48:30 +00:00
Anthony Baxter 9ceaa72ebe Patch #975056 - fixes for restartable signals on *BSD. In addition,
a few remaining calls to signal() were converted to PyOS_setsig().
2004-10-13 14:48:50 +00:00
Raymond Hettinger 87de0ca741 Silence a compiler warning by supplying the correct argument type to
the htons() function.
2004-09-28 02:19:40 +00:00
Trent Mick 8ea5bdf784 Patch for compilation on IRIX from rwgk on http://python.org/sf/728330 2004-09-13 17:48:41 +00:00
Trent Mick a708d6e3b0 Apply patch from http://python.org/sf/728330 to fix socket module compilation on Solaris 2.6, HP-UX 11, AIX 5.1 and (possibly) some IRIX versions. 2004-09-07 17:48:26 +00:00
Dave Cole e8bbfe4e63 Patch #1015012. Improve markup and punctuation in libsocket.tex 2004-08-26 00:51:16 +00:00
Martin v. Löwis b92b7ed9d6 Back out 1.289, which breaks platforms needing addrinfo.h, and
1.293, 1.298, and 1.300, which have tried to fix this for specific
platforms.
2004-08-25 06:24:58 +00:00
Dave Cole 07fda7e3a0 Updated the socketpair() docstring and documentation to explain that the
default famility is AF_UNIX if defined for the platform, otherwise the
default is AF_INET.
2004-08-23 05:16:23 +00:00
Dave Cole 0fc8575412 Removed unnecessary calls to signal() to ignore SIGPIPE. SIGPIPE is ignored
in initsigs() inside pythonrun.c.
2004-08-23 04:54:53 +00:00
Jason Tishler c246cb76e6 Bug #1001857: socketmodule does not build under cygwin
Restore clean building under Cygwin.
2004-08-09 13:25:59 +00:00
Dave Cole 331708b226 Patch #1003700: Add socketpair function to socket module. 2004-08-09 04:51:41 +00:00
Raymond Hettinger cbcff93d49 Restore compilation on MSVC++ 6.0 2004-08-03 08:52:46 +00:00
Mark Hammond a57ec93b93 Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on
connect error
2004-08-03 05:06:26 +00:00
Martin v. Löwis 81aec4bb80 Patch #984654: Add more address family constants. 2004-07-19 17:01:20 +00:00
Andrew M. Kuchling b8e1717041 [Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses 2004-07-10 23:39:35 +00:00
Andrew M. Kuchling 42851ab490 [Patch #982665 ] add SO_EXCLUSIVEADDRUSE constant 2004-07-10 14:19:21 +00:00
Andrew MacIntyre 5a8b4593d3 OS/2 EMX needs addrinfo.h for code included from getaddrinfo.c 2004-07-07 14:02:59 +00:00
Barry Warsaw 11b91a0ea3 Added socket.getservbyport(), and make its second argument and that of
getservbyname() optional.  Update the tests and the docs.
2004-06-28 00:50:43 +00:00
Martin v. Löwis 558d9bf528 Patch #929192: Improvements to bluetooth support.
Added setbdaddr and makebdaddr.
Extended makesockaddr to understand Bluetooth addresses.
Changed getsockaddr to expect the Bluetooth addresses as a string,
not a six element tuple.
Reformatted some of the Bluetooth code to be more consistent with PEP 7.
2004-06-03 09:24:42 +00:00
Martin v. Löwis 04697e89b9 Patch #924294: Do not check for AF_INET6 if it is not defined.
Will backport to 2.3.
2004-06-02 12:35:29 +00:00
Michael W. Hudson 76b8cc84a4 Band-aid type fix for
[ 728330 ] Don't define _SGAPI on IRIX

The Right Thing would be nice, for now this'll do.  At least it isn't
going to break anything *other* than IRIX...
2004-05-26 17:06:31 +00:00
Andrew MacIntyre daedf21852 Fixes for AF_UNIX support on OS/2:
- return the full size of the sockaddr_un structure, without which
  bind() fails with EINVAL;
- set test_socketserver to use a socket name that meets the form
  required by the underlying implementation;
- don't bother exercising the forking AF_UNIX tests on EMX - its
  fork() can't handle the stress.
2004-04-11 12:03:57 +00:00
Andrew MacIntyre d12dfbbcd9 OS/2's TCP/IP stack supports AF_UNIX sockets, with the limitation that
the socket name must start with /socket32/.  Unlike Unix systems, this
file never exists in the file system.
2004-04-04 07:13:49 +00:00
Brett Cannon 06c34798df Make socket.sslerror a subclass of socket.error .
Added socket.error to the socket module's C API.
2004-03-23 23:16:54 +00:00
Anthony Baxter 5d7c06720d Make socketmodule compile again on a modern Linux (that supports Bluetooth).
The Bluetooth code was obviously never tested on Linux.
2004-02-16 05:35:28 +00:00
Skip Montanaro 7befb9966e remove support for missing ANSI C header files (limits.h, stddef.h, etc). 2004-02-10 16:50:21 +00:00
Hye-Shik Chang 81268608bf Add FreeBSD support for bluetooth sockets.
(SF Patch #888148, reviewed by loewis)
2004-02-02 06:05:24 +00:00
Martin v. Löwis 12af0485f8 Patch #874083: Bluetooth support for socket module. 2004-01-31 12:34:17 +00:00
Martin v. Löwis da91d02461 Add IPV6_ socket options from RFCs 3493 and 3542. Fixes #867012. 2003-12-30 11:14:01 +00:00
Hye-Shik Chang a7b673f47c Fix erroneus argument parsing of socket.htons() on 64bit big endian
machines.
2003-12-17 09:40:23 +00:00
Martin v. Löwis 94681fc4a3 Patch #849595: Add socket.shutdown() constants. 2003-11-27 19:40:22 +00:00
Jack Jansen 4bae2d5e46 Getting rid of code dependent on GUSI or the MetroWerks compiler. 2003-11-19 22:52:23 +00:00
Walter Dörwald f0dfc7ac5c Fix a bunch of typos in documentation, docstrings and comments.
(From SF patch #810751)
2003-10-20 14:01:56 +00:00
Raymond Hettinger 8ae4689657 Simplify and speedup uses of Py_BuildValue():
* Py_BuildValue("(OOO)",a,b,c)  -->  PyTuple_Pack(3,a,b,c)
* Py_BuildValue("()",a)         -->  PyTuple_New(0)
* Py_BuildValue("O", a)         -->  Py_INCREF(a)
2003-10-12 19:09:37 +00:00
Anthony Baxter bab23cfc26 made the SGI INET_ADDRSTRLEN define apply for any compiler on Irix. Both the
SGI compiler and GCC seem to need this.
2003-10-04 08:00:49 +00:00
Martin v. Löwis a0f1734e44 Patch #813445: Add missing socket.IPPROTO_IPV6. Backported to 2.3. 2003-10-03 13:56:20 +00:00
Martin v. Löwis 5db099a4fe Release host name memory. Fixes #783312. Will backport to 2.3. 2003-08-07 11:55:15 +00:00
Martin v. Löwis 106490915b Patch #781722: Reject AF_INET6 if IPv6 is disabled. Will backport to 2.3. 2003-08-05 06:25:06 +00:00
Jeremy Hylton fb509a36c8 Get socketmodule compiling on IRIX 6.5.10.
I don't think the fix here is very good, but I'm not sure what would
be better.  In particular, we should not be defining _SGIAPI, but lots
of things break if we remove it.
2003-07-17 16:58:48 +00:00
Mark Hammond 14350ab006 Fix [ 766669 ] Consistent GPF on exit
Use Py_AtExit instead of atexit so we are called during Py_Finalize()
rather than during DLL teardown.
2003-07-09 04:57:46 +00:00
Raymond Hettinger ef7343c6cd SF patch #760257: add socket.timeout exception
(Contributed by Bob Halley)

Added a new exception, socket.timeout so that timeouts can be differentiated
from other socket exceptions.

Docs, more tests, and newsitem to follow.
2003-06-29 03:08:05 +00:00
Martin v. Löwis a94568a753 Patch #734231: Update RiscOS support. In particular, correct
riscospath.extsep, and use os.extsep throughout.
2003-05-10 07:36:56 +00:00
Just van Rossum 16e426bb15 Yet another addition to [731644]: only use the lock if thread-support
is enabled.
2003-05-09 08:12:00 +00:00
Just van Rossum 09aecd7a0d Addition to [731644]: also use the lock when using the getaddrinfo
emulation (ie. when HAVE_GETADDRINFO isn't defined).
2003-05-09 08:03:44 +00:00
Just van Rossum 1040d2ce7d [ 731644] & [ 604210 ] Release the GIL around getaddrinfo(), yet protect
access with lock on those platforms that getaddrinfo() isn't (known to be)
thread-safe. Thanks to MvL for mentoring this patch.
2003-05-09 07:53:18 +00:00
Martin v. Löwis e941617671 Patch #724588: Check whether the address of hstrerror and inet_pton can
be taken, and define NI_MAX{HOST|SERV} if necessary.
2003-05-03 10:12:45 +00:00
Martin v. Löwis c16f3bd8a3 Patch #708495: Port more stuff to OpenVMS. 2003-05-03 09:14:54 +00:00
Anthony Baxter 0e85f9d6fd Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
to that of Python2.1. Such nnn.nnn.nnn.nnn addresses are just used directly,
not passed to the resolver for a pointless lookup.
2003-05-02 15:40:46 +00:00
Martin v. Löwis fccac2e61a Patch #725942: Always rename emulation functions. 2003-05-01 05:20:46 +00:00
Guido van Rossum 47dfa4a89a Patch by Jp Calderone:
- The socket module now provides the functions inet_pton and inet_ntop
  for converting between string and packed representation of IP addresses.
  See SF patch #658327.

This still needs a bit of work in the doc area, because it is not
available on all platforms (especially not on Windows).
2003-04-25 05:48:32 +00:00
Martin v. Löwis 2548c730c1 Implement IDNA (Internationalized Domain Names in Applications). 2003-04-18 10:39:54 +00:00
Martin v. Löwis b9a0f91218 Rename LONG_LONG to PY_LONG_LONG. Fixes #710285. 2003-03-29 10:06:18 +00:00
Guido van Rossum b76bdf8ef7 The connect timeout code wasn't working on Windows.
Rather than trying to second-guess the various error returns
of a second connect(), use select() to determine whether the
socket becomes writable (which means connected).
2003-02-19 17:50:16 +00:00
Tim Peters 1df9fdd4d5 socket_inet_aton(): ip_addr was left undefined before use in the
!HAVE_INET_ATON case.  Repaired that, and tried to repair what looked
like out-of-date comments.
2003-02-13 03:13:40 +00:00
Neal Norwitz 88f115b0d4 Ummm, try to get it right this time 2003-02-13 02:15:42 +00:00
Neal Norwitz 10b214c2fd Use configure to check for inet_aton. 2003-02-13 02:11:10 +00:00
Guido van Rossum ad05cdfa1f Addressing SF bug #643005, implement socket.inet_aton() using
inet_aton() rather than inet_addr() -- the latter is obsolete because
it has a problem: "255.255.255.255" is a valid address but
indistinguishable from an error.

(I'm not sure if inet_aton() exists everywhere -- in case it doesn't,
I've left the old code in with an #ifdef.)
2003-02-12 23:08:22 +00:00
Guido van Rossum 8f24cdc0d5 SF patch #678257 by Geoff Talvola.
In sendall(), do an internal select before each send() call, instead
of only for the first one.
2003-01-31 18:15:58 +00:00
Jason Tishler fb8595df4f Patch #661760: Cygwin auto-import module patch
The attached patch enables shared extension
modules to build cleanly under Cygwin without
moving the static initialization of certain function
pointers (i.e., ones exported from the Python
DLL core) to a module initialization function.

Additionally, this patch fixes the modules that
have been changed in the past to accommodate
Cygwin.
2003-01-06 12:41:26 +00:00
Andrew MacIntyre 34d3e2d22a OS/2 sockets do not support AF_UNIX, even though EMX headers define it 2003-01-02 12:45:34 +00:00
Martin v. Löwis cf8f47ea95 Patch #650422: Use Posix AF_ constants instead of PF_ ones. 2002-12-11 13:10:57 +00:00
Martin v. Löwis 9e43730ca3 Don't include <ioctl.h> unless on __VMS. 2002-12-06 12:57:26 +00:00
Martin v. Löwis 79acb9edfa Patch #614055: Support OpenVMS. 2002-12-06 12:48:53 +00:00
Neal Norwitz 39d22e5693 Use O_NONBLOCK rather than O_NDELAY, so we get POSIX non-blocking I/O.
On HPUX, Solaris, Tru64 (Dec UNIX), and IRIX (I think),
O_NONBLOCK is the POSIX version of non-blocking I/O
which is what we want.

On Linux and FreeBSD (at least), O_NONBLOCK and O_NDELAY are the same.
So this change should have no negative effect on those platforms.

Tested on Linux, Solaris, HPUX.

Thanks to Anders Qvist for diagnosing this problem.
2002-11-02 19:55:21 +00:00
Martin v. Löwis 8eb92a014b Patch #608999: Fix portability problems with MIPSPro 7.x 2002-09-19 08:03:21 +00:00
Guido van Rossum 83a072d953 Update the module doc comment. 2002-09-03 19:10:18 +00:00
Neal Norwitz 90128ba22c SF bug #592645 fix memory leak in socket.getaddrinfo 2002-08-09 03:37:42 +00:00
Guido van Rossum 12e3c710db The other half of the patches added to SF patch 555085 by A I
MacIntyre.  At least on OS/2, a subsequent connect() on a nonblocking
socket returns errno==EISCONN to indicate success.  This seems
harmless on Unix.
2002-08-08 20:39:30 +00:00
Guido van Rossum 22a97159cd Clean up some docstrings. Some docstrings didn't show their return
value; others were inconsistent in what to name the argument or return
value; a few module-global functions had "socket." in front of their
name, against convention.
2002-08-08 20:37:08 +00:00
Tim Peters 5814187f5b internal_connect(): Windows. When sock_timeout > 0 and connect() yields
WSAEWOULDBLOCK, the second connect() attempt appears to yield WSAEISCONN
on Win98 but WSAEINVAL on Win2K.  So accept either as meaning "yawn,
fine".  This allows test_socket to succeed on my Win2K box (which it
already did on my Win98SE box).
2002-08-06 22:25:02 +00:00
Mark Hammond fe51c6d66e Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
for Py_Main().

Thanks to Kalle Svensson and Skip Montanaro for the patches.
2002-08-02 02:27:13 +00:00
Martin v. Löwis ddc6f4748e Pass length of result structure into setipaddr. Fixes bug #565747.
Committed to 2.2 branch.
2002-07-28 16:10:31 +00:00
Jeremy Hylton 825e47b655 Put checks for error returns in the right place. 2002-07-25 16:37:51 +00:00
Jeremy Hylton c075e197d6 Extended socket.htonl and ntohl to accept longs.
Fixes SF bug #568322.

The code should raise an OverflowError if the long is > 32 bits, even
on platforms where sizeof(long) > 4.
2002-07-25 16:01:12 +00:00
Mark Hammond 62b1ab1b31 Replace DL_IMPORT with PyMODINIT_FUNC and remove "/export:init..." link
command line for Windows builds.  This should allow MSVC to import and
build the Python MSVC6 project files without error.
2002-07-23 06:31:15 +00:00
Guido van Rossum ad65490628 Bail out early from internal_select() when socket file descriptor
closed.  Prevents core dump.
2002-07-19 12:44:59 +00:00
Tim Peters a12b4cfaa5 A Python float is a C double; redeclare defaulttimeout as such; stops
compiler wngs on Windows.
2002-07-18 22:38:44 +00:00
Guido van Rossum 1693ba8bf8 Silence warning about getdefaulttimeout in PyMethodDef. 2002-07-18 21:11:26 +00:00
Guido van Rossum 9d0c8cee66 Add default timeout functionality. This adds setdefaulttimeout() and
getdefaulttimeout() functions to the socket and _socket modules, and
appropriate tests.
2002-07-18 17:08:35 +00:00
Jeremy Hylton 938ace69a0 staticforward bites the dust.
The staticforward define was needed to support certain broken C
compilers (notably SCO ODT 3.0, perhaps early AIX as well) botched the
static keyword when it was used with a forward declaration of a static
initialized structure.  Standard C allows the forward declaration with
static, and we've decided to stop catering to broken C compilers.  (In
fact, we expect that the compilers are all fixed eight years later.)

I'm leaving staticforward and statichere defined in object.h as
static.  This is only for backwards compatibility with C extensions
that might still use it.

XXX I haven't updated the documentation.
2002-07-17 16:30:39 +00:00
Jack Jansen 84262fb1f3 Mac OS X Jaguar (developer preview) seems to have a working getaddrinfo(). 2002-07-02 14:40:42 +00:00
Martin v. Löwis 14f8b4cfcb Patch #568124: Add doc string macros. 2002-06-13 20:33:02 +00:00
Guido van Rossum 7b8bac106a Fix non-blocking connect() for Windows. Refactored the code
that retries the connect() call in timeout mode so it can be shared
between connect() and connect_ex(), and needs only a single #ifdef.

The test for this was doing funky stuff I don't approve of,
so I removed it in favor of a simpler test.  This allowed me
to implement a simpler, "purer" form of the timeout retry code.
Hopefully that's enough (if you want to be fancy, use non-blocking
mode and decode the errors yourself, like before).
2002-06-13 16:07:04 +00:00
Guido van Rossum 11ba094957 Major overhaul of timeout sockets:
- setblocking(0) and settimeout(0) are now equivalent, and ditto for
  setblocking(1) and settimeout(None).

- Don't raise an exception from internal_select(); let the final call
  report the error (this means you will get an EAGAIN error instead of
  an ETIMEDOUT error -- I don't care).

- Move the select to inside the Py_{BEGIN,END}_ALLOW_THREADS brackets,
  so other theads can run (this was a bug in the original code).

- Redid the retry logic in connect() and connect_ex() to avoid masking
  errors.  This probably doesn't work for Windows yet; I'll fix that
  next.  It may also fail on other platforms, depending on what
  retrying a connect does; I need help with this.

- Get rid of the retry logic in accept().  I don't think it was needed
  at all.  But I may be wrong.
2002-06-13 15:07:44 +00:00