diff options
Diffstat (limited to 'src/plugins/sys_util.h')
-rw-r--r-- | src/plugins/sys_util.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/plugins/sys_util.h b/src/plugins/sys_util.h index 6c227c3..d449712 100644 --- a/src/plugins/sys_util.h +++ b/src/plugins/sys_util.h @@ -34,4 +34,44 @@ void log_recv_event(sr_notif_event_t event, const char *msg); void log_recv_oper(sr_change_oper_t oper, const char *msg); int ip_prefix_split(const char* ip_prefix); +/** + * @brief Get IPv4 host address from IPv4 prefix. + * + * @param[out] dst Host IPv4 address. + * @param[in] src IPv4 Prefix. + * @param[in] length dst buffer length. + * @param[out] prefix Get Prefix length, optional value. Can be NULL. + * @return -1 when failure, 0 on success. + */ +int get_address_from_prefix(char* dst, const char* src, size_t length, + uint8_t* prefix_length); + +typedef struct +{ + uint8_t address[4]; +} sc_ipv4_addr; + +/** + * @brief Get IPv4 broadcast IP address form IPv4 network address. + * + * @param[out] broadcat Broadcast Ipv4 address. + * @param[in] network Network IPv4 address. + * @param[in] prefix Prefix number. + * @return -1 when failure, 0 on success. + */ +int get_network_broadcast(sc_ipv4_addr *broadcast, const sc_ipv4_addr *network, + uint8_t prefix_length); + +/** + * @brief Get last IPv4 address from the IP range. + * + * @param[out] last_ip_address Last Ipv4 address. + * @param[in] first_ip_address First IPv4 address. + * @param[in] prefix Prefix number. + * @return -1 when failure, 0 on success. + */ +int get_last_ip_address(sc_ipv4_addr *last_ip_address, + const sc_ipv4_addr *first_ip_address, + uint8_t prefix_length); + #endif /* __SYS_UTIL_H__ */ |