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 | |
| 30 | } //namespace network |
| 31 | |
| 32 | class Descriptor |
| 33 | { |
| 34 | private: |
| 35 | /** default value */ |
| 36 | int fd = -1; |
| 37 | |
| 38 | public: |
| 39 | Descriptor() = delete; |
| 40 | Descriptor(const Descriptor&) = delete; |
| 41 | Descriptor& operator=(const Descriptor&) = delete; |
| 42 | Descriptor(Descriptor&&) = delete; |
| 43 | Descriptor& operator=(Descriptor&&) = delete; |
| 44 | |
| 45 | Descriptor(int fd) : fd(fd) {} |
| 46 | |
| 47 | ~Descriptor() |
| 48 | { |
| 49 | if (fd >= 0) |
| 50 | { |
| 51 | close(fd); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | int operator()() const |
| 56 | { |
| 57 | return fd; |
| 58 | } |
| 59 | }; |
| 60 | |
| 61 | } //namespace phosphor |