b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | |
| 2 | #ifndef __PIPED_UTIL__ |
| 3 | #define __PIPED_UTIL__ |
| 4 | |
| 5 | #include <arpa/inet.h> |
| 6 | #include <include/log.h> |
| 7 | #include "diag_API.h" |
| 8 | |
| 9 | #define _FILE_ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) |
| 10 | |
| 11 | #ifdef PIPED_USE_LOGCAT |
| 12 | #define PD_PRINTF(CAT, format, args...) RLOG_DBG(PIPED, CAT, format, ##args) |
| 13 | #define PD_DBG(CAT, format, args...) RLOG_DBG(PIPED, CAT, format, ##args) |
| 14 | #define PD_INFO(CAT, format, args...) RLOG_INFO(PIPED, CAT, format, ##args) |
| 15 | #define PD_WARN(CAT, format, args...) RLOG_WARN(PIPED, CAT, format, ##args) |
| 16 | #define PD_ERR(CAT, format, args...) RLOG_ERROR(PIPED, CAT, format, ##args) |
| 17 | #else |
| 18 | #define PD_PRINTF(f_, ...) printf("%s:%d " f_, _FILE_ , __LINE__, ##__VA_ARGS__) |
| 19 | #define PD_DBG(f_, ...) PD_PRINTF(f_, ##__VA_ARGS__) |
| 20 | #define PD_INFO(f_, ...) PD_PRINTF(f_, ##__VA_ARGS__) |
| 21 | #define PD_WARN(f_, ...) PD_PRINTF("WARNING: " f_, ##__VA_ARGS__) |
| 22 | #define PD_ERR(f_, ...) PD_PRINTF("ERROR: " f_, ##__VA_ARGS__) |
| 23 | #endif |
| 24 | |
| 25 | #ifndef UNUSEDPARAM |
| 26 | #define UNUSEDPARAM(param) (void)param; |
| 27 | #endif |
| 28 | |
| 29 | void pd_path_init(struct pd_path *p); |
| 30 | void pd_path_set_iface(struct pd_path *p, const char *ifname); |
| 31 | void pd_path_set_file(struct pd_path *p, const char *fname); |
| 32 | void pd_path_set_iface_file(struct pd_path *p, const char *iface, |
| 33 | const char *fname); |
| 34 | int __pd_write_str(char *path, const char *v); |
| 35 | int __pd_write_bool(char *path, bool b); |
| 36 | int __pd_read(char *path, char *buf, int len); |
| 37 | int __pd_read_bool(char *path, bool *ans); |
| 38 | int pd_write_str(struct pd_path *p, const char *v); |
| 39 | int pd_write_bool(struct pd_path *p, bool b); |
| 40 | int pd_read(struct pd_path *p, char *buf, int len); |
| 41 | int pd_read_bool(struct pd_path *p, bool *ans); |
| 42 | int pd_file_exists(struct pd_path *p); |
| 43 | |
| 44 | int validate_ip(const char *addr, int family); |
| 45 | int ipv6_split_pref(const char *ip6addr, char *addr_buf, char *pref_buf); |
| 46 | int validate_prefixlen(const char *preflen); |
| 47 | int str_starts_with(const char *str, const char *pre); |
| 48 | void ipv4_change_addr(const char *ip1, char *ip2, int *last_oct); |
| 49 | int ipv4_change_oct(int oct); |
| 50 | void ipv4_get_alias(const char *ip1, char *ip2); |
| 51 | int ipv4_get_last_oct(const char *ip); |
| 52 | void pipe_log_test(void); |
| 53 | int ipv4_get_third_oct(const char *ip1); |
| 54 | int ipv4_get_second_oct(const char *ip1); |
| 55 | |
| 56 | |
| 57 | #endif |