Ratan Gupta | 8804feb | 2017-05-25 10:49:57 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <unistd.h> |
| 4 | |
| 5 | namespace phosphor |
| 6 | { |
| 7 | namespace 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 | */ |
| 15 | uint8_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 | */ |
| 22 | std::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 | */ |
| 28 | bool isLinkLocal(const std::string& address); |
| 29 | |
Ratan Gupta | 11cef80 | 2017-05-29 08:41:48 +0530 | [diff] [blame] | 30 | /* @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 | */ |
| 36 | std::string getNetworkID(int addressFamily, const std::string& ipaddress, |
| 37 | uint8_t prefix); |
| 38 | |
Ratan Gupta | 8804feb | 2017-05-25 10:49:57 +0530 | [diff] [blame] | 39 | } //namespace network |
| 40 | |
| 41 | class 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 Gupta | 11cef80 | 2017-05-29 08:41:48 +0530 | [diff] [blame] | 52 | Descriptor& operator=(Descriptor &&) = delete; |
Ratan Gupta | 8804feb | 2017-05-25 10:49:57 +0530 | [diff] [blame] | 53 | |
| 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 |