Ratan Gupta | 8804feb | 2017-05-25 10:49:57 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <unistd.h> |
Ratan Gupta | 3681a50 | 2017-06-17 19:20:04 +0530 | [diff] [blame] | 4 | #include "types.hpp" |
Ratan Gupta | 8804feb | 2017-05-25 10:49:57 +0530 | [diff] [blame] | 5 | |
| 6 | namespace phosphor |
| 7 | { |
| 8 | namespace network |
| 9 | { |
| 10 | |
| 11 | /* @brief converts the given subnet into prefix notation. |
| 12 | * @param[in] addressFamily - IP address family(AF_INET/AF_INET6). |
| 13 | * @param[in] mask - Subnet Mask. |
| 14 | * @returns prefix. |
| 15 | */ |
| 16 | uint8_t toCidr(int addressFamily, const std::string& mask); |
| 17 | |
| 18 | /* @brief converts the prefix into subnetmask. |
| 19 | * @param[in] addressFamily - IP address family(AF_INET/AF_INET6). |
| 20 | * @param[in] prefix - prefix length. |
| 21 | * @returns subnet mask. |
| 22 | */ |
| 23 | std::string toMask(int addressFamily, uint8_t prefix); |
| 24 | |
| 25 | /* @brief checks that the given ip address is link local or not. |
| 26 | * @param[in] address - IP address. |
| 27 | * @returns true if it is linklocal otherwise false. |
| 28 | */ |
| 29 | bool isLinkLocal(const std::string& address); |
| 30 | |
Ratan Gupta | 11cef80 | 2017-05-29 08:41:48 +0530 | [diff] [blame] | 31 | /* @brief gets the network section of the ip adress. |
| 32 | * @param[in] addressFamily - IP address family(AF_INET/AF_INET6). |
| 33 | * @param[in] ipaddress - IP address. |
| 34 | * @param[in] prefix - prefix length. |
| 35 | * @returns network section of the ipaddress. |
| 36 | */ |
| 37 | std::string getNetworkID(int addressFamily, const std::string& ipaddress, |
| 38 | uint8_t prefix); |
| 39 | |
Ratan Gupta | 3681a50 | 2017-06-17 19:20:04 +0530 | [diff] [blame] | 40 | /** @brief Get all the interfaces from the system. |
| 41 | * @returns list of interface names. |
| 42 | */ |
| 43 | IntfAddrMap getInterfaceAddrs(); |
| 44 | |
Ratan Gupta | 8804feb | 2017-05-25 10:49:57 +0530 | [diff] [blame] | 45 | } //namespace network |
| 46 | |
| 47 | class Descriptor |
| 48 | { |
| 49 | private: |
| 50 | /** default value */ |
| 51 | int fd = -1; |
| 52 | |
| 53 | public: |
| 54 | Descriptor() = delete; |
| 55 | Descriptor(const Descriptor&) = delete; |
| 56 | Descriptor& operator=(const Descriptor&) = delete; |
| 57 | Descriptor(Descriptor&&) = delete; |
Ratan Gupta | 11cef80 | 2017-05-29 08:41:48 +0530 | [diff] [blame] | 58 | Descriptor& operator=(Descriptor &&) = delete; |
Ratan Gupta | 8804feb | 2017-05-25 10:49:57 +0530 | [diff] [blame] | 59 | |
| 60 | Descriptor(int fd) : fd(fd) {} |
| 61 | |
| 62 | ~Descriptor() |
| 63 | { |
| 64 | if (fd >= 0) |
| 65 | { |
| 66 | close(fd); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | int operator()() const |
| 71 | { |
| 72 | return fd; |
| 73 | } |
| 74 | }; |
| 75 | |
| 76 | } //namespace phosphor |