blob: d29d604757768a66473dc44100ef3b75ec8ea82a [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001
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
29void pd_path_init(struct pd_path *p);
30void pd_path_set_iface(struct pd_path *p, const char *ifname);
31void pd_path_set_file(struct pd_path *p, const char *fname);
32void pd_path_set_iface_file(struct pd_path *p, const char *iface,
33 const char *fname);
34int __pd_write_str(char *path, const char *v);
35int __pd_write_bool(char *path, bool b);
36int __pd_read(char *path, char *buf, int len);
37int __pd_read_bool(char *path, bool *ans);
38int pd_write_str(struct pd_path *p, const char *v);
39int pd_write_bool(struct pd_path *p, bool b);
40int pd_read(struct pd_path *p, char *buf, int len);
41int pd_read_bool(struct pd_path *p, bool *ans);
42int pd_file_exists(struct pd_path *p);
43
44int validate_ip(const char *addr, int family);
45int ipv6_split_pref(const char *ip6addr, char *addr_buf, char *pref_buf);
46int validate_prefixlen(const char *preflen);
47int str_starts_with(const char *str, const char *pre);
48void ipv4_change_addr(const char *ip1, char *ip2, int *last_oct);
49int ipv4_change_oct(int oct);
50void ipv4_get_alias(const char *ip1, char *ip2);
51int ipv4_get_last_oct(const char *ip);
52void pipe_log_test(void);
53int ipv4_get_third_oct(const char *ip1);
54int ipv4_get_second_oct(const char *ip1);
55
56
57#endif