1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef INCLUDE_NETLINK_SOCKET_H__ 17 #define INCLUDE_NETLINK_SOCKET_H__ 18 19 #include <functional> 20 #include <memory> 21 #include <netinet/in.h> 22 #include <sys/epoll.h> 23 #include <linux/netlink.h> 24 #include <linux/rtnetlink.h> 25 26 namespace OHOS { 27 namespace nmd { 28 class NetlinkSocket { 29 public: 30 int socketFd; 31 32 virtual ~NetlinkSocket(); 33 SetPid(int pid)34 void SetPid(int pid) 35 { 36 this->pid = pid; 37 } 38 39 int Create(int protocol); 40 int Create(int type, int protocol); 41 int SendNetlinkMsgToKernel(struct nlmsghdr *msg); 42 int Shutdown(); 43 private: 44 int pid = 0; 45 }; 46 } // namespace nmd 47 } // namespace OHOS 48 #endif // !INCLUDE_NETLINK_SOCKET_H__ 49