summaryrefslogtreecommitdiffstats
path: root/Modules/socketmodule.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-100795: Don't call freeaddrinfo on failure. (GH-101252)Miss Islington (bot)2023-01-231-0/+4
| | | | | | | | | | | | When getaddrinfo returns an error, the output pointer is in an unknown state Don't call freeaddrinfo on it. See the issue for discussion and details with links to reasoning. _Most_ libc getaddrinfo implementations never modify the output pointer unless they are returning success. (cherry picked from commit b724ac2fe7fbb5a7a33d639cad8e748f17b325e0) Co-authored-by: Gregory P. Smith <greg@krypto.org> Co-authored-by: Sergey G. Brester <github@sebres.de> Co-authored-by: Oleg Iarygin <dralife@yandex.ru>
* [3.11] gh-95174: WASI: skip missing sockets functions (GH-95179) (GH-95308)Christian Heimes2022-07-311-10/+103
| | | | Co-authored-by: Christian Heimes <christian@python.org> Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* [3.11] gh-95174: Handle missing dup() and constants in WASI (GH-95229) ↵Christian Heimes2022-07-311-0/+4
| | | | | (GH-95272) Co-authored-by: Christian Heimes <christian@python.org>
* gh-94821: Fix autobind of empty unix domain address (GH-94826)Miss Islington (bot)2022-07-171-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When binding a unix socket to an empty address on Linux, the socket is automatically bound to an available address in the abstract namespace. >>> s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) >>> s.bind("") >>> s.getsockname() b'\x0075499' Since python 3.9, the socket is bound to the one address: >>> s.getsockname() b'\x00' And trying to bind multiple sockets will fail with: Traceback (most recent call last): File "/home/nsoffer/src/cpython/Lib/test/test_socket.py", line 5553, in testAutobind s2.bind("") OSError: [Errno 98] Address already in use Added 2 tests: - Auto binding empty address on Linux - Failing to bind an empty address on other platforms Fixes f6b3a07b7df6 (bpo-44493: Add missing terminated NUL in sockaddr_un's length (GH-26866) (cherry picked from commit c22f134211743cd5ad14cec1dd4f527bee542b4c) Co-authored-by: Nir Soffer <nsoffer@redhat.com>
* gh-84461: Silence some compiler warnings on WASM (GH-93978)Miss Islington (bot)2022-06-201-0/+2
| | | | | (cherry picked from commit 774ef28814d0d9d57ec813cb31b0a7af6c476127) Co-authored-by: Christian Heimes <christian@python.org>
* gh-92210: Move socket.__init__ to argument clinic (#92237)Joshua Herman2022-05-041-14/+26
| | | | | | Co-authored-by: Łukasz Langa <lukasz@langa.pl> Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no> Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@protonmail.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* gh-91320: Use _PyCFunction_CAST() (#92251)Victor Stinner2022-05-031-4/+4
| | | | | | | | | | Replace "(PyCFunction)(void(*)(void))func" cast with _PyCFunction_CAST(func). Change generated by the command: sed -i -e \ 's!(PyCFunction)(void(\*)(void)) *\([A-Za-z0-9_]\+\)!_PyCFunction_CAST(\1)!g' \ $(find -name "*.c")
* bpo-46696: Add socket.SO_INCOMING_CPU constant (#31237)David CARLIER2022-05-031-0/+3
| | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* gh-91498: socket: Add TCP_CONNECTION_INFO on macOS (#69256)David CARLIER2022-04-271-0/+3
| | | Fixes GH-91498
* bpo-44493: Add missing terminated NUL in sockaddr_un's length (GH-26866)ty2022-03-271-1/+6
| | | | | | | Add missing terminated NUL in sockaddr_un's length - Linux: https://man7.org/linux/man-pages/man7/unix.7.html - *BSD: SUN_LEN
* bpo-46030: socket module add couple of FreeBSD constants. (GH-30018)David CARLIER2022-03-171-0/+9
| | | Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
* bpo-40280: Disable AF_UNIX, AF_PACKET, SO_REUSE* on Emscripten (#31829)Christian Heimes2022-03-111-1/+1
| | | Emscripten's socket emulation is limited. AF_UNIX, AF_PACKET, setsockopt(), and most SO_* constants are not supported.
* closes bpo-46626: Expose IP_BIND_ADDRESS_NO_PORT socket option. (GH-31106)Benjamin Peterson2022-02-031-0/+3
|
* bpo-30512: Add CAN Socket support for NetBSD (GH-30066)Thomas Klausner2022-01-211-2/+4
|
* bpo-40280: Add --with-emscripten-target to build for browser or node (GH-30552)Christian Heimes2022-01-121-1/+1
| | | Co-authored-by: Ethan Smith <ethan@ethanhs.me>
* bpo-46303: Move fileutils.h private functions to internal C API (GH-30484)Victor Stinner2022-01-111-0/+5
| | | | | | | | | | Move almost all private functions of Include/cpython/fileutils.h to the internal C API Include/internal/pycore_fileutils.h. Only keep _Py_fopen_obj() in Include/cpython/fileutils.h, since it's used by _testcapi which must not use the internal C API. Move EncodeLocaleEx() and DecodeLocaleEx() functions from _testcapi to _testinternalcapi, since the C API moved to the internal C API.
* bpo-40280: Add configure check for socket shutdown (GH-29795)Christian Heimes2021-11-261-0/+4
|
* bpo-45743: Move __APPLE_USE_RFC_3542 into socketmodule.c (GH-29456)Christian Heimes2021-11-081-0/+2
|
* Fix typos in the Modules directory (GH-28761)Christian Clauss2021-10-071-1/+1
|
* bpo-41710: Add private _PyDeadline_Get() function (GH-28674)Victor Stinner2021-10-011-9/+11
| | | | | | | | Add a private C API for deadlines: add _PyDeadline_Init() and _PyDeadline_Get() functions. * Add _PyTime_Add() and _PyTime_Mul() functions which compute t1+t2 and t1*t2 and clamp the result on overflow. * _PyTime_MulDiv() now uses _PyTime_Add() and _PyTime_Mul().
* bpo-41710: Add _PyTime_AsTimespec_clamp() (GH-28629)Victor Stinner2021-09-301-1/+1
| | | | | | | | | | | | | | | Add the _PyTime_AsTimespec_clamp() function: similar to _PyTime_AsTimespec(), but clamp to _PyTime_t min/max and don't raise an exception. PyThread_acquire_lock_timed() now uses _PyTime_AsTimespec_clamp() to remove the Py_UNREACHABLE() code path. * Add _PyTime_AsTime_t() function. * Add PY_TIME_T_MIN and PY_TIME_T_MAX constants. * Replace _PyTime_AsTimeval_noraise() with _PyTime_AsTimeval_clamp(). * Add pytime_divide_round_up() function. * Fix integer overflow in pytime_divide(). * Add pytime_divmod() function.
* bpo-45228: Fix stack buffer overflow in parsing J1939 address (GH-28404)Serhiy Storchaka2021-09-171-8/+8
|
* Remove documentation for non-existing socket class attributes (GH-28029)Matti Picus2021-09-071-3/+0
| | | The functions in question are available on the module-level only.
* bpo-44740: Lowercase "internet" and "web" where appropriate. (#27378)Mariusz Felisiak2021-07-261-1/+1
| | | Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* bpo-34932: Add socket.TCP_KEEPALIVE for macOS (GH-25079)Shane Harvey2021-07-141-0/+4
|
* bpo-44077: Expose IP_RECVTOS in the socket module (GH-25992)Georg Sauthoff2021-06-201-0/+3
| | | Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* bpo-26227: Fixes decoding of host names on Windows from ANSI instead of ↵Steve Dower2021-04-211-1/+1
| | | | UTF-8 (GH-25510)
* bpo-43571: Add IPPROTO_MPTCP macro (GH-24946)Rui Cunha2021-03-201-0/+3
| | | Add IPPROTO_MPTCP constant when defined in the system headers.
* bpo-41798: Allocate _socket module C API on the heap (GH-24126)Erlend Egeberg Aasland2021-01-061-15/+45
|
* bpo-42393: Raise OverflowError iso. DeprecationWarning on overflow in ↵Erlend Egeberg Aasland2020-12-311-26/+10
| | | | socket.ntohs and socket.htons (GH-23980)
* bpo-42620: Improve socket.getsockname doc string (GH-23742)Christian Heimes2020-12-231-2/+3
| | | Signed-off-by: Christian Heimes <christian@python.org>
* bpo-42413: socket.timeout is now an alias of TimeoutError (GH-23413)Christian Heimes2020-11-201-11/+7
| | | Signed-off-by: Christian Heimes <christian@python.org>
* bpo-42006: Stop using PyDict_GetItem, PyDict_GetItemString and ↵Serhiy Storchaka2020-10-261-13/+16
| | | | | | | | | | | _PyDict_GetItemId. (GH-22648) These functions are considered not safe because they suppress all internal errors and can return wrong result. PyDict_GetItemString and _PyDict_GetItemId can also silence current exception in rare cases. Remove no longer used _PyDict_GetItemId. Add _PyDict_ContainsId and rename _PyDict_Contains into _PyDict_Contains_KnownHash.
* 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>