BIND_OPTS3结构的未定义问题

本文介绍了解决编译过程中遇到的BIND_OPTS3结构未定义的问题。BIND_OPTS3为Vista新增,需要Vista SDK支持。文中给出了具体的定义代码,帮助通过编译。

编译一个源代码的时候发现BIND_OPTS3结构报告未定义。google里搜索了半天也没找到缺哪个头文件。MSDN上的信息也很少,没说清楚。后来看了篇文章,说BIND_OPTS3是Vista新加的,要VistaSDK,BIND_OPTS3是从BIND_OPTS2结构继承来的。所以在源代码里加下面的定义:

typedef struct tagBIND_OPTS3 : tagBIND_OPTS2
{
HWND hwnd;
} BIND_OPTS3, * LPBIND_OPTS3;

再编译,通过。

include/jemalloc/internal/log.h:42:1: 警告:空声明 [默认启用] struct log_var_s { ^ include/jemalloc/internal/log.h:62:31: 错误:expected declaration specifiers or ‘...’ before ‘log_var_t’ unsigned log_var_update_state(log_var_t *log_var); ^ include/jemalloc/internal/log.h:89:41: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token log_impl_varargs(const char *name, ...) { ^ In file included from src/jemalloc.c:18:0: include/jemalloc/internal/spin.h:8:3: 错误:为形参‘spin_t’指定了存储类 } spin_t; ^ include/jemalloc/internal/spin.h:11:21: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token spin_cpu_spinwait() { ^ include/jemalloc/internal/spin.h:21:15: 错误:expected declaration specifiers or ‘...’ before ‘spin_t’ spin_adaptive(spin_t *spin) { ^ src/jemalloc.c:29:5: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_ATTR’ JEMALLOC_ATTR(weak) ^ src/jemalloc.c:32:1: 错误:形参‘opt_abort’已初始化 bool opt_abort = ^ src/jemalloc.c:32:6: 错误:形参‘opt_abort’重定义 bool opt_abort = ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:11:13: 附注:‘opt_abort’的上一个定义在此 extern bool opt_abort; ^ src/jemalloc.c:39:1: 错误:形参‘opt_abort_conf’已初始化 bool opt_abort_conf = ^ src/jemalloc.c:39:6: 错误:形参‘opt_abort_conf’重定义 bool opt_abort_conf = ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:12:13: 附注:‘opt_abort_conf’的上一个定义在此 extern bool opt_abort_conf; ^ src/jemalloc.c:47:1: 错误:形参‘opt_confirm_conf’已初始化 bool opt_confirm_conf = false; ^ src/jemalloc.c:47:6: 错误:形参‘opt_confirm_conf’重定义 bool opt_confirm_conf = false; ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:13:13: 附注:‘opt_confirm_conf’的上一个定义在此 extern bool opt_confirm_conf; ^ src/jemalloc.c:48:1: 错误:形参‘opt_junk’已初始化 const char *opt_junk = ^ src/jemalloc.c:48:13: 错误:形参‘opt_junk’重定义 const char *opt_junk = ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:14:20: 附注:‘opt_junk’的上一个定义在此 extern const char *opt_junk; ^ src/jemalloc.c:55:1: 错误:形参‘opt_junk_alloc’已初始化 bool opt_junk_alloc = ^ src/jemalloc.c:55:6: 错误:形参‘opt_junk_alloc’重定义 bool opt_junk_alloc = ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:15:13: 附注:‘opt_junk_alloc’的上一个定义在此 extern bool opt_junk_alloc; ^ src/jemalloc.c:62:1: 错误:形参‘opt_junk_free’已初始化 bool opt_junk_free = ^ src/jemalloc.c:62:6: 错误:形参‘opt_junk_free’重定义 bool opt_junk_free = ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:16:13: 附注:‘opt_junk_free’的上一个定义在此 extern bool opt_junk_free; ^ src/jemalloc.c:70:1: 错误:形参‘opt_utrace’已初始化 bool opt_utrace = false; ^ src/jemalloc.c:70:6: 错误:形参‘opt_utrace’重定义 bool opt_utrace = false; ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:17:13: 附注:‘opt_utrace’的上一个定义在此 extern bool opt_utrace; ^ src/jemalloc.c:71:1: 错误:形参‘opt_xmalloc’已初始化 bool opt_xmalloc = false; ^ src/jemalloc.c:71:6: 错误:形参‘opt_xmalloc’重定义 bool opt_xmalloc = false; ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:18:13: 附注:‘opt_xmalloc’的上一个定义在此 extern bool opt_xmalloc; ^ src/jemalloc.c:72:1: 错误:形参‘opt_zero’已初始化 bool opt_zero = false; ^ src/jemalloc.c:72:6: 错误:形参‘opt_zero’重定义 bool opt_zero = false; ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:19:13: 附注:‘opt_zero’的上一个定义在此 extern bool opt_zero; ^ src/jemalloc.c:73:1: 错误:形参‘opt_narenas’已初始化 unsigned opt_narenas = 0; ^ src/jemalloc.c:73:10: 错误:形参‘opt_narenas’重定义 unsigned opt_narenas = 0; ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:20:17: 附注:‘opt_narenas’的上一个定义在此 extern unsigned opt_narenas; ^ src/jemalloc.c:75:10: 错误:形参‘ncpus’重定义 unsigned ncpus; ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:23:17: 附注:‘ncpus’的上一个定义在此 extern unsigned ncpus; ^ src/jemalloc.c:78:1: 错误:expected declaration specifiers before ‘malloc_mutex_t’ malloc_mutex_t arenas_lock; ^ src/jemalloc.c:89:1: 错误:expected declaration specifiers before ‘JEMALLOC_ALIGNED’ JEMALLOC_ALIGNED(CACHELINE) ^ src/jemalloc.c:91:19: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘narenas_total’ static atomic_u_t narenas_total; /* Use narenas_total_*(). */ ^ src/jemalloc.c:93:18: 错误:为形参‘a0’指定了存储类 static arena_t *a0; /* arenas[0]. */ ^ src/jemalloc.c:94:11: 错误:形参‘narenas_auto’重定义 unsigned narenas_auto; ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:26:17: 附注:‘narenas_auto’的上一个定义在此 extern unsigned narenas_auto; ^ src/jemalloc.c:95:11: 错误:形参‘manual_arena_base’重定义 unsigned manual_arena_base; ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:29:17: 附注:‘manual_arena_base’的上一个定义在此 extern unsigned manual_arena_base; ^ src/jemalloc.c:102:3: 错误:为形参‘malloc_init_t’指定了存储类 } malloc_init_t; ^ src/jemalloc.c:103:22: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘malloc_init_state’ static malloc_init_t malloc_init_state = malloc_init_uninitialized; ^ src/jemalloc.c:106:1: 错误:形参‘malloc_slow’已初始化 bool malloc_slow = true; ^ src/jemalloc.c:106:8: 错误:形参‘malloc_slow’重定义 bool malloc_slow = true; ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:8:13: 附注:‘malloc_slow’的上一个定义在此 extern bool malloc_slow; ^ src/jemalloc.c:109:1: 警告:空声明 [默认启用] enum { ^ src/jemalloc.c:116:16: 错误:为形参‘malloc_slow_flags’指定了存储类 static uint8_t malloc_slow_flags; ^ src/jemalloc.c:123:19: 错误:为形参‘malloc_initializer’指定了存储类 static pthread_t malloc_initializer = NO_INITIALIZER; ^ src/jemalloc.c:123:1: 错误:形参‘malloc_initializer’已初始化 static pthread_t malloc_initializer = NO_INITIALIZER; ^ src/jemalloc.c:166:23: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘init_lock’ static malloc_mutex_t init_lock = MALLOC_MUTEX_INITIALIZER; ^ src/jemalloc.c:166:59: 错误:expected declaration specifiers before ‘;’ token static malloc_mutex_t init_lock = MALLOC_MUTEX_INITIALIZER; ^ src/jemalloc.c:173:3: 错误:为形参‘malloc_utrace_t’指定了存储类 } malloc_utrace_t; ^ src/jemalloc.c:192:13: 错误:为形参‘had_conf_error’指定了存储类 static bool had_conf_error = false; ^ src/jemalloc.c:192:1: 错误:形参‘had_conf_error’已初始化 static bool had_conf_error = false; ^ src/jemalloc.c:200:13: 错误:为形参‘malloc_init_hard_a0’指定了存储类 static bool malloc_init_hard_a0(void); ^ src/jemalloc.c:201:13: 错误:为形参‘malloc_init_hard’指定了存储类 static bool malloc_init_hard(void); ^ src/jemalloc.c:209:26: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_initialized(void) { ^ In file included from include/jemalloc/internal/jemalloc_preamble.h:34:0, from src/jemalloc.c:2: include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:213:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE bool ^ include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:221:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE bool ^ src/jemalloc.c:235:52: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token a0ialloc(size_t size, bool zero, bool is_internal) { ^ src/jemalloc.c:245:40: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token a0idalloc(void *ptr, bool is_internal) { ^ src/jemalloc.c:250:23: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token a0malloc(size_t size) { ^ src/jemalloc.c:255:21: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token a0dalloc(void *ptr) { ^ src/jemalloc.c:266:31: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token bootstrap_malloc(size_t size) { ^ src/jemalloc.c:275:43: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token bootstrap_calloc(size_t num, size_t size) { ^ src/jemalloc.c:288:27: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token bootstrap_free(void *ptr) { ^ src/jemalloc.c:297:41: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token arena_set(unsigned ind, arena_t *arena) { ^ src/jemalloc.c:302:37: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token narenas_total_set(unsigned narenas) { ^ src/jemalloc.c:307:25: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token narenas_total_inc(void) { ^ src/jemalloc.c:312:25: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token narenas_total_get(void) { ^ src/jemalloc.c:318:19: 错误:expected declaration specifiers or ‘...’ before ‘tsdn_t’ arena_init_locked(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks) { ^ src/jemalloc.c:318:47: 错误:未知的类型名‘extent_hooks_t’ arena_init_locked(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks) { ^ src/jemalloc.c:346:36: 错误:expected declaration specifiers or ‘...’ before ‘tsdn_t’ arena_new_create_background_thread(tsdn_t *tsdn, unsigned ind) { ^ src/jemalloc.c:364:12: 错误:expected declaration specifiers or ‘...’ before ‘tsdn_t’ arena_init(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks) { ^ src/jemalloc.c:364:40: 错误:未知的类型名‘extent_hooks_t’ arena_init(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks) { ^ src/jemalloc.c:377:12: 错误:expected declaration specifiers or ‘...’ before ‘tsd_t’ arena_bind(tsd_t *tsd, unsigned ind, bool internal) { ^ src/jemalloc.c:397:15: 错误:expected declaration specifiers or ‘...’ before ‘tsd_t’ arena_migrate(tsd_t *tsd, unsigned oldind, unsigned newind) { ^ src/jemalloc.c:408:14: 错误:expected declaration specifiers or ‘...’ before ‘tsd_t’ arena_unbind(tsd_t *tsd, unsigned ind, bool internal) { ^ src/jemalloc.c:422:22: 错误:expected declaration specifiers or ‘...’ before ‘tsd_t’ arena_tdata_get_hard(tsd_t *tsd, unsigned ind) { ^ src/jemalloc.c:499:19: 错误:expected declaration specifiers or ‘...’ before ‘tsd_t’ arena_choose_hard(tsd_t *tsd, bool internal) { ^ src/jemalloc.c:613:16: 错误:expected declaration specifiers or ‘...’ before ‘tsd_t’ iarena_cleanup(tsd_t *tsd) { ^ src/jemalloc.c:623:15: 错误:expected declaration specifiers or ‘...’ before ‘tsd_t’ arena_cleanup(tsd_t *tsd) { ^ src/jemalloc.c:633:22: 错误:expected declaration specifiers or ‘...’ before ‘tsd_t’ arenas_tdata_cleanup(tsd_t *tsd) { ^ src/jemalloc.c:647:26: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token stats_print_atexit(void) { ^ In file included from include/jemalloc/internal/jemalloc_preamble.h:34:0, from src/jemalloc.c:2: include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:683:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE void ^ src/jemalloc.c:712:42: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token jemalloc_secure_getenv(const char *name) { ^ src/jemalloc.c:726:20: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_ncpus(void) { ^ src/jemalloc.c:754:55: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token init_opt_stats_print_opts(const char *v, size_t vlen) { ^ src/jemalloc.c:781:80: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token size_t *vlen_left, size_t *slab_start, size_t *slab_end, size_t *new_size) { ^ src/jemalloc.c:824:39: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token char const **v_p, size_t *vlen_p) { ^ src/jemalloc.c:898:33: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_abort_invalid_conf(void) { ^ src/jemalloc.c:907:18: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token size_t vlen) { ^ src/jemalloc.c:920:29: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_slow_flag_init(void) { ^ src/jemalloc.c:938:67: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token obtain_malloc_conf(unsigned which_source, char buf[PATH_MAX + 1]) { ^ src/jemalloc.c:1023:29: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token char buf[PATH_MAX + 1]) { ^ src/jemalloc.c:1440:74: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_conf_init(sc_data_t *sc_data, unsigned bin_shard_sizes[SC_NBINS]) { ^ src/jemalloc.c:1453:31: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_init_hard_needed(void) { ^ src/jemalloc.c:1479:30: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_init_hard_a0_locked() { ^ src/jemalloc.c:1564:27: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_init_hard_a0(void) { ^ src/jemalloc.c:1575:35: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_init_hard_recursible(void) { ^ src/jemalloc.c:1602:30: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_narenas_default(void) { ^ src/jemalloc.c:1616:55: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token percpu_arena_as_initialized(percpu_arena_mode_t mode) { ^ src/jemalloc.c:1628:27: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_init_narenas(void) { ^ src/jemalloc.c:1704:26: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_init_percpu(void) { ^ src/jemalloc.c:1709:31: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_init_hard_finish(void) { ^ src/jemalloc.c:1721:26: 错误:expected declaration specifiers or ‘...’ before ‘tsdn_t’ malloc_init_hard_cleanup(tsdn_t *tsdn, bool reentrancy_set) { ^ src/jemalloc.c:1733:24: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_init_hard(void) { ^ src/jemalloc.c:1815:30: 错误:为形参‘static_opts_t’指定了存储类 typedef struct static_opts_s static_opts_t; ^ src/jemalloc.c:1816:1: 警告:空声明 [默认启用] struct static_opts_s { ^ In file included from include/jemalloc/internal/jemalloc_preamble.h:34:0, from src/jemalloc.c:2: include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:1863:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE void ^ src/jemalloc.c:1886:31: 错误:为形参‘dynamic_opts_t’指定了存储类 typedef struct dynamic_opts_s dynamic_opts_t; ^ src/jemalloc.c:1887:1: 警告:空声明 [默认启用] struct dynamic_opts_s { ^ In file included from include/jemalloc/internal/jemalloc_preamble.h:34:0, from src/jemalloc.c:2: include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:1898:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE void ^ include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:1911:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE void * ^ include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:1953:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE void * ^ include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:1989:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE bool ^ include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:2027:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE int ^ include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:2227:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE bool ^ include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:2245:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE int ^ src/jemalloc.c:2269:1: 错误:expected declaration specifiers before ‘JEMALLOC_NOINLINE’ JEMALLOC_NOINLINE ^ src/jemalloc.c:2320:1: 错误:未知的类型名‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:2320:36: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_RESTRICT_RETURN’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:2391:1: 错误:expected declaration specifiers before ‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT int JEMALLOC_NOTHROW ^ src/jemalloc.c:2430:1: 错误:未知的类型名‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:2430:36: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_RESTRICT_RETURN’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:2471:1: 错误:未知的类型名‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:2471:36: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_RESTRICT_RETURN’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:2506:22: 错误:expected declaration specifiers or ‘...’ before ‘tsd_t’ irealloc_prof_sample(tsd_t *tsd, void *old_ptr, size_t old_usize, size_t usize, ^ src/jemalloc.c:2507:24: 错误:expected declaration specifiers or ‘...’ before ‘hook_ralloc_args_t’ prof_tctx_t *tctx, hook_ralloc_args_t *hook_args) { ^ In file included from include/jemalloc/internal/jemalloc_preamble.h:34:0, from src/jemalloc.c:2: include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:2528:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE void * ^ include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:2555:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE void ^ include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:2594:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE void ^ src/jemalloc.c:2650:1: 错误:未知的类型名‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:2650:36: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_RESTRICT_RETURN’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:2769:1: 错误:expected declaration specifiers before ‘JEMALLOC_NOINLINE’ JEMALLOC_NOINLINE ^ In file included from include/jemalloc/internal/jemalloc_preamble.h:34:0, from src/jemalloc.c:2: include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:2805:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE ^ src/jemalloc.c:2862:1: 错误:expected declaration specifiers before ‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT void JEMALLOC_NOTHROW ^ src/jemalloc.c:3095:1: 错误:未知的类型名‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:3095:36: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_RESTRICT_RETURN’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:3149:22: 错误:expected declaration specifiers or ‘...’ before ‘tsdn_t’ irallocx_prof_sample(tsdn_t *tsdn, void *old_ptr, size_t old_usize, ^ src/jemalloc.c:3151:24: 错误:expected declaration specifiers or ‘...’ before ‘hook_ralloc_args_t’ prof_tctx_t *tctx, hook_ralloc_args_t *hook_args) { ^ In file included from include/jemalloc/internal/jemalloc_preamble.h:34:0, from src/jemalloc.c:2: include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:3173:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE void * ^ src/jemalloc.c:3213:1: 错误:未知的类型名‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:3213:36: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_RESTRICT_RETURN’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ In file included from include/jemalloc/internal/jemalloc_preamble.h:34:0, from src/jemalloc.c:2: include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:3311:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE size_t ^ src/jemalloc.c:3325:22: 错误:expected declaration specifiers or ‘...’ before ‘tsdn_t’ ixallocx_prof_sample(tsdn_t *tsdn, void *ptr, size_t old_usize, size_t size, ^ In file included from include/jemalloc/internal/jemalloc_preamble.h:34:0, from src/jemalloc.c:2: include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:3338:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE size_t ^ src/jemalloc.c:3389:1: 错误:未知的类型名‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW ^ src/jemalloc.c:3389:24: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_NOTHROW’ JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW ^ src/jemalloc.c:3459:1: 错误:未知的类型名‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW ^ src/jemalloc.c:3459:24: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_NOTHROW’ JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW ^ src/jemalloc.c:3486:1: 错误:expected declaration specifiers before ‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT void JEMALLOC_NOTHROW ^ In file included from include/jemalloc/internal/jemalloc_preamble.h:34:0, from src/jemalloc.c:2: include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:3533:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE size_t ^ src/jemalloc.c:3547:1: 错误:expected declaration specifiers before ‘JEMALLOC_NOINLINE’ JEMALLOC_NOINLINE void ^ src/jemalloc.c:3593:1: 错误:expected declaration specifiers before ‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT void JEMALLOC_NOTHROW ^ src/jemalloc.c:3606:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘je_sdallocx_noflags’ je_sdallocx_noflags(void *ptr, size_t size) { ^ src/jemalloc.c:3617:1: 错误:未知的类型名‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW ^ src/jemalloc.c:3617:24: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_NOTHROW’ JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW ^ src/jemalloc.c:3644:1: 错误:expected declaration specifiers before ‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT int JEMALLOC_NOTHROW ^ src/jemalloc.c:3666:1: 错误:expected declaration specifiers before ‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT int JEMALLOC_NOTHROW ^ src/jemalloc.c:3686:1: 错误:expected declaration specifiers before ‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT int JEMALLOC_NOTHROW ^ src/jemalloc.c:3707:1: 错误:expected declaration specifiers before ‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT void JEMALLOC_NOTHROW ^ src/jemalloc.c:3721:1: 错误:未知的类型名‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW ^ src/jemalloc.c:3721:24: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_NOTHROW’ JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW ^ src/jemalloc.c:3772:1: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ JEMALLOC_ATTR(constructor) ^ src/jemalloc.c:3786:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token { ^ src/jemalloc.c:3860:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token { ^ src/jemalloc.c:3894:31: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token jemalloc_postfork_child(void) { ^ src/jemalloc.c:3927:1: 错误:expected declaration specifiers before ‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT int JEMALLOC_NOTHROW ^ In file included from include/jemalloc/internal/assert.h:1:0, from include/jemalloc/internal/bit_util.h:4, from include/jemalloc/internal/bitmap.h:5, from include/jemalloc/internal/arena_structs_a.h:4, from include/jemalloc/internal/jemalloc_internal_includes.h:53, from src/jemalloc.c:3: include/jemalloc/internal/malloc_io.h:54:8: 错误:原型函数定义中使用了旧式参数声明 size_t malloc_snprintf(char *str, size_t size, const char *format, ...) ^ src/jemalloc.c:3931:1: 错误:expected ‘{’ at end of input } ^ src/jemalloc.c:3931:1: 警告:在有返回值的函数中,控制流程到达函数尾 [-Wreturn-type] } ^ make: *** [src/jemalloc.sym.o] 错误 1
09-24
/*!Copyright(c) 2012-2019 Shenzhen TP-LINK Technologies Co.Ltd. * *\file url_class.c *\brief process for URL query * *\author Wanghao *\version 1.0.0 *\date 27Aug19 * *\history * */ #include <sys/stat.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <sys/socket.h> #include <sys/types.h> #include <string.h> #include <asm/types.h> #include <linux/netlink.h> #include <linux/socket.h> #include <getopt.h> #include <errno.h> #include <avira/auc/aucApi.h> #include <pthread.h> #include <signal.h> #include <sys/time.h> #include <curl/curl.h> #include "cJSON.h" #include <uci.h> #include <mali_url_check.h> #include <fcntl.h> #include <unistd.h> #define printErr(fmt, args...) printf("\033[1m[ %s ] %03d: "fmt"\033[0m", __FUNCTION__, __LINE__, ##args) #define printWar(fmt, args...) printf("\033[1m[ %s ] %03d: "fmt"\033[0m", __FUNCTION__, __LINE__, ##args) #define CURL_DEBUG 0 #define URL_CLASS_LOG_LEVEL LOG_LEVEL_MAX #define URL_CLASS_LOG(level, fmt, args...) \ do \ { \ if (level >= URL_CLASS_LOG_LEVEL) \ { \ static char cmd[1024] = {0}, final[1024+128] = {0}; \ struct timeval tv; \ struct tm* local; \ gettimeofday(&tv, NULL); \ local = localtime(&tv.tv_sec); \ memset(cmd,0,sizeof(cmd));memset(final,0,sizeof(final));\ snprintf(cmd, sizeof(cmd), fmt, ##args); \ snprintf(final, sizeof(final), "echo \"%04d-%02d-%02d %02d:%02d:%02d.%03d|level:%d|%s:%d|%s| - ",\ local->tm_year + 1900, local->tm_mon + 1, local->tm_mday, \ local->tm_hour, local->tm_min, local->tm_sec, (int)(tv.tv_usec / 1000), \ level, __FILE__, __LINE__, __func__); \ int _i = 0, _j = strlen(final); \ for(_i = 0; _i < 1024 && _j < 1024+128-15; _i++,_j++) \ { \ if(cmd[_i] == &#39;\"&#39; || cmd[_i] == &#39;\\&#39; || cmd[_i] == &#39;`&#39; || cmd[_i] == &#39;$&#39;) \ { \ final[_j++] = &#39;\\&#39;; \ } \ final[_j] = cmd[_i]; \ } \ strncpy(final + (final[strlen(final) - 1] == &#39;\n&#39;? strlen(final)-1: strlen(final)), "\"> /dev/console", 16); \ system(final); \ } \ } while (0) #define MIN(a,b) ((a)<(b) ? (a):(b)) #define MALI_MAX_WAIT_TIME 1024 typedef enum { LOG_LEVEL_DEBUG = 0, // log level debug LOG_LEVEL_INFO, // log level information LOG_LEVEL_WARN, // log level warning LOG_LEVEL_ERROR, // log level error LOG_LEVEL_EMRG, // log level emergency LOG_LEVEL_MAX }E_LOG_LEVE; struct Options { bool use_tp_service; }; struct Options opts; #define MAX_PAYLOAD 1024 // maximum payload size #ifndef NETLINK_URL_CLASS #define NETLINK_URL_CLASS 27 #endif //#define MAX_URL_ENTRY_LEN 512//256 #define MAX_URL_LEN 256 #define MAX_URL_CAT_DEFAULT 9999 #define PCTL_WEB_URL_ID_ALL 0xfffe #if SUPPORT_CLOUD_UPDATE_AUC_INFO #define POST_TRANSFER_TIMEOUT 20 #define POST_CONNECT_TIMEOUT 20 #define AUC_UPDATE_TIME_INTERVAL_DEFAULT 3600 //1h #define AUC_UPDATE_TIME_INTERVAL_FAST 10 //10s #define REQUEST_TIMEOUT_MS 8000 #define MAX_TOKEN_LEN 128 #define FILE_CLOUD_TOKEN_HOMECARE "/tmp/cloud/cloud_token_homecare" #define GET_AUC_URL_POSTFIX "/v1/configuration/auc-service-info" #define CA_CRT_PATH "/etc/certificate/2048_newroot.cer" struct auc_update_status_info { int update_time_interval; time_t updata_time_stamp_last; }; static struct auc_update_status_info auc_update_status = { .update_time_interval = AUC_UPDATE_TIME_INTERVAL_DEFAULT, .updata_time_stamp_last = 0, }; typedef struct _st_http_resinfo { long status_code; }st_http_resinfo; #endif enum url_req { URL_REQ_VOID = 0, URL_REQ_HELLO, URL_REQ_CAT, URL_REQ_LOG, URL_REQ_LOG_HISTORY, URL_REQ_BYE, URL_REQ_END }; struct url_carrier { int id; int info_id; unsigned char url_len; unsigned int cat_id; unsigned int cat_map; char url[MAX_URL_LEN]; }; enum url_process_status { URL_PROCESS_READY = 0, //waiting for auc process URL_PROCESSING //auc is processing, changing url is useless }; struct url_entry { int id; int info_id; unsigned int cat_map; unsigned char query; unsigned char url_len; enum url_process_status process_flag; struct url_entry *prev; struct url_entry *next; char url[MAX_URL_LEN]; }; pthread_mutex_t url_lock = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t mali_url_check_lock = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; //struct url_entry url_array[MAX_URL_ENTRY_LEN]; struct url_entry *url_array; static struct url_entry url_list = { .id = 0, .info_id = 0, .cat_map = 0, .query = 0, .url_len = 0, .prev = NULL, .next = NULL, }; int sock_fd = -1; //cat mapping table int mapping_table[][32] = { {1, 274, 276, 374, 132, -1}, //1100, 1-Games {2, 193, 447, 449, -1}, //1000, 2-Download {3, 222, 223, 224, 357, -1}, //900, 3-Media {4, 107, 388, -1}, //800, 4-Pay-to-surf & Shopping {5, 414, 445, -1}, //700, 5-Social Networking {6, 359, 360, 355, 293, 397, 450, 451, -1}, //600, 6-Oline Communications and Search {7, 443, -1}, //500, 7-Gambling {10, 241, 179, 76, 170, 167, -1}, //200, 10-Sex Education {11, 234, 400, 269, 444, 446, 395, 429, 391, 390, 103, 64, 65, 66, 149, 452, 453, 442, -1}, //100, 11-Adult Content {13, 2, -1}, //000, unsafe, 13-Malware {14, 3, -1}, //000, unsafe, 14-Phishing {15, 197, -1}, // 15-web_search {12, MAX_URL_CAT_DEFAULT, -1}, //2000, 12-Other(Default) {-1} //END }; static inline void strncpy_safe(char *__dest, const char *__src, size_t __n) { strncpy(__dest, __src, __n); __dest[__n] = &#39;\0&#39;; } static void on_exit_handler() { struct sockaddr_nl dest_addr; struct nlmsghdr *nlh = NULL; struct iovec iov; struct msghdr msg; int state_smg = 0; nlh = (struct nlmsghdr *)malloc(NLMSG_SPACE(MAX_PAYLOAD)); if (!nlh) { printErr("malloc nlmsghdr error!\n"); close(sock_fd); return; } //say bye to kernel memset(nlh,0,NLMSG_SPACE(MAX_PAYLOAD)); memset(&dest_addr,0,sizeof(dest_addr)); dest_addr.nl_family = AF_NETLINK; dest_addr.nl_pid = 0; dest_addr.nl_groups = 0; nlh->nlmsg_len = NLMSG_SPACE(MAX_PAYLOAD); nlh->nlmsg_pid = 0; nlh->nlmsg_flags = 0; nlh->nlmsg_type = URL_REQ_BYE; iov.iov_base = (void *)nlh; iov.iov_len = NLMSG_SPACE(MAX_PAYLOAD); memset(&msg, 0, sizeof(msg)); msg.msg_name = (void *)&dest_addr; msg.msg_namelen = sizeof(dest_addr); msg.msg_iov = &iov; msg.msg_iovlen = 1; state_smg = sendmsg(sock_fd, &msg, 0); if (state_smg < 0) { printErr("get error sendmsg = %s\n",strerror(errno)); } if (nlh) { free(nlh); } close(sock_fd); return; } static void signal_exit_handler(int sig) { exit(0); } static int url_send(int id, unsigned int cat_id, char *url, unsigned char url_len, unsigned short type) { struct nlmsghdr *nlh = NULL; struct iovec iov; struct msghdr msg; struct sockaddr_nl dest_addr; struct url_carrier data; int state_smg = 0; int ret = 0; nlh = (struct nlmsghdr *)malloc(NLMSG_SPACE(MAX_PAYLOAD)); if (!nlh) { printErr("malloc nlmsghdr error!\n"); return -1; } memset(&dest_addr,0,sizeof(dest_addr)); dest_addr.nl_family = AF_NETLINK; dest_addr.nl_pid = 0; dest_addr.nl_groups = 0; nlh->nlmsg_len = NLMSG_SPACE(MAX_PAYLOAD); nlh->nlmsg_pid = getpid(); nlh->nlmsg_flags = 0; nlh->nlmsg_type = type; memset(&data, 0, sizeof(struct url_carrier)); data.id = id; data.cat_id = cat_id; data.url_len = url_len; strncpy_safe(data.url, url, url_len); printWar("url_send to kernel, id=%d, cat_id=%x, url=%s, url_len=%d \n", data.id, data.cat_id, data.url, data.url_len); memcpy(NLMSG_DATA(nlh), &data, sizeof(struct url_carrier)); iov.iov_base = (void *)nlh; iov.iov_len = NLMSG_SPACE(MAX_PAYLOAD); memset(&msg, 0, sizeof(msg)); msg.msg_name = (void *)&dest_addr; msg.msg_namelen = sizeof(dest_addr); msg.msg_iov = &iov; msg.msg_iovlen = 1; state_smg = sendmsg(sock_fd, &msg, 0); if (state_smg < 0) { printErr("get error sendmsg = %s\n",strerror(errno)); ret = -1; goto out; } out: if (nlh) { free(nlh); } return ret; } static void __attribute__((unused)) dump_list(struct url_entry *list) { printErr("dump:\n"); while (list) { printWar("id=%d url=%s\n", list->id, list->url); list = list->next; } } static void cond_timedwait(long timeout) { struct timespec abstime; struct timeval now; long nsec = 0; pthread_mutex_lock(&url_lock); gettimeofday(&now, NULL); nsec = now.tv_usec * 1000 + (timeout % 1000) * 1000000; abstime.tv_sec=now.tv_sec + nsec / 1000000000 + timeout / 1000; abstime.tv_nsec=nsec % 1000000000; pthread_cond_timedwait(&cond, &url_lock, &abstime); pthread_mutex_unlock(&url_lock); } #if SUPPORT_CLOUD_UPDATE_AUC_INFO static int OnDebug(CURL * curl, curl_infotype itype, char * pData, size_t size, void *lpVoid) { if (itype == CURLINFO_TEXT) { //URL_CLASS_LOG(LOG_LEVEL_DEBUG,"[TEXT]%s", pData); } else if (itype == CURLINFO_HEADER_IN) { URL_CLASS_LOG(LOG_LEVEL_DEBUG, "[HEADER_IN]%s", pData); } else if (itype == CURLINFO_HEADER_OUT) { URL_CLASS_LOG(LOG_LEVEL_DEBUG, "[HEADER_OUT]%s", pData); } else if (itype == CURLINFO_DATA_IN) { URL_CLASS_LOG(LOG_LEVEL_DEBUG, "[DATA_IN]%s", pData); } else if (itype == CURLINFO_DATA_OUT) { URL_CLASS_LOG(LOG_LEVEL_DEBUG, "[DATA_OUT]%s", pData); } return 0; } static size_t OnWriteData_Post(void* buffer, size_t size, size_t nmemb, void* lpVoid) { if (NULL == buffer) { return -1; } unsigned int len = (unsigned int)size * (unsigned int)nmemb; char *str = (char*)malloc(len + 1); if (NULL == str) { return -1; } char* pData = (char*)buffer; memset(str, 0, len + 1); memcpy(str, pData, len); URL_CLASS_LOG(LOG_LEVEL_DEBUG, "response: %s\n", str); char **response = (char**)lpVoid; *response = str; return len; } static size_t cloud_https_post(const char *pUrl, const char *requestHeader, const char *request, char **response, st_http_resinfo *pHttpResInfo) { CURLcode res; CURL* curl = NULL; struct curl_slist *headers = NULL; #ifdef CURL_DEBUG char errbuf[CURL_ERROR_SIZE]; memset(errbuf, &#39;\0&#39;, CURL_ERROR_SIZE); #endif if (NULL == pUrl || NULL == request || NULL == response || NULL == pHttpResInfo) { return CURLE_FAILED_INIT; } URL_CLASS_LOG(LOG_LEVEL_DEBUG, "pUrl:%s\n requestHeader:%s\n request:%s\n", pUrl, requestHeader, request); res = curl_global_init(CURL_GLOBAL_ALL); if (CURLE_OK != res) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "curl global init fail and ret %d", res); return res; } curl = curl_easy_init(); if (NULL == curl) { res = CURLE_FAILED_INIT; URL_CLASS_LOG(LOG_LEVEL_ERROR, "curl init fail"); goto exit; } //headers = curl_slist_append(headers, "Content-Type: application/json;charset=UTF-8"); headers = curl_slist_append(headers, "Content-Type: application/json"); if (NULL == headers) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "curl get header list fail"); goto exit; } if ((NULL != requestHeader) && (0 < strlen(requestHeader))) { URL_CLASS_LOG(LOG_LEVEL_DEBUG, "requestHeader is %s", requestHeader); headers = curl_slist_append(headers, requestHeader); if (NULL == headers) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "curl append requestHeader fail"); goto exit; } } #ifdef CURL_DEBUG //provide a buffer to store errors in res = curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); if (CURLE_OK != res) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "curl set option CURLOPT_ERRORBUFFER ret %d", res); goto exit; } #endif if (CURL_DEBUG) { URL_CLASS_LOG(LOG_LEVEL_DEBUG, "post sesstion debug on"); res = curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); if (CURLE_OK != res) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "curl set option CURLOPT_VERBOSE ret %d", res); goto exit; } res = curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, OnDebug); if (CURLE_OK != res) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "curl set option CURLOPT_DEBUGFUNCTION ret %d", res); goto exit; } } //set url res = curl_easy_setopt(curl, CURLOPT_URL, pUrl); if (CURLE_OK != res) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "curl set option CURLOPT_URL ret %d", res); goto exit; } //set header res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); if (CURLE_OK != res) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "curl set option CURLOPT_HTTPHEADER ret %d", res); goto exit; } //set post method res = curl_easy_setopt(curl, CURLOPT_POST, 1); if (CURLE_OK != res) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "curl set option CURLOPT_POST ret %d", res); goto exit; } res = curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request); if (CURLE_OK != res) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "curl set option CURLOPT_POSTFIELDS ret %d", res); goto exit; } //set read/write params res = curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL); if (CURLE_OK != res) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "curl set option CURLOPT_READFUNCTION ret %d", res); goto exit; } res = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, OnWriteData_Post); if (CURLE_OK != res) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "curl set option CURLOPT_WRITEFUNCTION ret %d", res); goto exit; } res = curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)response); if (CURLE_OK != res) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "curl set option CURLOPT_WRITEDATA ret %d", res); goto exit; } res = curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); if (CURLE_OK != res) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "curl set option CURLOPT_NOSIGNAL ret %d", res); goto exit; } //set certificate info res = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1); if (CURLE_OK != res) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "curl set option CURLOPT_SSL_VERIFYPEER ret %d", res); goto exit; } res = curl_easy_setopt(curl, CURLOPT_CAINFO, CA_CRT_PATH); if (CURLE_OK != res) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "curl set option CURLOPT_CAINFO ret %d", res); goto exit; } //set CURLOPT_CONNECTTIMEOUT res = curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, POST_TRANSFER_TIMEOUT); if (CURLE_OK != res) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "curl set option CURLOPT_CONNECTTIMEOUT ret %d", res); goto exit; } //set CURLOPT_TIMEOUT res = curl_easy_setopt(curl, CURLOPT_TIMEOUT, POST_CONNECT_TIMEOUT); if (CURLE_OK != res) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "curl set option CURLOPT_TIMEOUT ret %d", res); goto exit; } //CURLOPT needs to be set_ FOLLOWLOCATION is 1, otherwise, the data after redirecting will not be returned res = curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION,1); if (CURLE_OK != res) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "curl set option CURLOPT_FOLLOWLOCATION ret %d", res); goto exit; } res = curl_easy_perform(curl); #ifdef CURL_DEBUG if(CURLE_OK != res) { URL_CLASS_LOG(LOG_LEVEL_DEBUG, "curl post return error: %s", errbuf); } #endif curl_easy_getinfo(curl, CURLINFO_HTTP_CODE, &(pHttpResInfo->status_code)); URL_CLASS_LOG(LOG_LEVEL_DEBUG, "cloud_https_post done. ret %d, http status code %d", res, pHttpResInfo->status_code); exit: if (headers) { curl_slist_free_all(headers); } if (curl) { curl_easy_cleanup(curl); } curl_global_cleanup(); return res; } static int get_token_url(char *token, char *url) { int ret = -1; int retry_count = 3; FILE *fp = NULL; while (retry_count > 0) { if(fp = fopen(FILE_CLOUD_TOKEN_HOMECARE, "r")) { fscanf(fp, "%s", token); fscanf(fp, "%s", url); fclose(fp); ret = 0; break; } else { system("cloud_getDevToken homecare"); } retry_count--; } if ((*(token + MAX_TOKEN_LEN - 1) != 0) || (*(url + MAX_URL_LEN - 1) != 0)) { URL_CLASS_LOG(LOG_LEVEL_WARN, "token or url pointer out of range"); ret = -1; } return ret; } static char* get_auc_info_from_cloud_request_data() { int ret = -1; cJSON* request_data_json = NULL; char* request_data = NULL; unsigned char country_code[3] = {0}; FILE *fp = NULL; if ((request_data_json = cJSON_CreateObject()) == NULL) { goto out; } if (fp = popen("getfirm COUNTRY | tr &#39;A-Z&#39; &#39;a-z&#39;", "r")) { if (fread(country_code, sizeof(char), 2, fp) > 0) { cJSON_AddStringToObject(request_data_json, (const char*)"region", (const char*)country_code); request_data = cJSON_PrintUnformatted(request_data_json); URL_CLASS_LOG(LOG_LEVEL_DEBUG, "request_data:%s", request_data); } pclose(fp); } cJSON_Delete(request_data_json); return request_data; out: return NULL; } static int get_auc_info_from_cloud(struct auc_info *auc_info, char *device_token, char *url_prefix) { int ret = -1; int ret_post = 0; char request_url[MAX_URL_LEN] = {0}; char request_header[MAX_TOKEN_LEN + 32] = {0}; char *request_data = NULL; char *response = NULL; st_http_resinfo httpResInfo; cJSON* response_json = NULL; cJSON* auc_server_json= NULL; cJSON* api_key_json = NULL; cJSON* user_guid_json = NULL; if (auc_info == NULL || device_token == NULL || url_prefix == NULL) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "params error\n"); return ret; } memset(&httpResInfo, 0, sizeof(st_http_resinfo)); snprintf(request_url, MAX_URL_LEN, "%s%s", url_prefix, GET_AUC_URL_POSTFIX); snprintf(request_header, MAX_TOKEN_LEN + 32, "Authorization: %s", device_token); request_data = get_auc_info_from_cloud_request_data(); //get post result ret_post = cloud_https_post(request_url, request_header, request_data, &response, &httpResInfo); URL_CLASS_LOG(LOG_LEVEL_DEBUG, "curl post return %d http retcode: %ld", ret_post, httpResInfo.status_code); if(request_data) { cJSON_free(request_data); } if (response && httpResInfo.status_code == 200) { response_json = cJSON_Parse(response); auc_server_json= cJSON_GetObjectItem(response_json, "aucServerUrl"); api_key_json = cJSON_GetObjectItem(response_json, "apiKey"); user_guid_json = cJSON_GetObjectItem(response_json, "userGuid"); if (auc_server_json->valuestring && api_key_json->valuestring && user_guid_json->valuestring) { snprintf(auc_info->auc_server, MAX_AUC_SERVER_LEN, "%s", auc_server_json->valuestring); snprintf(auc_info->api_key, MAX_API_KEY_LEN, "%s", api_key_json->valuestring); snprintf(auc_info->user_guid, MAX_USER_GUID, "%s", user_guid_json->valuestring); ret = 0; } } out: cJSON_Delete(response_json); return ret; } static void set_retry_time_interval(void) { if (auc_update_status.update_time_interval == AUC_UPDATE_TIME_INTERVAL_DEFAULT) { auc_update_status.update_time_interval = AUC_UPDATE_TIME_INTERVAL_FAST; } else if (auc_update_status.update_time_interval < AUC_UPDATE_TIME_INTERVAL_DEFAULT && (auc_update_status.update_time_interval * 2) < AUC_UPDATE_TIME_INTERVAL_DEFAULT) { auc_update_status.update_time_interval = auc_update_status.update_time_interval * 2; } else { auc_update_status.update_time_interval = AUC_UPDATE_TIME_INTERVAL_DEFAULT; } } static void update_libauc_url(struct auc_info *auc_info, bool use_tp_service) { char device_token[MAX_TOKEN_LEN] = {0}; char cloud_homecare_url[MAX_URL_LEN] = {0}; time_t time_stamp; memset(device_token, 0, MAX_TOKEN_LEN); memset(cloud_homecare_url, 0, MAX_URL_LEN); memset(auc_info->auc_server, 0, MAX_AUC_SERVER_LEN); memset(auc_info->api_key, 0, MAX_API_KEY_LEN); memset(auc_info->user_guid, 0, MAX_USER_GUID); //get time stamp time(&time_stamp); URL_CLASS_LOG(LOG_LEVEL_DEBUG, "start time_stamp:%d, updata_time_stamp_last:%d, update_time_interval:%d\n", time_stamp, auc_update_status.updata_time_stamp_last, auc_update_status.update_time_interval); if ((time_stamp - auc_update_status.updata_time_stamp_last) >= auc_update_status.update_time_interval) { if(use_tp_service) { if (0 == (get_token_url(device_token, cloud_homecare_url))) { memset(auc_info->tp_auc_server, 0, MAX_AUC_SERVER_LEN); snprintf(auc_info->tp_auc_server, MAX_AUC_SERVER_LEN, "%s", cloud_homecare_url); auc_update_status.updata_time_stamp_last = time_stamp; auc_update_status.update_time_interval = AUC_UPDATE_TIME_INTERVAL_DEFAULT; } else { auc_update_status.updata_time_stamp_last = time_stamp; set_retry_time_interval(); } } else { if (0 == (get_token_url(device_token, cloud_homecare_url))) { if (0 == get_auc_info_from_cloud(auc_info, device_token, cloud_homecare_url)) { auc_update_status.updata_time_stamp_last = time_stamp; auc_update_status.update_time_interval = AUC_UPDATE_TIME_INTERVAL_DEFAULT; } else { auc_update_status.updata_time_stamp_last = time_stamp; set_retry_time_interval(); } } else { auc_update_status.updata_time_stamp_last = time_stamp; set_retry_time_interval(); } } } else { } URL_CLASS_LOG(LOG_LEVEL_DEBUG, "end time_stamp:%d, updata_time_stamp_last:%d, update_time_interval:%d\n", time_stamp, auc_update_status.updata_time_stamp_last, auc_update_status.update_time_interval); URL_CLASS_LOG(LOG_LEVEL_DEBUG, "auc_server:%s, tp_auc_server:%s, api_key:%s, user_guid:%s\n", auc_info->auc_server, auc_info->tp_auc_server, auc_info->api_key, auc_info->user_guid); return; } #endif static void *mali_checkQuery(void *unused) { int ret = 0; int ret_mali = 0; int failed_num = 0; unsigned int wait_time = 0; parse_para para = {0, 0, 0}; srand((uint32_t)getpid()); while (1) { ret = parse_config(&para); if(0 == ret) { if ((web_protection)&&(para.web_protection)) { ret_mali = mali_url_hash_list_update(true); if (ret_mali < 0) { if (!failed_num) wait_time = 2 + (rand() % 254); else if (wait_time < MALI_MAX_WAIT_TIME) wait_time <<= 1; failed_num++; sleep(MIN(wait_time, MALI_MAX_WAIT_TIME)); } else { if (!access(CLOUD_HASH_FILE_UPDATE_FLAG, R_OK)) { pthread_mutex_lock(&mali_url_check_lock); mali_url_hash_list_update(false); pthread_mutex_unlock(&mali_url_check_lock); } failed_num = 0; } } else if ((web_protection)&&(!para.web_protection)) { pthread_mutex_lock(&mali_url_check_lock); mali_url_check_free(); web_protection = false; pthread_mutex_unlock(&mali_url_check_lock); failed_num = 0; } else if ((!web_protection)&&(para.web_protection)) { pthread_mutex_lock(&mali_url_check_lock); ret_mali = mali_url_check_init(false); if (0 == ret_mali) { web_protection = true; pthread_mutex_unlock(&mali_url_check_lock); failed_num = 0; } else { pthread_mutex_unlock(&mali_url_check_lock); if (!failed_num) wait_time = 2 + (rand() % 254); else if (wait_time < MALI_MAX_WAIT_TIME) wait_time <<= 1; failed_num++; sleep(MIN(wait_time, MALI_MAX_WAIT_TIME)); } } } sleep(5); } } void write_to_csv(const char *url, int original_cat_id, int mapped_cat_id, const char *category_name) { int fd = open("/var/auc_classification_results.csv", O_CREAT | O_WRONLY | O_APPEND, 0644); if (fd != -1) { char buffer[512]; const char *name = (category_name != NULL) ? category_name : ""; // 处理NULL情况 snprintf(buffer, sizeof(buffer), "%s,%d,%d,%s\n", url, original_cat_id, mapped_cat_id, name); // 添加名称列 write(fd, buffer, strlen(buffer)); close(fd); } } static void *aucQuery(void *unused) { int ret = 0; struct url_info url_info; bool is_mali = false; #if SUPPORT_CLOUD_UPDATE_AUC_INFO struct auc_info auc_info; #endif unsigned int cat_id = 0; int tmp_id = 0; int index = 0; int index_cat = 0; int index_subcat = 0; unsigned char matched = 0; struct url_entry *tmp_list = NULL; struct url_entry *clean = NULL; unsigned char tmp_url_len; char tmp_url[MAX_URL_LEN] = {0}; printWar("create AUC query thread\n"); while (1) { pthread_mutex_lock(&url_lock); tmp_list = url_list.next; pthread_mutex_unlock(&url_lock); while (tmp_list) { pthread_mutex_lock(&url_lock); tmp_list->process_flag = URL_PROCESSING; pthread_mutex_unlock(&url_lock); url_info.url = tmp_list->url; url_info.info_len = 0; ret = pthread_mutex_trylock(&mali_url_check_lock); if (!ret) { is_mali = web_protection? is_url_malicious(url_info.url) : false; if (is_mali) { cat_id = URL_CAT_SECURITY; URL_CLASS_LOG(LOG_LEVEL_DEBUG, "Malicious URL detected. URL: %s, Original Cat ID: %d, Mapped Cat ID: %d", url_info.url, cat_id, cat_id); #if DEBUG printWar("cat ret=%d url=%s id=%d info_id=%d\n", cat_id, url_info.url, tmp_list->id, tmp_list->info_id); #endif /* DEBUG */ pthread_mutex_lock(&url_lock); tmp_list->prev->next = tmp_list->next; if (tmp_list->next) { tmp_list->next->prev = tmp_list->prev; } tmp_list->query = 1; tmp_id = tmp_list->id; tmp_list->id = 0; tmp_list->info_id = 0; tmp_list->cat_map = 0; tmp_url_len = tmp_list->url_len; memset(tmp_url, 0, MAX_URL_LEN); strncpy_safe(tmp_url, tmp_list->url, tmp_list->url_len); clean = tmp_list; tmp_list = tmp_list->next; clean->next = NULL; clean->prev = NULL; pthread_mutex_unlock(&url_lock); pthread_mutex_unlock(&mali_url_check_lock); write_to_csv(url_info.url, cat_id, cat_id, "Security"); goto block_mali; } else { pthread_mutex_unlock(&mali_url_check_lock); } } if((!opts.use_tp_service && tmp_list->cat_map) || (opts.use_tp_service && (tmp_list->info_id != PCTL_WEB_URL_ID_ALL) && (tmp_list->cat_map & (~URL_CAT_SECURITY)))) { printWar("before send to auc\n"); #if SUPPORT_CLOUD_UPDATE_AUC_INFO update_libauc_url(&auc_info, opts.use_tp_service); ret = auc_query(&url_info, &auc_info, opts.use_tp_service); #else ret = auc_query(&url_info, opts.use_tp_service); #endif printWar("after send to auc\n"); for (index = 0; index < url_info.info_len; index++) { printWar("cat ret=%d url=%s id=%d name=%s\n", ret, url_info.url, url_info.info[index].id, url_info.info[index].name); } } //remove from url_list pthread_mutex_lock(&url_lock); tmp_list->prev->next = tmp_list->next; if (tmp_list->next) { tmp_list->next->prev = tmp_list->prev; } tmp_list->query = 1; tmp_id = tmp_list->id; tmp_list->id = 0; tmp_list->info_id = 0; tmp_list->cat_map = 0; tmp_url_len = tmp_list->url_len; memset(tmp_url, 0, MAX_URL_LEN); strncpy_safe(tmp_url, tmp_list->url, tmp_list->url_len); clean = tmp_list; tmp_list = tmp_list->next; clean->next = NULL; clean->prev = NULL; pthread_mutex_unlock(&url_lock); //send to kernel cat_id = 0; int original_cat_id = 0; const char *category_name = ""; for (index = 0; index < url_info.info_len; index++) { original_cat_id = url_info.info[index].id; category_name = url_info.info[index].name; int cat_id = 0; // 每次循环初始化 cat_id URL_CLASS_LOG(LOG_LEVEL_DEBUG, "Non-malicious URL. URL: %s, Original Cat ID: %d, Mapped Cat ID: %d", url_info.url, original_cat_id, cat_id); for (index_cat = 0; mapping_table[index_cat][0] > 0; index_cat++) { matched = 0; for (index_subcat = 1; mapping_table[index_cat][index_subcat] >= 0; index_subcat++) { if (url_info.info[index].id == mapping_table[index_cat][index_subcat] || mapping_table[index_cat][index_subcat] == MAX_URL_CAT_DEFAULT) { cat_id |= 0x1 << (mapping_table[index_cat][0] - 1); matched = 1; break; } } if (matched) { break; } } // 将结果写入CSV文件 write_to_csv(url_info.url, original_cat_id, cat_id, category_name); } block_mali: printWar("send to kernel, url=%s cat_id=%x\n", url_info.url, cat_id); url_send(tmp_id, cat_id, tmp_url, tmp_url_len, URL_REQ_CAT); printWar("after send to kernel\n"); } cond_timedwait(500);//500ms } return 0; } static const char* short_opt = "s:h"; static struct option long_opt[] = { {"server" , required_argument , NULL, &#39;a&#39;}, {"help" , no_argument , NULL, &#39;h&#39;}, {0 , 0 , NULL, 0 } }; static void printHelp(char *progName); static int parseOpts(int argc, char* argv[], struct Options* opt); static void printHelpInstruction(char *progName); static unsigned int get_max_url_entry_len(void) { unsigned int *url_entry_len = NULL; int state; struct msghdr msg; struct iovec iov; struct nlmsghdr *nlh = NULL; nlh = (struct nlmsghdr *)malloc(NLMSG_SPACE(MAX_PAYLOAD)); if (!nlh) { printErr("malloc nlmsghdr error!\n"); return 0; } nlh->nlmsg_len = NLMSG_SPACE(MAX_PAYLOAD); nlh->nlmsg_pid = getpid(); nlh->nlmsg_flags = 0; nlh->nlmsg_type = URL_REQ_HELLO; iov.iov_base = (void *)nlh; iov.iov_len = NLMSG_SPACE(MAX_PAYLOAD); memset(&msg, 0, sizeof(msg)); msg.msg_name = NULL; msg.msg_namelen = 0; msg.msg_iov = &iov; msg.msg_iovlen = 1; if (sock_fd < 0) { printErr("error getting socket in recving: %s\n", strerror(errno)); return 0; } state = recvmsg(sock_fd, &msg, 0); if(state < 0) { printWar("state<1\n"); return 0; } //store to array url_entry_len = (unsigned int *)NLMSG_DATA(nlh); URL_CLASS_LOG(LOG_LEVEL_DEBUG, "msg from kernel, max_url_entry_len=%u\n", *url_entry_len); return *url_entry_len; } int main(int argc, char* argv[]) { int state; struct sockaddr_nl src_addr, dest_addr; struct nlmsghdr *nlh = NULL; struct iovec iov; struct msghdr msg; int retval; int state_smg = 0; pthread_t pid, pid_mali; int pret = 0; struct url_carrier *tmp = NULL; int index; pid_t fpid = 0; int ret = 0; int rc = parseOpts(argc, argv, &opts); unsigned int url_entry_len = 0; unsigned int malloc_url_entry_len = 0; if (!rc) { return 1; } fpid = fork(); if (fpid < 0) { printErr("error fork.../n"); exit(1); } else if (fpid > 0) { exit(0); } //setup exit handler atexit(on_exit_handler); signal(SIGTERM, signal_exit_handler); signal(SIGINT, signal_exit_handler); // Create a socket sock_fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_URL_CLASS); if (sock_fd < 0) { printErr("error getting socket: %s\n", strerror(errno)); return -1; } int send_buf = 4096; int recv_buf = 4096; if(setsockopt(sock_fd, SOL_SOCKET, SO_SNDBUF, &send_buf, sizeof(send_buf)) < 0) { printErr("setsockopt: %s", strerror(errno)); } if(setsockopt(sock_fd, SOL_SOCKET, SO_RCVBUF, &recv_buf, sizeof(recv_buf)) < 0) { printErr("setsockopt: %s", strerror(errno)); } // To prepare binding memset(&src_addr, 0, sizeof(src_addr)); src_addr.nl_family = AF_NETLINK; src_addr.nl_pid = getpid(); src_addr.nl_groups = 0; retval = bind(sock_fd, (struct sockaddr*)&src_addr, sizeof(src_addr)); if (retval < 0) { printErr("bind failed: %s\n", strerror(errno)); ret = -1; goto exit; } nlh = (struct nlmsghdr *)malloc(NLMSG_SPACE(MAX_PAYLOAD)); if (!nlh) { printErr("malloc nlmsghdr error!\n"); ret = -1; goto exit; } memset(&dest_addr,0,sizeof(dest_addr)); dest_addr.nl_family = AF_NETLINK; dest_addr.nl_pid = 0; dest_addr.nl_groups = 0; nlh->nlmsg_len = NLMSG_SPACE(MAX_PAYLOAD); nlh->nlmsg_pid = getpid(); nlh->nlmsg_flags = 0; nlh->nlmsg_type = URL_REQ_HELLO; iov.iov_base = (void *)nlh; iov.iov_len = NLMSG_SPACE(MAX_PAYLOAD); memset(&msg, 0, sizeof(msg)); msg.msg_name = (void *)&dest_addr; msg.msg_namelen = sizeof(dest_addr); msg.msg_iov = &iov; msg.msg_iovlen = 1; state_smg = sendmsg(sock_fd, &msg, 0);//Hello to kernel if (state_smg < 0) { printErr("get error sendmsg = %s\n",strerror(errno)); ret = -1; goto exit; } url_entry_len = get_max_url_entry_len(); if(url_entry_len == 0) { printErr("error getting url_entry_len\n"); ret = -1; goto exit; } malloc_url_entry_len = url_entry_len * 2.5;//double for backup, ex. id=1 recv and querying, but id=1 deleted by xt_pctl, then another id=1 recv, place it at url_entry_len+1 //if third/fourth... id=1 recv, they are insert in 2*url_entry_len~2.5*url_entry_len in order url_array = (struct url_entry *)malloc(malloc_url_entry_len * sizeof(struct url_entry)); if (!nlh) { printErr("malloc url_array error!\n"); ret = -1; goto exit; } //mali_checkQuery thread and AUC query thread if (pthread_mutex_init(&mali_url_check_lock, NULL) != 0 ) { printErr("mali_checkQuery pthread_mutex_init failed...%d\n", pret); ret = -1; goto exit; } if (pthread_mutex_init(&url_lock, NULL) != 0 || pthread_cond_init(&cond, NULL) != 0) { printErr("auc pthread_mutex_init failed...%d\n", pret); ret = -1; goto exit; } if ((pret = pthread_create(&pid_mali, NULL, mali_checkQuery, NULL)) != 0){ printErr("mali_checkQuery pthread_create failed...%d\n", pret); ret = -1; goto exit; } if ((pret = pthread_create(&pid, NULL, aucQuery, NULL)) != 0){ printErr("auc pthread_create failed...%d\n", pret); ret = -1; goto exit; } memset(url_array, 0, malloc_url_entry_len * sizeof(struct url_entry)); memset(nlh,0,NLMSG_SPACE(MAX_PAYLOAD));//ready to recv kernel info while (1) { state = recvmsg(sock_fd, &msg, 0); if(state < 0) { printWar("state<1\n"); } //store to array tmp = (struct url_carrier *)NLMSG_DATA(nlh); index = tmp->id; //URL_CLASS_LOG(LOG_LEVEL_DEBUG, "msg from kernel, url=%s len=%d id=%d", tmp->url, tmp->url_len, tmp->id); pthread_mutex_lock(&url_lock); if(index >= url_entry_len) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "Error: xt_pctl url entry size is larger than url_class(%u)!", url_entry_len); pthread_mutex_unlock(&url_lock); continue; } if (url_array[index].prev) {//this node is already in list if(url_array[index].url_len != tmp->url_len || strncmp(url_array[index].url, tmp->url, tmp->url_len) || url_array[index].info_id != tmp->info_id || url_array[index].cat_map != tmp->cat_map) { URL_CLASS_LOG(LOG_LEVEL_DEBUG, "Different node already in list, old_url=%s old_len=%d id=%d, old_process_flag=%d", url_array[index].url, url_array[index].url_len, url_array[index].id, url_array[index].process_flag); if(url_array[index].process_flag == URL_PROCESS_READY) {//Still can modify url_array[index].url_len = tmp->url_len; url_array[index].info_id = tmp->info_id; url_array[index].cat_map = tmp->cat_map; strncpy_safe(url_array[index].url, tmp->url, tmp->url_len); pthread_cond_signal(&cond); pthread_mutex_unlock(&url_lock); URL_CLASS_LOG(LOG_LEVEL_DEBUG, "Replace url=%s at url_array[%d]\n", tmp->url, index); continue; } else { index = url_entry_len + tmp->id; if (url_array[index].prev) { if(url_array[index].url_len == tmp->url_len && !strncmp(url_array[index].url, tmp->url, tmp->url_len) && url_array[index].info_id == tmp->info_id && url_array[index].cat_map == tmp->cat_map) {//Exactly same node is already in list URL_CLASS_LOG(LOG_LEVEL_DEBUG, "url=%s at url_array[%d] already exist!\n", tmp->url, index); pthread_mutex_unlock(&url_lock); continue; } if(url_array[index].process_flag == URL_PROCESS_READY) {//Still can modify url_array[index].url_len = tmp->url_len; url_array[index].info_id = tmp->info_id; url_array[index].cat_map = tmp->cat_map; strncpy_safe(url_array[index].url, tmp->url, tmp->url_len); pthread_cond_signal(&cond); pthread_mutex_unlock(&url_lock); URL_CLASS_LOG(LOG_LEVEL_WARN, "Replace url=%s at url_array[%d]\n", tmp->url, index); continue; } index = 2 * url_entry_len; while(index < malloc_url_entry_len && url_array[index].prev) { index++; } if(index >= malloc_url_entry_len) { //An auc query is ignored here! URL_CLASS_LOG(LOG_LEVEL_ERROR, "url_array is full! url=%s query is ignored!\n", tmp->url_len); pthread_mutex_unlock(&url_lock); continue; } } URL_CLASS_LOG(LOG_LEVEL_DEBUG, "Place url=%s at url_array[%d]\n", tmp->url, index); } } else {//Exactly same node is already in list pthread_mutex_unlock(&url_lock); continue; } } url_array[index].id = tmp->id; url_array[index].query = 0; url_array[index].process_flag = URL_PROCESS_READY; url_array[index].url_len = tmp->url_len; url_array[index].info_id = tmp->info_id; url_array[index].cat_map = tmp->cat_map; strncpy_safe(url_array[index].url, tmp->url, tmp->url_len); printWar("msg from kernel, url=%s len=%d id=%d\n", url_array[index].url, url_array[index].url_len, url_array[index].id); //add to list url_array[index].next = url_list.next; if (url_list.next) { url_list.next->prev = &url_array[index]; } url_array[index].prev = &url_list; url_list.next = &url_array[index]; pthread_cond_signal(&cond); pthread_mutex_unlock(&url_lock); } exit: if (nlh) { free(nlh); } if (url_array) { free(url_array); } on_exit_handler(); return ret; } static size_t _strlcpy(char *dst, const char *src, size_t dstsize) { size_t srclen = (size_t)strlen(src); if (dstsize > 0) { size_t len = (srclen >= dstsize) ? dstsize - 1 : srclen; memset(dst, 0, (len + 1)); memcpy(dst, src, len); } return srclen; } static struct uci_context *_uci_context_init(const char *config_path) { struct uci_context *uci_ctx = NULL; uci_ctx = uci_alloc_context(); if (uci_ctx) { uci_set_confdir(uci_ctx, config_path); } return uci_ctx; } static void _uci_context_free(struct uci_context *uci_ctx) { if (uci_ctx) { uci_free_context(uci_ctx); } } static int _uci_get_value(char * p_uci_str, char* p_value) { struct uci_context *uci_ctx = NULL; struct uci_element *e = NULL; struct uci_ptr p_uci; if (NULL == p_uci_str || NULL == p_value) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "p_uci_str or p_value is null"); goto error; } uci_ctx = _uci_context_init("/etc/config"); if (!uci_ctx) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "fail to init uci context:%s", p_uci_str); goto error; } if (UCI_OK != uci_lookup_ptr(uci_ctx, &p_uci, p_uci_str, true)) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "fail to get ptr %s ", p_uci_str); goto error; } e = p_uci.last; if (UCI_TYPE_OPTION != e->type) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "element type is not option:%d", e->type); goto error; } if (UCI_TYPE_STRING != p_uci.o->type) { URL_CLASS_LOG(LOG_LEVEL_ERROR, "option type is not string:%d", p_uci.o->type); goto error; } _strlcpy(p_value, p_uci.o->v.string, 64); URL_CLASS_LOG(LOG_LEVEL_DEBUG, "Success to get option value %s = %s ", p_uci_str,p_uci.o->v.string); _uci_context_free(uci_ctx); return 0; error: _uci_context_free(uci_ctx); return -1; } int parseOpts(int argc, char* argv[], struct Options* opt) { int c; int rc = 999; int use_tp_service = -1; while((c = getopt_long(argc, argv, short_opt, long_opt, NULL)) != -1) { switch(c) { case -1: /* no more arguments */ case 0: /* long options toggles */ break; case &#39;s&#39;: if (optarg) { if(strcmp(optarg, "avira") == 0) { use_tp_service = 0; URL_CLASS_LOG(LOG_LEVEL_DEBUG, "parse Opts receive use avira service!"); } else if(strcmp(optarg, "tplink") == 0) { use_tp_service = 1; URL_CLASS_LOG(LOG_LEVEL_DEBUG, "parse Opts receive use tplink service!"); } else { URL_CLASS_LOG(LOG_LEVEL_ERROR, "parse Opts receive %s, not avaliable! Try %s -s tplink or %s -s avira", optarg, argv[0], argv[0]); } } rc = &#39;s&#39;; break; case &#39;t&#39;: rc = &#39;t&#39;; break; case &#39;h&#39;: printHelp(argv[0]); rc = 0; break; case &#39;:&#39;: case &#39;?&#39;: printHelpInstruction(argv[0]); rc = 0; break; default: printf("%s : invalid option --\n", c); printHelpInstruction(argv[0]); rc = 0; break; } } if(use_tp_service == -1) { char _key[64] = "avira.info.status"; char _value[64] = {0}; if (_uci_get_value(_key, _value)) { URL_CLASS_LOG(LOG_LEVEL_DEBUG, "-s Parameter not found! Config avira.info.status not found! use default avira service!"); opt->use_tp_service = false; } else { if(strncmp(_value, "available", sizeof("available") - 1) == 0 || strncmp(_value, "libauc_available", sizeof("libauc_available") - 1) == 0)//avira服务可用 { URL_CLASS_LOG(LOG_LEVEL_DEBUG, "-s Parameter not found! Config avira.info.status=%s! use avira service!", _value); opt->use_tp_service = false; } else { URL_CLASS_LOG(LOG_LEVEL_DEBUG, "-s Parameter not found! Config avira.info.status=%s! use tplink service!", _value); opt->use_tp_service = true; } } } else { opt->use_tp_service = use_tp_service ? true : false; } return rc; } void printHelpInstruction(char *progName) { printf("Try: %s --help for more information\n", progName); } void printHelp(char *progName) { printf("Usage: %s\n\t -s <tplink/avira> Use the specified service provider", progName); } 我修改了这个代码的部分内容,如何单独编译这个代码,之后拷贝到我的设备中替换原有进程
09-23
编译的时候报错了,该怎么修改代码解决? PATH=“/mydisk/platform/buildroot/build/armv8/host/bin:/mydisk/platform/buildroot/build/armv8/host/sbin:/usr/local/bin:/home/felix/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin” /usr/bin/make -j4 -C /mydisk/platform/buildroot/build/armv8/build/tplink/gpioReset-1.0/ Scanning dependencies of target gpioReset [ 33%] Building C object CMakeFiles/gpioReset.dir/srvcGpioReset.c.o [ 66%] Building C object CMakeFiles/gpioReset.dir/mainGpioReset.c.o srvcGpioReset.c: In function ‘gpioResetSrvc’: srvcGpioReset.c:22:16: error: ‘ERR_INIT’ undeclared (first use in this function); did you mean ‘ESRMNT’? return ERR_INIT; ^~~~~~~~ ESRMNT srvcGpioReset.c:22:16: note: each undeclared identifier is reported only once for each function it appears in srvcGpioReset.c:80:12: error: ‘ERR_NO_ERROR’ undeclared (first use in this function); did you mean ‘PAL_MQ_ERROR’? return ERR_NO_ERROR; ^~~~~~~~~~~~ PAL_MQ_ERROR srvcGpioReset.c: In function ‘gpioResetSrvcExit’: srvcGpioReset.c:86:12: error: ‘ERR_NO_ERROR’ undeclared (first use in this function); did you mean ‘PAL_MQ_ERROR’? return ERR_NO_ERROR; ^~~~~~~~~~~~ PAL_MQ_ERROR srvcGpioReset.c:87:1: error: control reaches end of non-void function [-Werror=return-type] } ^ cc1: all warnings being treated as errors CMakeFiles/gpioReset.dir/build.make:78: recipe for target ‘CMakeFiles/gpioReset.dir/srvcGpioReset.c.o’ failed make[4]: *** [CMakeFiles/gpioReset.dir/srvcGpioReset.c.o] Error 1 make[4]: *** Waiting for unfinished jobs… mainGpioReset.c: In function ‘init_gpio_reset’: mainGpioReset.c:89:5: error: unknown type name ‘shell_init_func_t’ shell_init_func_t shell_initfunc = {}; ^~~~~~~~~~~~~~~~~ mainGpioReset.c:89:40: error: empty scalar initializer shell_init_func_t shell_initfunc = {}; ^ mainGpioReset.c:89:40: note: (near initialization for ‘shell_initfunc’) mainGpioReset.c:90:28: error: request for member ‘mm_init_table’ in something not a structure or union memcpy(&(shell_initfunc.mm_init_table), &initFunc, sizeof(mm_app_init_t)); ^ mainGpioReset.c:91:5: error: implicit declaration of function ‘shell_regfunc’ [-Werror=implicit-function-declaration] shell_regfunc(MODULE_GPIO_RESET_INDEX, shell_initfunc, srvc, mm_app_srvc_size(srvc), GPIO_RESET_SUB_NAME); ^~~~~~~~~~~~~ mainGpioReset.c:91:19: error: ‘MODULE_GPIO_RESET_INDEX’ undeclared (first use in this function); did you mean ‘SRVC_GPIO_RESET_H’? shell_regfunc(MODULE_GPIO_RESET_INDEX, shell_initfunc, srvc, mm_app_srvc_size(srvc), GPIO_RESET_SUB_NAME); ^~~~~~~~~~~~~~~~~~~~~~~ SRVC_GPIO_RESET_H mainGpioReset.c:91:19: note: each undeclared identifier is reported only once for each function it appears in cc1: all warnings being treated as errors CMakeFiles/gpioReset.dir/build.make:65: recipe for target ‘CMakeFiles/gpioReset.dir/mainGpioReset.c.o’ failed make[4]: *** [CMakeFiles/gpioReset.dir/mainGpioReset.c.o] Error 1 CMakeFiles/Makefile2:78: recipe for target ‘CMakeFiles/gpioReset.dir/all’ failed make[3]: *** [CMakeFiles/gpioReset.dir/all] Error 2 Makefile:132: recipe for target ‘all’ failed make[2]: *** [all] Error 2 package/tplink/tplink-generic.mk:289: recipe for target ‘/mydisk/platform/buildroot/build/armv8/build/tplink/gpioReset-1.0/.stamp_built’ failed make[1]: *** [/mydisk/platform/buildroot/build/armv8/build/tplink/gpioReset-1.0/.stamp_built] Error 2 Makefile:84: recipe for target ‘_all’ failed make: *** [_all] Error 2 下面是现在的代码: main: /*!Copyright (c) 2010-2011 TP-LINK Technologies CO.,LTD. *All rights reserved. * *\file mainRebootScheduleCpn.c *\brief * *\author Yang Jingjing *\version *\date 2025-09-09 */ /**************************************************************************************************/ /* INCLUDE_FILES */ /**************************************************************************************************/ /* libc header */ #include <stdio.h> #include <unistd.h> #include "fepDefs.h" #include "pal/msgq.h" #include "tpDbg/tpdebug.h" #include "mm/mm.h" #include "common/applError.h" #include "srvcGpioReset.h" /**************************************************************************************************/ /* DEFINES */ /**************************************************************************************************/ #define GPIO_RESET_USR_NAME_MAX_LEN 10 #define GPIO_RESET_SUB_NAME "GPIO_RESET" /**************************************************************************************************/ /* TYPES */ /**************************************************************************************************/ /**************************************************************************************************/ /* EXTERN_PROTOTYPES */ /**************************************************************************************************/ /**************************************************************************************************/ /* LOCAL_PROTOTYPES */ /**************************************************************************************************/ /**************************************************************************************************/ /* VARIABLES */ /**************************************************************************************************/ static mm_app_prvt_srvc_t srvc[] = { { .tid = PAL_THREAD_ERROR, .func = gpioResetSrvc, .pre_exit_f = gpioResetSrvcExit, .name = "gpio-reset", .start = MM_APP_SRVC_IDLE, .stack_size = SRVC_GPIO_RESET_STACK_SIZE_DEFAULT, .prio = SRVC_GPIO_RESET_PRIO_DEFAULT, .srvc_id = GPIO_RESET_PRVT_SRVC, .meta_arg = NULL } }; /**************************************************************************************************/ /* LOCAL_FUNCTIONS */ /**************************************************************************************************/ /**************************************************************************************************/ /* PUBLIC_FUNCTIONS */ /**************************************************************************************************/ static __attribute__((constructor)) int init_gpio_reset() { mm_app_init_t initFunc = {0}; DBG("GPIO Reset main start."); // 初始化函数表(保留基本结构,简化不必要的初始化) initFunc._init_platform = NULL; initFunc._init_private = NULL; initFunc._init_public = NULL; initFunc._init_application = NULL; initFunc._init_preconfig = NULL; initFunc._init_defconfig = NULL; initFunc._init_loadconfig = NULL; initFunc._init_stable = NULL; shell_init_func_t shell_initfunc = {}; memcpy(&(shell_initfunc.mm_init_table), &initFunc, sizeof(mm_app_init_t)); shell_regfunc(MODULE_GPIO_RESET_INDEX, shell_initfunc, srvc, mm_app_srvc_size(srvc), GPIO_RESET_SUB_NAME); DBG("GPIO Reset main loop."); return 0; } srvc: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/socket.h> #include <linux/netlink.h> #include "srvcGpioReset.h" #include "tpDbg/tpdebug.h" int gpioResetSrvc(void *param) { struct sockaddr_nl src_addr, dest_addr; struct nlmsghdr *nlh = NULL; struct iovec iov; struct msghdr msg; int sock_fd, ret; // 创建Netlink socket sock_fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GPIO_EVENT); if (sock_fd < 0) { DBG_ERR("Failed to create netlink socket: %s", strerror(errno)); return ERR_INIT; } memset(&src_addr, 0, sizeof(src_addr)); src_addr.nl_family = AF_NETLINK; src_addr.nl_pid = getpid(); // 应用进程ID src_addr.nl_groups = 1; // 加入组播组1 // 绑定socket if (bind(sock_fd, (struct sockaddr*)&src_addr, sizeof(src_addr))) { DBG_ERR("Bind failed: %s", strerror(errno)); close(sock_fd); return ERR_INIT; } // 准备接收缓冲区 nlh = (struct nlmsghdr *)malloc(NLMSG_SPACE(sizeof(struct gpio_netlink_msg))); if (!nlh) { DBG_ERR("Memory allocation failed"); close(sock_fd); return ERR_INIT; } memset(nlh, 0, NLMSG_SPACE(sizeof(struct gpio_netlink_msg))); iov.iov_base = (void *)nlh; iov.iov_len = NLMSG_SPACE(sizeof(struct gpio_netlink_msg)); memset(&msg, 0, sizeof(msg)); msg.msg_name = (void *)&dest_addr; msg.msg_namelen = sizeof(dest_addr); msg.msg_iov = &iov; msg.msg_iovlen = 1; DBG("GPIO Reset service started. Waiting for reset events..."); while (1) { // 接收Netlink消息 ret = recvmsg(sock_fd, &msg, 0); if (ret < 0) { DBG_ERR("recvmsg error: %s", strerror(errno)); continue; } // 解析消息 struct gpio_netlink_msg *msg_data = (struct gpio_netlink_msg *)NLMSG_DATA(nlh); // 检查是否为reset事件 if (strcmp(msg_data->button_name, "reset") == 0) { DBG("=== RESET EVENT DETECTED ==="); DBG("Event type: %u", msg_data->event_type); DBG("Value: %d", msg_data->value); DBG("Timestamp: %lu", msg_data->timestamp); DBG("============================"); } } free(nlh); close(sock_fd); return ERR_NO_ERROR; } int gpioResetSrvcExit(void *param) { // 清理资源的位置(实际在循环中不会退出) return ERR_NO_ERROR; } srvc.h: #ifndef _SRVC_GPIO_RESET_H_ #define _SRVC_GPIO_RESET_H_ #ifdef __cplusplus extern "C" { #endif #include <linux/netlink.h> #include <sys/socket.h> // 与内核相同的定义 #define NETLINK_GPIO_EVENT 31 #define SRVC_GPIO_RESET_STACK_SIZE_DEFAULT 10240 #define SRVC_GPIO_RESET_PRIO_DEFAULT PAL_THREAD_PRIO_IGNORE #define GPIO_RESET_PRVT_SRVC 0 // Netlink消息结构(与内核保持一致) struct gpio_netlink_msg { char button_name[32]; unsigned int event_type; int value; unsigned long timestamp; }; int gpioResetSrvc(void *param); int gpioResetSrvcExit(void *param); #ifdef __cplusplus } #endif #endif // _SRVC_GPIO_RESET_H_
最新发布
10-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值