summaryrefslogtreecommitdiffstats
path: root/Modules/socketmodule.c
Commit message (Collapse)AuthorAgeFilesLines
* bpo-36020: Remove snprintf macro in pyerrors.h (GH-20889)Victor Stinner2020-06-151-4/+3
| | | | | | | | | | On Windows, #include "pyerrors.h" no longer defines "snprintf" and "vsnprintf" macros. PyOS_snprintf() and PyOS_vsnprintf() should be used to get portable behavior. Replace snprintf() calls with PyOS_snprintf() and replace vsnprintf() calls with PyOS_vsnprintf().
* bpo-25920: Remove socket.getaddrinfo() lock on macOS (GH-20177)Victor Stinner2020-05-281-47/+2
| | | | | | | | | On macOS, socket.getaddrinfo() no longer uses an internal lock to prevent race conditions when calling getaddrinfo(). getaddrinfo is thread-safe is macOS 10.5, whereas Python 3.9 requires macOS 10.6 or newer. The lock was also used on FreeBSD older than 5.3, OpenBSD older than 201311 and NetBSD older than 4.
* bpo-37999: No longer use __int__ in implicit integer conversions. (GH-15636)Serhiy Storchaka2020-05-261-7/+0
| | | | Only __index__ should be used to make integer conversions lossless.
* bpo-40291: Add support for CAN_J1939 sockets (GH-19538)karl ding2020-04-291-0/+93
| | | | Add support for CAN_J1939 sockets that wrap SAE J1939 protocol functionality provided by Linux 5.4+ kernels.
* bpo-40268: Remove unused structmember.h includes (GH-19530)Victor Stinner2020-04-151-1/+1
| | | | | | If only offsetof() is needed: include stddef.h instead. When structmember.h is used, add a comment explaining that PyMemberDef is used.
* bpo-40268: Remove explicit pythread.h includes (#19529)Victor Stinner2020-04-151-6/+1
| | | | Remove explicit pythread.h includes: it is always included by Python.h.
* bpo-25780: Expose CAN_RAW_JOIN_FILTERS in the socket module (GH-19190)Zackery Spytz2020-04-091-0/+3
| | | Co-Authored-By: Stefan Tatschner <stefan@rumpelsepp.org>
* bpo-40121: Fixes audit event raised on creating a new socket (GH-19238)Steve Dower2020-03-311-3/+4
|
* closes bpo-39859: Do not downcast result of hstrerror (GH-18790)Andy Lester2020-03-061-1/+1
| | | | | set_herror builds a string by calling hstrerror but downcasts its return value to char *. It should be const char *. Automerge-Triggered-By: @benjaminp
* bpo-39573: Add Py_SET_TYPE() function (GH-18394)Victor Stinner2020-02-071-1/+1
| | | Add Py_SET_TYPE() function to set the type of an object.
* bpo-39573: Use Py_TYPE() macro in Modules directory (GH-18393)Victor Stinner2020-02-071-1/+1
| | | Replace direct access to PyObject.ob_type with Py_TYPE().
* bpo-38282: Rewrite getsockaddrarg() helper function (GH-16698)Victor Stinner2019-10-101-39/+22
| | | | | | | | Rewrite getsockaddrarg() helper function of socketmodule.c (_socket module) to prevent a false alarm when compiling codde using GCC with _FORTIFY_SOURCE=2. Pass a pointer of the sock_addr_t union, rather than passing a pointer to a sockaddr structure. Add "struct sockaddr_tipc tipc;" to the sock_addr_t union.
* closes bpo-37405: Make socket.getsockname() always return a tuple for ↵bggardner2019-09-121-1/+1
| | | | | AF_CAN. (GH-14392) This fixes a regression from 3.5. In recent releases, `getsockname()` in the AF_CAN case has returned a string.
* bpo-15999: Always pass bool instead of int to socket.setblocking(). (GH-15621)Serhiy Storchaka2019-09-011-1/+1
|
* Unmark files as executable that can't actually be executed. (GH-15353)Greg Price2019-08-211-0/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | There are plenty of legitimate scripts in the tree that begin with a `#!`, but also a few that seem to be marked executable by mistake. Found them with this command -- it gets executable files known to Git, filters to the ones that don't start with a `#!`, and then unmarks them as executable: $ git ls-files --stage \ | perl -lane 'print $F[3] if (!/^100644/)' \ | while read f; do head -c2 "$f" | grep -qxF '#!' \ || chmod a-x "$f"; \ done Looking at the list by hand confirms that we didn't sweep up any files that should have the executable bit after all. In particular * The `.psd` files are images from Photoshop. * The `.bat` files sure look like things that can be run. But we have lots of other `.bat` files, and they don't have this bit set, so it must not be needed for them. Automerge-Triggered-By: @benjaminp
* bpo-37811: FreeBSD, OSX: fix poll(2) usage in sockets module (GH-15202)Artem Khramov2019-08-141-0/+11
| | | | | | | | | | | | | | | | FreeBSD implementation of poll(2) restricts the timeout argument to be either zero, or positive, or equal to INFTIM (-1). Unless otherwise overridden, socket timeout defaults to -1. This value is then converted to milliseconds (-1000) and used as argument to the poll syscall. poll returns EINVAL (22), and the connection fails. This bug was discovered during the EINTR handling testing, and the reproduction code can be found in https://bugs.python.org/issue23618 (see connect_eintr.py, attached). On GNU/Linux, the example runs as expected. This change is trivial: If the supplied timeout value is negative, truncate it to -1.
* bpo-36590: Add Bluetooth RFCOMM and support for Windows. (GH-12767)Greg Bowser2019-08-021-6/+59
| | | | | | | | | | | Support for RFCOMM, L2CAP, HCI, SCO is based on the BTPROTO_* macros being defined. Winsock only supports RFCOMM, even though it has a BTHPROTO_L2CAP macro. L2CAP support would build on windows, but not necessarily work. This also adds some basic unittests for constants (all of which existed prior to this commit, just not on windows) and creating sockets. pair: Nate Duarte <slacknate@gmail.com>
* bpo-37085: Expose SocketCAN bcm_msg_head flags (#13646)karl ding2019-07-311-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | Expose the CAN_BCM SocketCAN constants used in the bcm_msg_head struct flags (provided by <linux/can/bcm.h>) under the socket library. This adds the following constants with a CAN_BCM prefix: * SETTIMER * STARTTIMER * TX_COUNTEVT * TX_ANNOUNCE * TX_CP_CAN_ID * RX_FILTER_ID * RX_CHECK_DLC * RX_NO_AUTOTIMER * RX_ANNOUNCE_RESUME * TX_RESET_MULTI_IDX * RX_RTR_FRAME * CAN_FD_FRAME The CAN_FD_FRAME flag was introduced in the 4.8 kernel, while the other ones were present since SocketCAN drivers were mainlined in 2.6.25. As such, it is probably unnecessary to guard against these constants being missing.
* bpo-37345: Add formal UDPLITE support (GH-14258)Gabe Appleton2019-06-241-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | At the moment you can definitely use UDPLITE sockets on Linux systems, but it would be good if this support were formalized such that you can detect support at runtime easily. At the moment, to make and use a UDPLITE socket requires something like the following code: ``` >>> import socket >>> a = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 136) >>> b = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 136) >>> a.bind(('localhost', 44444)) >>> b.sendto(b'test'*256, ('localhost', 44444)) >>> b.setsockopt(136, 10, 16) >>> b.sendto(b'test'*256, ('localhost', 44444)) >>> b.setsockopt(136, 10, 32) >>> b.sendto(b'test'*256, ('localhost', 44444)) >>> b.setsockopt(136, 10, 64) >>> b.sendto(b'test'*256, ('localhost', 44444)) ``` If you look at this through Wireshark, you can see that the packets are different in that the checksums and checksum coverages change. With the pull request that I am submitting momentarily, you could do the following code instead: ``` >>> import socket >>> a = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDPLITE) >>> b = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDPLITE) >>> a.bind(('localhost', 44444)) >>> b.sendto(b'test'*256, ('localhost', 44444)) >>> b.set_send_checksum_coverage(16) >>> b.sendto(b'test'*256, ('localhost', 44444)) >>> b.set_send_checksum_coverage(32) >>> b.sendto(b'test'*256, ('localhost', 44444)) >>> b.set_send_checksum_coverage(64) >>> b.sendto(b'test'*256, ('localhost', 44444)) ``` One can also detect support for UDPLITE just by checking ``` >>> hasattr(socket, 'IPPROTO_UDPLITE') ``` https://bugs.python.org/issue37345
* bpo-36974: tp_print -> tp_vectorcall_offset and tp_reserved -> tp_as_async ↵Jeroen Demeyer2019-05-311-2/+2
| | | | | | | | | (GH-13464) Automatically replace tp_print -> tp_vectorcall_offset tp_compare -> tp_as_async tp_reserved -> tp_as_async
* bpo-37007: Implement socket.if_nametoindex(), if_indextoname() and ↵Zackery Spytz2019-05-291-11/+49
| | | | if_nameindex() on Windows (GH-13522)
* bpo-32388: Remove cross-version binary compatibility requirement in tp_flags ↵Antoine Pitrou2019-05-291-2/+1
| | | | | | | | (GH-4944) It is now allowed to add new fields at the end of the PyTypeObject struct without having to allocate a dedicated compatibility flag in tp_flags. This will reduce the risk of running out of bits in the 32-bit tp_flags value.
* bpo-36842: Implement PEP 578 (GH-12613)Steve Dower2019-05-231-0/+80
| | | Adds sys.audit, sys.addaudithook, io.open_code, and associated C APIs.
* bpo-29515: add missing socket.IPPROTO_* constants on Windows (GH-12183)Giampaolo Rodola2019-03-281-1/+46
|
* bpo-8677: use PY_SSIZE_T_CLEAN in socketmodule.c (GH-12467)Inada Naoki2019-03-201-1/+2
|
* bpo-36254: Fix invalid uses of %d in format strings in C. (GH-12264)Serhiy Storchaka2019-03-131-2/+2
|
* bpo-35550: Fix incorrect Solaris define guards (GH-11275)Jakub Kulík2018-12-311-1/+1
| | | | | | | Python source code uses on several places ifdef sun or defined(sun) without the underscores, which is not standard compliant and shouldn't be used. Defines should check for __sun instead. Reference: http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system#Solaris https://bugs.python.org/issue35550
* bpo-35214: MSan workarounds for socket, time, and test_faulthandler. (GH-11375)Gregory P. Smith2018-12-311-0/+20
| | | | | Add Clang Memory Sanitizer build instrumentation to work around false positives from the socket and time modules as well as skipping a couple test_faulthandler tests.
* bpo-35415: validate fileno argument to socket.socket (GH-10917)Dima Tisnek2018-12-171-20/+29
| | | https://bugs.python.org/issue35415
* bpo-35454: Fix miscellaneous minor issues in error handling. (#11077)Serhiy Storchaka2018-12-111-4/+8
| | | | | | * bpo-35454: Fix miscellaneous minor issues in error handling. * Fix a null pointer dereference.
* bpo-35050: AF_ALG length check off-by-one error (GH-10058)Christian Heimes2018-12-101-3/+5
| | | | | | | | The length check for AF_ALG salg_name and salg_type had a off-by-one error. The code assumed that both values are not necessarily NULL terminated. However the Kernel code for alg_bind() ensures that the last byte of both strings are NULL terminated. Signed-off-by: Christian Heimes <christian@python.org>
* bpo-33012: Fix invalid function cast warnings with gcc 8. (GH-6749)Serhiy Storchaka2018-11-271-4/+4
| | | | | | Fix invalid function cast warnings with gcc 8 for method conventions different from METH_NOARGS, METH_O and METH_VARARGS excluding Argument Clinic generated code.
* Fix a possible reference leak in _socket.getaddrinfo(). (GH-10543)Zackery Spytz2018-11-141-2/+4
| | | "single" needs to be decrefed if PyList_Append() fails.
* bpo-31425: Expose AF_QIPCRTR in socket module (GH-3706)Bjorn Andersson2018-09-261-2/+49
| | | | | | The AF_QIPCRTR address family was introduced in Linux v4.7. Co-authored-by: Bjorn Andersson <bjorn.andersson@linaro.org>
* closes bpo-25041: Document AF_PACKET socket address format. (GH-4092)Cheryl Sabella2018-09-121-3/+3
|
* closes bpo-29832: Remove "getsockaddrarg" from error messages. (GH-3163)Oren Milman2018-09-111-60/+119
|
* closes bpo-34581 : Conditionalize use of __pragma in Modules/socketmodule.c. ↵Erik Janssens2018-09-051-2/+5
| | | | | | (GH-9067)
* bpo-34217: Use lowercase for windows headers (GH-8472)Erik Janssens2018-08-161-1/+1
|
* bpo-33012: Fix invalid function cast warnings with gcc 8 for METH_NOARGS. ↵Siddhesh Poyarekar2018-04-291-10/+10
| | | | | | | | | (GH-6030) METH_NOARGS functions need only a single argument but they are cast into a PyCFunction, which takes two arguments. This triggers an invalid function cast warning in gcc8 due to the argument mismatch. Fix this by adding a dummy unused argument.
* bpo-32394: Remove some TCP options on old version Windows. (GH-5523)animalize2018-02-261-0/+70
|
* bpo-32221: makeipaddr(): remove interface part + speedup (GH-5449) (#5449)Коренберг Марк2018-02-121-28/+31
|
* Fix some warnings produced by different compilers. (#5593)Serhiy Storchaka2018-02-091-2/+6
|
* bpo-32746: Fix multiple typos (GH-5144)Leo Arias2018-02-041-1/+1
| | | Fix typos found by codespell in docs, docstrings, and comments.
* bpo-32747: Remove trailing spaces in docstrings. (GH-5491)oldk2018-02-021-7/+7
|
* bpo-28134: Auto-detect socket values from file descriptor (#1349)Christian Heimes2018-01-291-2/+69
| | | | | | | | | | | | | | | Fix socket(fileno=fd) by auto-detecting the socket's family, type, and proto from the file descriptor. The auto-detection can be overruled by passing in family, type, and proto explicitly. Without the fix, all socket except for TCP/IP over IPv4 are basically broken: >>> s = socket.create_connection(('www.python.org', 443)) >>> s <socket.socket fd=3, family=AddressFamily.AF_INET6, type=SocketKind.SOCK_STREAM, proto=6, laddr=('2003:58:bc4a:3b00:56ee:75ff:fe47:ca7b', 59730, 0, 0), raddr=('2a04:4e42:1b::223', 443, 0, 0)> >>> socket.socket(fileno=s.fileno()) <socket.socket fd=3, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('2003:58:bc4a:3b00::%2550471192', 59730, 0, 2550471192), raddr=('2a04:4e42:1b:0:700c:e70b:ff7f:0%2550471192', 443, 0, 2550471192)> Signed-off-by: Christian Heimes <christian@python.org>
* bpo-32373: Add socket.getblocking() method. (#4926)Yury Selivanov2018-01-281-1/+48
|
* Revert "bpo-32221: makeipaddr(): remove interface part + speedup (GH-4724)" ↵Yury Selivanov2018-01-281-31/+28
| | | | | (#5394) This reverts commit 47c0b1f7d4115e6f15e6776c1f91d28e7d96fe0c.
* bpo-32221: makeipaddr(): remove interface part + speedup (GH-4724)Коренберг Марк2018-01-271-28/+31
|
* bpo-32454: socket closefd (#5048)Christian Heimes2018-01-271-2/+29
| | | | | Add close(fd) function to the socket module Signed-off-by: Christian Heimes <christian@python.org>
* bpo-32282: Remove unnecessary check for `VersionHelpers.h` in ↵Max Bélanger2018-01-071-10/+0
| | | | `socketmodule.c` on Windows