diff options
| author | luwenpeng <[email protected]> | 2024-10-24 16:22:18 +0800 |
|---|---|---|
| committer | luwenpeng <[email protected]> | 2024-10-24 16:22:18 +0800 |
| commit | e0b8732a15d7ea31f51b093209dfc085ea28dcd3 (patch) | |
| tree | eececcf70fa21ee2ba4fbc04df649c91cbbd4c16 /test | |
| parent | cb6f2319352b65001db13c32b879d847abf0d90f (diff) | |
Optimize log output
Diffstat (limited to 'test')
| -rw-r--r-- | test/packet_tool/packet_tool.c | 12 | ||||
| -rw-r--r-- | test/session_debugger/session_debugger.c | 12 |
2 files changed, 17 insertions, 7 deletions
diff --git a/test/packet_tool/packet_tool.c b/test/packet_tool/packet_tool.c index 65753fd..fa249b9 100644 --- a/test/packet_tool/packet_tool.c +++ b/test/packet_tool/packet_tool.c @@ -241,21 +241,31 @@ static void packet_handler(u_char *user, const struct pcap_pkthdr *h, const u_ch { struct runtime *rte = (struct runtime *)user; + char *ptr = (char *)calloc(1, h->caplen); + if (ptr == NULL) + { + PRINT_RED("calloc() failed"); + return; + } + memcpy(ptr, bytes, h->caplen); + struct packet pkt; memset(&pkt, 0, sizeof(pkt)); - packet_parse(&pkt, (const char *)bytes, h->caplen); + packet_parse(&pkt, (const char *)ptr, h->caplen); rte->pcap_count++; if (rte->print_verbose) { PRINT_GREEN("frame=%lu len=%u", rte->pcap_count, h->caplen); packet_print(&pkt); + packet_dump_hex(&pkt, STDOUT_FILENO); } if (rte->tshark_format) { tshark_format(rte, &pkt); } + free(ptr); } static void usage(char *cmd) diff --git a/test/session_debugger/session_debugger.c b/test/session_debugger/session_debugger.c index 48c028a..4a6a267 100644 --- a/test/session_debugger/session_debugger.c +++ b/test/session_debugger/session_debugger.c @@ -175,12 +175,12 @@ static void on_session_free(struct session *sess, void *arg) char buff[PATH_MAX] = {0}; session_to_str(exdata->sess, 0, buff, sizeof(buff) - 1); - session_debugger_log(exdata->dbg->fd, "sess free: %s", buff); + session_debugger_log(exdata->dbg->fd, "session free: %s", buff); snprintf(buff, sizeof(buff), "==========================================================\n" - "C2S Data Packets : %6lu | C2S Data Bytes : %6lu\n" - "S2C Data Packets : %6lu | S2C Data Bytes : %6lu\n" + "C2S Data Packets : %6lu | C2S Data Bytes : %6lu\n" + "S2C Data Packets : %6lu | S2C Data Bytes : %6lu\n" "----------------------------------------------------------\n" "C2S Control Packets : %6lu | C2S Control Bytes : %6lu\n" "S2C Control Packets : %6lu | S2C Control Bytes : %6lu\n" @@ -189,7 +189,7 @@ static void on_session_free(struct session *sess, void *arg) "S2C TCP Segments : %6lu | S2C TCP Bytes : %6lu\n" "----------------------------------------------------------\n" "C2S UDP Payload : %6lu | C2S UDP Bytes : %6lu\n" - "S2C UDP Payload : %6lu | S2C UDP Bytes : %6lu\n", + "S2C UDP Payload : %6lu | S2C UDP Bytes : %6lu", exdata->c2s_rx_data_pkts, exdata->c2s_rx_data_bytes, exdata->s2c_rx_data_pkts, exdata->s2c_rx_data_bytes, exdata->c2s_rx_ctrl_pkts, exdata->c2s_rx_ctrl_bytes, @@ -438,7 +438,7 @@ struct stellar_module *session_debugger_on_init(struct stellar_module_manager *m } stellar_module_set_ctx(dbg_mod, dbg); - STELLAR_LOG_FATAL(dbg->logger, "session debugger", "session_debugger initialized") + STELLAR_LOG_FATAL(dbg->logger, "session debugger", "session_debugger init") return dbg_mod; } @@ -450,7 +450,7 @@ void session_debugger_on_exit(struct stellar_module_manager *mod_mgr, struct ste struct session_debugger *dbg = stellar_module_get_ctx(mod); if (dbg) { - STELLAR_LOG_FATAL(dbg->logger, "session debugger", "session_debugger exited") + STELLAR_LOG_FATAL(dbg->logger, "session debugger", "session_debugger exit") session_debugger_free(dbg); } stellar_module_free(mod); |
