Joel Scherpelz | f3fa5cc | 2017-05-22 12:30:03 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef NETUTILS_NETLINK_H |
| 18 | #define NETUTILS_NETLINK_H |
| 19 | |
| 20 | #include <functional> |
| 21 | #include <ostream> |
| 22 | #include <linux/netlink.h> |
| 23 | |
| 24 | #include "netdutils/Slice.h" |
| 25 | |
| 26 | namespace android { |
| 27 | namespace netdutils { |
| 28 | |
| 29 | // Invoke onMsg once for each netlink message in buf. onMsg will be |
| 30 | // invoked with an aligned and deserialized header along with a Slice |
| 31 | // containing the message payload. |
| 32 | // |
| 33 | // Assume that the first message begins at offset zero within buf. |
| 34 | void forEachNetlinkMessage(const Slice buf, |
| 35 | const std::function<void(const nlmsghdr&, const Slice)>& onMsg); |
| 36 | |
| 37 | // Invoke onAttr once for each netlink attribute in buf. onAttr will be |
| 38 | // invoked with an aligned and deserialized header along with a Slice |
| 39 | // containing the attribute payload. |
| 40 | // |
| 41 | // Assume that the first attribute begins at offset zero within buf. |
| 42 | void forEachNetlinkAttribute(const Slice buf, |
| 43 | const std::function<void(const nlattr&, const Slice)>& onAttr); |
| 44 | |
| 45 | } // namespace netdutils |
| 46 | } // namespace android |
| 47 | |
| 48 | bool operator==(const sockaddr_nl& lhs, const sockaddr_nl& rhs); |
| 49 | bool operator!=(const sockaddr_nl& lhs, const sockaddr_nl& rhs); |
| 50 | |
| 51 | std::ostream& operator<<(std::ostream& os, const nlmsghdr& hdr); |
| 52 | std::ostream& operator<<(std::ostream& os, const nlattr& attr); |
| 53 | std::ostream& operator<<(std::ostream& os, const sockaddr_nl& addr); |
| 54 | |
| 55 | #endif /* NETUTILS_NETLINK_H */ |