From a30930465eec3e8c1b5aa1ce5eefc2511846beda Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Sat, 10 Aug 2019 18:55:54 +0300 Subject: [PATCH] Net: Add LocalSocket::socket_path() This is a little utility function to safely extract the path without manually dealing with sun_path and null-termination. --- Kernel/Net/LocalSocket.cpp | 6 ++++++ Kernel/Net/LocalSocket.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp index c7eb24dba1..d9453c5e1f 100644 --- a/Kernel/Net/LocalSocket.cpp +++ b/Kernel/Net/LocalSocket.cpp @@ -227,3 +227,9 @@ ssize_t LocalSocket::recvfrom(FileDescription& description, void* buffer, size_t } ASSERT_NOT_REACHED(); } + +StringView LocalSocket::socket_path() const +{ + int len = strnlen(m_address.sun_path, sizeof(m_address.sun_path)); + return { m_address.sun_path, len }; +} diff --git a/Kernel/Net/LocalSocket.h b/Kernel/Net/LocalSocket.h index b764a6a117..84c470173d 100644 --- a/Kernel/Net/LocalSocket.h +++ b/Kernel/Net/LocalSocket.h @@ -10,6 +10,8 @@ public: static NonnullRefPtr create(int type); virtual ~LocalSocket() override; + + StringView socket_path() const; // ^Socket virtual KResult bind(const sockaddr*, socklen_t) override; virtual KResult connect(FileDescription&, const sockaddr*, socklen_t, ShouldBlock = ShouldBlock::Yes) override;