blob: fb511fedf95208260747056eaf2db9bf8f7e6cdf [file] [log] [blame]
Ratan Gupta8804feb2017-05-25 10:49:57 +05301#pragma once
2
3#include <unistd.h>
4
5namespace phosphor
6{
7namespace network
8{
9
10/* @brief converts the given subnet into prefix notation.
11 * @param[in] addressFamily - IP address family(AF_INET/AF_INET6).
12 * @param[in] mask - Subnet Mask.
13 * @returns prefix.
14 */
15uint8_t toCidr(int addressFamily, const std::string& mask);
16
17/* @brief converts the prefix into subnetmask.
18 * @param[in] addressFamily - IP address family(AF_INET/AF_INET6).
19 * @param[in] prefix - prefix length.
20 * @returns subnet mask.
21 */
22std::string toMask(int addressFamily, uint8_t prefix);
23
24/* @brief checks that the given ip address is link local or not.
25 * @param[in] address - IP address.
26 * @returns true if it is linklocal otherwise false.
27 */
28bool isLinkLocal(const std::string& address);
29
Ratan Gupta11cef802017-05-29 08:41:48 +053030/* @brief gets the network section of the ip adress.
31 * @param[in] addressFamily - IP address family(AF_INET/AF_INET6).
32 * @param[in] ipaddress - IP address.
33 * @param[in] prefix - prefix length.
34 * @returns network section of the ipaddress.
35 */
36std::string getNetworkID(int addressFamily, const std::string& ipaddress,
37 uint8_t prefix);
38
Ratan Gupta8804feb2017-05-25 10:49:57 +053039} //namespace network
40
41class Descriptor
42{
43 private:
44 /** default value */
45 int fd = -1;
46
47 public:
48 Descriptor() = delete;
49 Descriptor(const Descriptor&) = delete;
50 Descriptor& operator=(const Descriptor&) = delete;
51 Descriptor(Descriptor&&) = delete;
Ratan Gupta11cef802017-05-29 08:41:48 +053052 Descriptor& operator=(Descriptor &&) = delete;
Ratan Gupta8804feb2017-05-25 10:49:57 +053053
54 Descriptor(int fd) : fd(fd) {}
55
56 ~Descriptor()
57 {
58 if (fd >= 0)
59 {
60 close(fd);
61 }
62 }
63
64 int operator()() const
65 {
66 return fd;
67 }
68};
69
70} //namespace phosphor