#include #include #include #include #include #include #include #include #include "log.h" #include "trace_api.h" void cb(trace_ret_t ret, void *arg) { printf("reply valaue:%u\n", ret); } int main(int argc, char **argv) { printf("1111\n"); SYSLOG_INIT("test-client"); trace_client_init(); printf("argc num:%d\n", argc); #if 0 int count = 1; if (argc >= 2) { count = atoi(argv[1]); } int async = 1; if (argc >= 3) { async = atoi(argv[2]); } for (int i = 0; i < count; i++) { trace_policy_t trace1 = {0}; //trace1.src.addr.ip4.s_addr = i; trace1.dst.addr.ip4.s_addr = i; //memset(&trace1, 0, sizeof(trace1)); trace1.src.family = TRACE_FAMILY_IP4; trace1.dst.family = TRACE_FAMILY_IP4; trace1.protocol = 30; trace1.app_type = 3; trace1.base_type = 4; if (async == 1) { printf("async exec\n"); trace_async_exec(&trace1, cb, NULL); } else if (async == 2) { printf("exec no reply\n"); trace_exec_no_reply(&trace1); } else { printf("sync exec\n"); trace_sync_exec(&trace1); printf("sync final\n"); } printf("send success\n"); } #else printf("usage: %s src_ip src_port dst_ip dst_port protocol is_async(1=async, 2=exce_no_reply, 3=sync)\n", argv[0]); struct in_addr src_addr={0}; struct in_addr dst_addr={0}; u16 src_port = 0; u16 dst_port = 0; u16 prot = 6; int async = 1; if (argc >= 2) { inet_aton(argv[1], &src_addr); } if (argc >= 3) { src_port = atoi(argv[2]); } if (argc >= 4) { inet_aton(argv[3], &dst_addr); } if (argc >= 5) { dst_port = atoi(argv[4]); } if (argc >= 6) { prot = atoi(argv[5]); } if (argc >= 7) { async = atoi(argv[6]); } trace_policy_t trace1 = {0}; trace1.src.addr.ip4.s_addr = src_addr.s_addr; trace1.dst.addr.ip4.s_addr = dst_addr.s_addr; trace1.src.family = TRACE_FAMILY_IP4; trace1.dst.family = TRACE_FAMILY_IP4; trace1.sport = htons(src_port); trace1.dport = htons(dst_port); trace1.protocol = prot; trace1.app_type = 3; trace1.base_type = 4; if (async == 1) { printf("async exec\n"); trace_async_exec(&trace1, cb, NULL); } else if (async == 2) { printf("exec no reply\n"); trace_exec_no_reply(&trace1); } else { printf("sync exec\n"); trace_sync_exec(&trace1); printf("sync final\n"); } printf("send success\n"); #endif //policy_client_exit(); if (async != 3) { sleep(10); } trace_client_exit(); return 0; }