blob: d29d604757768a66473dc44100ef3b75ec8ea82a [file] [log] [blame]
#ifndef __PIPED_UTIL__
#define __PIPED_UTIL__
#include <arpa/inet.h>
#include <include/log.h>
#include "diag_API.h"
#define _FILE_ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#ifdef PIPED_USE_LOGCAT
#define PD_PRINTF(CAT, format, args...) RLOG_DBG(PIPED, CAT, format, ##args)
#define PD_DBG(CAT, format, args...) RLOG_DBG(PIPED, CAT, format, ##args)
#define PD_INFO(CAT, format, args...) RLOG_INFO(PIPED, CAT, format, ##args)
#define PD_WARN(CAT, format, args...) RLOG_WARN(PIPED, CAT, format, ##args)
#define PD_ERR(CAT, format, args...) RLOG_ERROR(PIPED, CAT, format, ##args)
#else
#define PD_PRINTF(f_, ...) printf("%s:%d " f_, _FILE_ , __LINE__, ##__VA_ARGS__)
#define PD_DBG(f_, ...) PD_PRINTF(f_, ##__VA_ARGS__)
#define PD_INFO(f_, ...) PD_PRINTF(f_, ##__VA_ARGS__)
#define PD_WARN(f_, ...) PD_PRINTF("WARNING: " f_, ##__VA_ARGS__)
#define PD_ERR(f_, ...) PD_PRINTF("ERROR: " f_, ##__VA_ARGS__)
#endif
#ifndef UNUSEDPARAM
#define UNUSEDPARAM(param) (void)param;
#endif
void pd_path_init(struct pd_path *p);
void pd_path_set_iface(struct pd_path *p, const char *ifname);
void pd_path_set_file(struct pd_path *p, const char *fname);
void pd_path_set_iface_file(struct pd_path *p, const char *iface,
const char *fname);
int __pd_write_str(char *path, const char *v);
int __pd_write_bool(char *path, bool b);
int __pd_read(char *path, char *buf, int len);
int __pd_read_bool(char *path, bool *ans);
int pd_write_str(struct pd_path *p, const char *v);
int pd_write_bool(struct pd_path *p, bool b);
int pd_read(struct pd_path *p, char *buf, int len);
int pd_read_bool(struct pd_path *p, bool *ans);
int pd_file_exists(struct pd_path *p);
int validate_ip(const char *addr, int family);
int ipv6_split_pref(const char *ip6addr, char *addr_buf, char *pref_buf);
int validate_prefixlen(const char *preflen);
int str_starts_with(const char *str, const char *pre);
void ipv4_change_addr(const char *ip1, char *ip2, int *last_oct);
int ipv4_change_oct(int oct);
void ipv4_get_alias(const char *ip1, char *ip2);
int ipv4_get_last_oct(const char *ip);
void pipe_log_test(void);
int ipv4_get_third_oct(const char *ip1);
int ipv4_get_second_oct(const char *ip1);
#endif