diff options
Diffstat (limited to 'automotive/can/1.0/default/libnl++/Socket.cpp')
-rw-r--r-- | automotive/can/1.0/default/libnl++/Socket.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/automotive/can/1.0/default/libnl++/Socket.cpp b/automotive/can/1.0/default/libnl++/Socket.cpp index 514d9bb1b9..cc1d839434 100644 --- a/automotive/can/1.0/default/libnl++/Socket.cpp +++ b/automotive/can/1.0/default/libnl++/Socket.cpp @@ -68,6 +68,11 @@ bool Socket::send(const Buffer<nlmsghdr>& msg, const sockaddr_nl& sa) { return true; } +bool Socket::send(const Buffer<nlmsghdr>& msg, uint32_t destination) { + sockaddr_nl sa = {.nl_family = AF_NETLINK, .nl_pad = 0, .nl_pid = destination, .nl_groups = 0}; + return send(msg, sa); +} + bool Socket::increaseReceiveBuffer(size_t maxSize) { if (maxSize == 0) { LOG(ERROR) << "Maximum receive size should not be zero"; @@ -157,6 +162,26 @@ pollfd Socket::preparePoll(short events) { return {mFd.get(), events, 0}; } +bool Socket::addMembership(unsigned group) { + const auto res = + setsockopt(mFd.get(), SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, &group, sizeof(group)); + if (res < 0) { + PLOG(ERROR) << "Failed joining multicast group " << group; + return false; + } + return true; +} + +bool Socket::dropMembership(unsigned group) { + const auto res = + setsockopt(mFd.get(), SOL_NETLINK, NETLINK_DROP_MEMBERSHIP, &group, sizeof(group)); + if (res < 0) { + PLOG(ERROR) << "Failed leaving multicast group " << group; + return false; + } + return true; +} + Socket::receive_iterator::receive_iterator(Socket& socket, bool end) : mSocket(socket), mIsEnd(end) { if (!end) receive(); |