summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-12-15 08:38:48 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-12-15 21:00:08 -0500
commit5ffc22689058b4f14cd9a8bb17bed71aa051021d (patch)
tree4ee54eabba936df03c99364fd8a3bf960a81dd7b
parent17a1dad79588313c879a3eef94dcb8d5ad1b57ba (diff)
downloadpython-systemd-5ffc22689058b4f14cd9a8bb17bed71aa051021d.tar.gz
_daemon: allow specifying flowinfo
Not particularly useful, but let's have it for completeness.
-rw-r--r--systemd/_daemon.c19
1 files 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;