A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2016-August/145872.html below:

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

[Python-Dev] socket.setsockopt() with optval=NULLChristian Heimes christian at python.org
Sun Aug 21 08:37:51 EDT 2016
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
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4