Creating netdev
[platform/core/security/vasum.git] / common / netlink / netlink.hpp
1 /*
2  *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Mateusz Malicki <m.malicki2@samsung.com>
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License
17  */
18
19 /**
20  * @file
21  * @author  Mateusz Malicki (m.malicki2@samsung.com)
22  * @brief   Netlink class declaration
23  */
24
25 #ifndef COMMON_NETLINK_NETLINK_HPP
26 #define COMMON_NETLINK_NETLINK_HPP
27
28 #include <linux/netlink.h>
29
30 namespace vasum {
31
32 /**
33  * Netlink class is responsible for communicating
34  * with kernel through netlink interface
35  */
36 class Netlink {
37 public:
38     Netlink();
39     ~Netlink();
40
41     Netlink(const Netlink& other) = delete;
42     Netlink& operator=(const Netlink& other) = delete;
43
44     /**
45      * Open connnection
46      */
47     void open();
48
49     /**
50      * Close connection
51      */
52     void close();
53
54     /**
55      * Send message
56      *
57      * It is not thread safe and even you shouldn't call this function on
58      * different instances at the same time
59      *
60      * @param nlmsg pointer to message
61      */
62     void send(const nlmsghdr *nlmsg);
63
64     /**
65      * Receive message
66      *
67      * It is not thread safe and even you shouldn't call this function on
68      * different instances at the same time
69      *
70      * @param answer pointer to answer buffer
71      */
72     int rcv(nlmsghdr *answer);
73 private:
74     int mFd;
75 };
76
77 } // namespace vasum
78
79 #endif /* COMMON_NETLINK_NETLINK_HPP */