[Python-Dev] socket.setsockopt() with optval=NULL (original) (raw)

Benjamin Peterson benjamin at python.org
Tue Aug 23 00:41:42 EDT 2016


Another option would be add a setalg method with whatever (nice, pythonic) API we want. Emulating the crummy C-level API needn't be a goal I think.

On Sun, Aug 21, 2016, at 05:37, Christian Heimes wrote:

Hi,

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)) What do you think? Christian


Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/benjamin%40python.org



More information about the Python-Dev mailing list