(original) (raw)

Wouldn't

setsockopt(socket.SOL\_ALG, socket.ALG\_SET\_AEAD\_AUTHSIZE, None, taglen)

be more consistent?

--Guido (mobile)


On Aug 21, 2016 5:40 AM, "Christian Heimes" <christian@python.org> 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.AF\_INET, socket.SOCK\_STREAM)
sock.setsockopt(socket.SOL\_SOCKET, socket.SO\_REUSEADDR,
b'\\x00\\x00\\x00\\x00')
sock.setsockopt(socket.SOL\_SOCKET, socket.SO\_REUSEADDR, 1)
\---

$ strace -e setsockopt ./python example.py
setsockopt(3, SOL\_SOCKET, SO\_REUSEADDR, \[0\], 4) = 0
setsockopt(3, SOL\_SOCKET, SO\_REUSEADDR, \[1\], 4) = 0


For AF\_ALG (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.SOL\_ALG, socket.ALG\_SET\_AEAD\_AUTHSIZE, (None, taglen))

What do you think?

Christian
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/guido%40python.org