From 7abc0201d0875d9bf0c849bf1259afdd1f8109bd Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 27 May 2024 12:31:33 +0900 Subject: [PATCH] sd-device-monitor: introduce device_monitor_get_address() Currently it is used internally, but will be used later at other places. --- src/libsystemd/sd-device/device-monitor-private.h | 3 +++ src/libsystemd/sd-device/device-monitor.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/libsystemd/sd-device/device-monitor-private.h b/src/libsystemd/sd-device/device-monitor-private.h index 96513649ff8..43cc1914e01 100644 --- a/src/libsystemd/sd-device/device-monitor-private.h +++ b/src/libsystemd/sd-device/device-monitor-private.h @@ -5,6 +5,8 @@ #include "sd-device.h" +#include "socket-util.h" + typedef enum MonitorNetlinkGroup { MONITOR_GROUP_NONE, MONITOR_GROUP_KERNEL, @@ -15,6 +17,7 @@ typedef enum MonitorNetlinkGroup { int device_monitor_new_full(sd_device_monitor **ret, MonitorNetlinkGroup group, int fd); int device_monitor_disconnect(sd_device_monitor *m); +int device_monitor_get_address(sd_device_monitor *m, union sockaddr_union *ret); int device_monitor_allow_unicast_sender(sd_device_monitor *m, sd_device_monitor *sender); int device_monitor_get_fd(sd_device_monitor *m); int device_monitor_send_device(sd_device_monitor *m, sd_device_monitor *destination, sd_device *device); diff --git a/src/libsystemd/sd-device/device-monitor.c b/src/libsystemd/sd-device/device-monitor.c index 49167c69f5a..56f8836ef31 100644 --- a/src/libsystemd/sd-device/device-monitor.c +++ b/src/libsystemd/sd-device/device-monitor.c @@ -25,7 +25,6 @@ #include "missing_socket.h" #include "mountpoint-util.h" #include "set.h" -#include "socket-util.h" #include "stat-util.h" #include "string-util.h" #include "strv.h" @@ -105,12 +104,19 @@ static int monitor_set_nl_address(sd_device_monitor *m) { return 0; } +int device_monitor_get_address(sd_device_monitor *m, union sockaddr_union *ret) { + assert(m); + assert(ret); + + *ret = m->snl; + return 0; +} + int device_monitor_allow_unicast_sender(sd_device_monitor *m, sd_device_monitor *sender) { assert(m); assert(sender); - m->snl_trusted_sender.nl.nl_pid = sender->snl.nl.nl_pid; - return 0; + return device_monitor_get_address(sender, &m->snl_trusted_sender); } _public_ int sd_device_monitor_set_receive_buffer_size(sd_device_monitor *m, size_t size) {