[Python-Dev] socket.setsockopt() with optval=NULL (original) (raw)
Martin Panter vadmium+py at gmail.com
Sun Aug 21 23:45:01 EDT 2016
- Previous message (by thread): [Python-Dev] socket.setsockopt() with optval=NULL
- Next message (by thread): [Python-Dev] socket.setsockopt() with optval=NULL
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 21 August 2016 at 12:37, Christian Heimes <christian at python.org> wrote:
the socket.setsockopt(level, optname, value) method has two calling variants. When it is called with a buffer-like object as value, it calls the C API function setsockopt() with optval=buffer.buf and optlen=buffer.len. When value is an integer, setsockopt() packs it as int32 and sends it with optlen=4.
--- # example.py import socket sock = socket.socket(socket.AFINET, socket.SOCKSTREAM) sock.setsockopt(socket.SOLSOCKET, socket.SOREUSEADDR, b'\x00\x00\x00\x00') sock.setsockopt(socket.SOLSOCKET, socket.SOREUSEADDR, 1) --- $ strace -e setsockopt ./python example.py setsockopt(3, SOLSOCKET, SOREUSEADDR, [0], 4) = 0 setsockopt(3, SOLSOCKET, SOREUSEADDR, [1], 4) = 0
For AFALG (Linux Kernel crypto) I need a way to call the C API function setsockopt() with optval=NULL and optlen as any arbitrary number. I have been playing with multiple ideas. So far I liked the idea of value=(None, int) most. setsockopt(socket.SOLALG, socket.ALGSETAEADAUTHSIZE, (None, taglen))
Would this new functionality be open-ended? What would happen if you did
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, (None, 4))
On Linux, this seems to fail with errno = EFAULT, which would be fine. But this does not seem to be specified by Posix, and I imagine other platforms might crash. On the other hand, these sort of holes are already present in the socket module. E.g. with MSG_TRUNC <https://bugs.python.org/issue24933> you can apparently get Python to copy from unallocated memory.
- Previous message (by thread): [Python-Dev] socket.setsockopt() with optval=NULL
- Next message (by thread): [Python-Dev] socket.setsockopt() with optval=NULL
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]