| 1 | // Copyright (C) Microsoft Corporation. All rights reserved. |
| 2 | #pragma once |
| 3 | |
| 4 | #include <vector> |
| 5 | #include <optional> |
| 6 | #include <linux/netlink.h> |
| 7 | #include <linux/rtnetlink.h> |
| 8 | #include "Fwd.h" |
| 9 | |
| 10 | template <typename TMessage> |
| 11 | class NetlinkMessage |
| 12 | { |
| 13 | public: |
| 14 | using Titerator = std::vector<char>::const_iterator; |
| 15 | |
| 16 | NetlinkMessage(const NetlinkResponse& response, Titerator responseBegin, Titerator begin, Titerator end); |
| 17 | |
| 18 | const TMessage* Payload() const; |
| 19 | |
| 20 | const nlmsghdr* Header() const; |
| 21 | |
| 22 | template <typename TAttribute> |
| 23 | std::vector<const TAttribute*> Attributes(int type) const; |
| 24 | |
| 25 | template <typename TAttribute> |
| 26 | std::optional<const TAttribute*> UniqueAttribute(int type) const; |
| 27 | |
| 28 | private: |
| 29 | const rtattr* FirstAttribute() const; |
| 30 | |
| 31 | const NetlinkResponse& m_response; |
| 32 | Titerator m_responseBegin; |
| 33 | Titerator m_begin; |
| 34 | Titerator m_end; |
| 35 | }; |
| 36 | |
| 37 | #include "NetlinkMessage.hxx" |