summaryrefslogtreecommitdiffstats
path: root/Modules/socketmodule.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-63760: Don't declare gethostname() on Solaris (#108817)Victor Stinner2023-09-021-5/+0
| | | | | | | | | | | | | Since 2005, Solaris defines gethostname(). socketmodule.c no longer has to define gethostname() for Solaris. Oracle Solaris and OpenSolaris have patches to remove the gethostname() definition in Python: * https://github.com/oracle/solaris-userland/blob/master/components/python/python37/patches/15-gethostname.patch * https://github.com/OpenIndiana/oi-userland/blob/oi/hipster/components/python/python37/patches/15-gethostname.patch * https://github.com/omniosorg/omnios-build/blob/master/build/python27/patches/24-gethostname.patch Co-authored-by: Jakub Kulík <Kulikjak@gmail.com>
* gh-108765: Python.h no longer includes <unistd.h> (#108783)Victor Stinner2023-09-021-1/+1
|
* gh-108765: Remove old prototypes from pyport.h (#108782)Victor Stinner2023-09-021-1/+5
| | | | | | | Move prototypes of gethostname(), _getpty() and struct termios from pyport.h to the C code using them: posixmodule.c, socketmodule.c and termios.c. Replace "#ifdef SOLARIS" with "#ifdef __sun".
* gh-108240: Add pycore_capsule.h internal header file (#108596)Victor Stinner2023-08-291-0/+1
| | | | Move _PyCapsule_SetTraverse() definition to a new internal header file: pycore_capsule.h.
* gh-107913: Fix possible losses of OSError error codes (GH-107930)Serhiy Storchaka2023-08-261-5/+7
| | | | | | Functions like PyErr_SetFromErrno() and SetFromWindowsErr() should be called immediately after using the C API which sets errno or the Windows error code.
* gh-108444: Replace _PyLong_AsInt() with PyLong_AsInt() (#108459)Victor Stinner2023-08-241-4/+4
| | | | | | Change generated by the command: sed -i -e 's!_PyLong_AsInt!PyLong_AsInt!g' \ $(find -name "*.c" -o -name "*.h")
* gh-106320: Remove private _PyDict functions (#108449)Victor Stinner2023-08-241-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Move private functions to the internal C API (pycore_dict.h): * _PyDictView_Intersect() * _PyDictView_New() * _PyDict_ContainsId() * _PyDict_DelItemId() * _PyDict_DelItem_KnownHash() * _PyDict_GetItemIdWithError() * _PyDict_GetItem_KnownHash() * _PyDict_HasSplitTable() * _PyDict_NewPresized() * _PyDict_Next() * _PyDict_Pop() * _PyDict_SetItemId() * _PyDict_SetItem_KnownHash() * _PyDict_SizeOf() No longer export most of these functions. Move also the _PyDictViewObject structure to the internal C API. Move dict_getitem_knownhash() function from _testcapi to the _testinternalcapi extension. Update test_capi.test_dict for this change.
* gh-108240: Add _PyCapsule_SetTraverse() internal function (#108339)Victor Stinner2023-08-231-6/+31
| | | | | The _socket extension uses _PyCapsule_SetTraverse() to visit and clear the socket type in the garbage collector. So the _socket.socket type can be cleared in some corner cases when it wasn't possible before.
* gh-104432: Use `memcpy()` to avoid misaligned loads (#104433)Christopher Chavez2023-07-271-5/+17
| | | | | Fix potential unaligned memory access on C APIs involving returned sequences of `char *` pointers within the :mod:`grp` and :mod:`socket` modules. These were revealed using a ``-fsaniziter=alignment`` build on ARM macOS.
* gh-106869: Use new PyMemberDef constant names (#106871)Victor Stinner2023-07-251-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Remove '#include "structmember.h"'. * If needed, add <stddef.h> to get offsetof() function. * Update Parser/asdl_c.py to regenerate Python/Python-ast.c. * Replace: * T_SHORT => Py_T_SHORT * T_INT => Py_T_INT * T_LONG => Py_T_LONG * T_FLOAT => Py_T_FLOAT * T_DOUBLE => Py_T_DOUBLE * T_STRING => Py_T_STRING * T_OBJECT => _Py_T_OBJECT * T_CHAR => Py_T_CHAR * T_BYTE => Py_T_BYTE * T_UBYTE => Py_T_UBYTE * T_USHORT => Py_T_USHORT * T_UINT => Py_T_UINT * T_ULONG => Py_T_ULONG * T_STRING_INPLACE => Py_T_STRING_INPLACE * T_BOOL => Py_T_BOOL * T_OBJECT_EX => Py_T_OBJECT_EX * T_LONGLONG => Py_T_LONGLONG * T_ULONGLONG => Py_T_ULONGLONG * T_PYSSIZET => Py_T_PYSSIZET * T_NONE => _Py_T_NONE * READONLY => Py_READONLY * PY_AUDIT_READ => Py_AUDIT_READ * READ_RESTRICTED => Py_AUDIT_READ * PY_WRITE_RESTRICTED => _Py_WRITE_RESTRICTED * RESTRICTED => (READ_RESTRICTED | _Py_WRITE_RESTRICTED)
* gh-86493: Use PyModule_Add() instead of PyModule_AddObjectRef() (GH-106860)Serhiy Storchaka2023-07-181-10/+2
|
* gh-104922: remove PY_SSIZE_T_CLEAN (#106315)Inada Naoki2023-07-021-1/+0
|
* gh-92536: Remove PyUnicode_READY() calls (#105210)Victor Stinner2023-06-011-3/+0
| | | | Since Python 3.12, PyUnicode_READY() does nothing and always returns 0.
* gh-98836: Extend PyUnicode_FromFormat() (GH-98838)Serhiy Storchaka2023-05-211-6/+2
| | | | | | | | | * Support for conversion specifiers o (octal) and X (uppercase hexadecimal). * Support for length modifiers j (intmax_t) and t (ptrdiff_t). * Length modifiers are now applied to all integer conversions. * Support for wchar_t C strings (%ls and %lV). * Support for variable width and precision (*). * Support for flag - (left alignment).
* GH-104308: socket.getnameinfo should release the GIL (#104307)Nathaniel J. Smith2023-05-081-0/+2
| | | | | | | | | * socket.getnameinfo should release the GIL * 📜🤖 Added by blurb_it. --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
* gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205)Eric Snow2023-05-051-0/+1
| | | Here we are doing no more than adding the value for Py_mod_multiple_interpreters and using it for stdlib modules. We will start checking for it in gh-104206 (once PyInterpreterState.ceval.own_gil is added in gh-104204).
* gh-96534: socketmodule: support FreeBSD divert(4) socket (#96536)Gleb Smirnoff2023-05-041-0/+13
|
* gh-89415: Add source-specific multicast constants to socket module (#103684)Reese Hyde2023-04-271-0/+12
| | | | | Add socket options for source-specific multicast when present as C #defines. Co-authored-by: Oleg Iarygin <dralife@yandex.ru>
* gh-103092: Isolate `socket` module (#103094)Erlend E. Aasland2023-04-091-161/+233
|
* gh-83004: Harden _socket init (GH-103261)Erlend E. Aasland2023-04-071-537/+581
| | | Automerge-Triggered-By: GH:erlend-aasland
* Add IPv6 into to the docstring for socket.getsockname (#102961)Brian Haley2023-03-301-1/+2
| | | Signed-off-by: Brian Haley <haleyb.dev@gmail.com>
* gh-102255: Use GetVersionEx instead of GetVersionExW to match argument type ↵Max Bachmann2023-03-201-1/+1
| | | | | | (GH-102583) Since we pass a structure of type `OSVERSIONINFOEX`, we need to call `GetVersionEx` instead of `GetVersionExW`.
* gh-102255: Improve build support for Windows API partitions (GH-102256)Max Bachmann2023-03-091-21/+39
| | | | | Add `MS_WINDOWS_DESKTOP`, `MS_WINDOWS_APPS`, `MS_WINDOWS_SYSTEM` and `MS_WINDOWS_GAMES` preprocessor definitions to allow switching off functionality missing from particular API partitions ("partitions" are used in Windows to identify overlapping subsets of APIs). CPython only officially supports `MS_WINDOWS_DESKTOP` and `MS_WINDOWS_SYSTEM` (APPS is included by normal desktop builds, but APPS without DESKTOP is not covered). Other configurations are a convenience for people building their own runtimes. `MS_WINDOWS_GAMES` is for the Xbox subset of the Windows API, which is also available on client OS, but is restricted compared to `MS_WINDOWS_DESKTOP`. These restrictions may change over time, as they relate to the build headers rather than the OS support, and so we assume that Xbox builds will use the latest available version of the GDK.
* gh-102336: Remove code specifically for handling Windows 7 (GH-102337)Max Bachmann2023-03-011-32/+10
|
* gh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives ↵Irit Katriel2023-02-241-3/+2
| | | | (in Modules/) (#102196)
* gh-74895: getaddrinfo no longer raises OverflowError (#2435)Radek Smejkal2023-02-141-5/+9
| | | `socket.getaddrinfo()` no longer raises `OverflowError` based on the **port** argument. Error reporting (or not) for its value is left up to the underlying C library `getaddrinfo()` implementation.
* gh-100795: Don't call freeaddrinfo on failure. (#101252)Gregory P. Smith2023-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. Co-authored-by: Sergey G. Brester <github@sebres.de> Co-authored-by: Oleg Iarygin <dralife@yandex.ru>
* Revert "gh-100795: avoid unexpected `freeaddrinfo` after failed ↵Kumar Aditya2023-01-221-2/+0
| | | | | | | `getaddrinfo` (#101220)" (#101238) Revert "gh-100795: avoid unexpected `freeaddrinfo` after failed `getaddrinfo` (#101220)" This reverts commit 5f08fe4a2c055880c23c6f9b57ff03005d193bfc.
* gh-100795: avoid unexpected `freeaddrinfo` after failed `getaddrinfo` (#101220)Sergey G. Brester2023-01-221-0/+2
| | | Co-authored-by: Oleg Iarygin <dralife@yandex.ru>
* GH-100813: Add `socket.IP_PKTINFO` constant (#10294)dsentinel2023-01-091-0/+3
|
* gh-98030: socket: add missing TCP socket options (#98031)Matthieu Baerts2022-12-081-3/+63
| | | | | | | | | | | | | A few TCP socket options have been added to the Linux kernel these last few years. This commit adds all the ones available in Linux 6.0: https://elixir.bootlin.com/linux/v6.0/source/include/uapi/linux/tcp.h#L91 While at it, the TCP_FASTOPEN option has been moved lower in the list just to keep the same order as in tcp.h to ease future synchronisations. Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
* bpo-15999: Accept arbitrary values for boolean parameters. (#15609)Serhiy Storchaka2022-12-031-2/+2
| | | builtins and extension module functions and methods that expect boolean values for parameters now accept any Python object rather than just a bool or int type. This is more consistent with how native Python code itself behaves.
* gh-99300: Use Py_NewRef() in Modules/ directory (#99469)Victor Stinner2022-11-141-18/+8
| | | | Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in test C files of the Modules/ directory.
* gh-95389: expose popular ETHERTYPE_* constants in the socket module (#95390)Noam Cohen2022-11-071-0/+23
| | | | Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com> Co-authored-by: CAM Gerlach <CAM.Gerlach@Gerlach.CAM>
* gh-95174: WASI: skip missing sockets functions (GH-95179)Christian Heimes2022-07-271-10/+103
|
* gh-95174: Handle missing dup() and constants in WASI (GH-95229)Christian Heimes2022-07-261-0/+4
| | | | | | | - check for ``dup()`` libc function - handle missing ``F_DUPFD`` in ``dup2()`` replacement function - add workaround for WASI libc bug in MSG_TRUNC - ESHUTDOWN is missing, use EPIPE instead - POLLPRI is missing, define as 0 (no-op)
* gh-94821: Fix autobind of empty unix domain address (GH-94826)Nir Soffer2022-07-151-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)
* gh-94068: Remove HVSOCKET_CONTAINER_PASSTHRU constant because it has been ↵Steve Dower2022-06-211-1/+0
| | | | | | | removed from Windows (GH-94069) Fixes #94068 Automerge-Triggered-By: GH:zware
* gh-84461: Silence some compiler warnings on WASM (GH-93978)Christian Heimes2022-06-201-0/+2
|
* gh-92658: AF_HYPERV is only supported on Windows (#93192)Victor Stinner2022-05-251-7/+7
| | | | | Only build the AF_HYPERV support on Windows for the _socket extension. FreeBSD defines the AF_HYPERV macro but doesn't have the SOCKADDR_HV type.
* gh-92658: Add Hyper-V socket support (GH-92755)Jordan Borean2022-05-241-0/+131
|
* gh-91968: Add socket constants SO_USER_COOKIE/SO_RTABLE from BSD (#91967)David CARLIER2022-05-081-0/+6
| | | | | Those are somewhat equivalent to Linux' SO_MARK. Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* 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
|