From 5ffc22689058b4f14cd9a8bb17bed71aa051021d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 15 Dec 2016 08:38:48 -0500 Subject: _daemon: allow specifying flowinfo Not particularly useful, but let's have it for completeness. --- systemd/_daemon.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/systemd/_daemon.c b/systemd/_daemon.c index f122722..90cf205 100644 --- a/systemd/_daemon.c +++ b/systemd/_daemon.c @@ -319,7 +319,7 @@ static PyObject* is_socket_inet(PyObject *self, PyObject *args) { #ifdef HAVE_IS_SOCKET_SOCKADDR PyDoc_STRVAR(is_socket_sockaddr__doc__, - "_is_socket_sockaddr(fd, address, type=0, listening=-1) -> bool\n\n" + "_is_socket_sockaddr(fd, address, type=0, flowinfo=0, listening=-1) -> bool\n\n" "Wraps sd_is_socket_inet_sockaddr(3).\n" "`address` is a systemd-style numerical IPv4 or IPv6 address as used in\n" "ListenStream=. A port may be included after a colon (\":\"). See\n" @@ -329,15 +329,17 @@ PyDoc_STRVAR(is_socket_sockaddr__doc__, static PyObject* is_socket_sockaddr(PyObject *self, PyObject *args) { int r; - int fd, type = 0, listening = -1; + int fd, type = 0, flowinfo = 0, listening = -1; const char *address; union sockaddr_union addr = {}; unsigned addr_len; - if (!PyArg_ParseTuple(args, "is|ii:_is_socket_sockaddr", + if (!PyArg_ParseTuple(args, "is|iii:_is_socket_sockaddr", &fd, &address, - &type, &listening)) + &type, + &flowinfo, + &listening)) return NULL; r = parse_sockaddr(address, &addr, &addr_len); @@ -346,6 +348,15 @@ static PyObject* is_socket_sockaddr(PyObject *self, PyObject *args) { return NULL; } + if (flowinfo != 0) { + if (addr.sa.sa_family != AF_INET6) { + set_error(-EINVAL, NULL, "flowinfo is only applicable to IPv6 addresses"); + return NULL; + } + + addr.in6.sin6_flowinfo = flowinfo; + } + r = sd_is_socket_sockaddr(fd, type, &addr.sa, addr_len, listening); if (set_error(r, NULL, NULL) < 0) return NULL; -- cgit v1.2.1