diff --git a/src/util.c b/src/util.c index 274e42b3..74960a47 100644 --- a/src/util.c +++ b/src/util.c @@ -218,30 +218,29 @@ save_pid_file(const char *pf) return; } -// true: 1; false: 0 -int +bool is_valid_ip(const char *ip) { if (!ip) { - return 0; + return false; } struct sockaddr_in sa; int result = inet_pton(AF_INET, ip, &(sa.sin_addr)); return result != 0; } -int +bool is_valid_ip6(const char *ip) { if (!ip) { - return 0; + return false; } struct sockaddr_in6 sa; int result = inet_pton(AF_INET6, ip, &(sa.sin6_addr)); return result != 0; } -int +bool is_valid_mac(const char *mac) { int i = 0; @@ -354,3 +353,12 @@ get_cpu_usage() return percent_usage; } + +bool +is_file_exist(const char *file) +{ + struct stat buf; + if(stat(file, &buf) == 0) + return true; + return false; +} \ No newline at end of file diff --git a/src/util.h b/src/util.h index 5fd92d78..73be92ee 100644 --- a/src/util.h +++ b/src/util.h @@ -7,8 +7,7 @@ #ifndef _UTIL_H_ #define _UTIL_H_ -#include -#include +#include /** @brief Initialize the ICMP socket */ int init_icmp_socket(void); @@ -24,12 +23,14 @@ void icmp6_ping(const char *); /** @brief Save pid of this wifidog in pid file */ void save_pid_file(const char *); -int is_valid_ip(const char *); +bool is_valid_ip(const char *); -int is_valid_ip6(const char *); +bool is_valid_ip6(const char *); -int is_valid_mac(const char *); +bool is_valid_mac(const char *); float get_cpu_usage(); +bool is_file_exist(const char *file); + #endif /* _UTIL_H_ */