Skip to content

Commit b5e9778

Browse files
committed
fix bug
1 parent fa8a802 commit b5e9778

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

http_flow.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <memory.h>
55
#include <stdlib.h>
66
#include <getopt.h>
7+
#include <errno.h>
78
#include <iostream>
89
#include <fstream>
910
#include <string>
@@ -256,8 +257,11 @@ static bool process_tcp(struct packet_info *packet, const u_char *content, size_
256257
uint16_t src_port = ntohs(tcp_header->th_sport);
257258
uint16_t dst_port = ntohs(tcp_header->th_dport);
258259

259-
packet->src_addr.append(":" + std::to_string(src_port));
260-
packet->dst_addr.append(":" + std::to_string(dst_port));
260+
char buff[128];
261+
std::snprintf(buff, 128, "%s:%d", packet->src_addr.c_str(), src_port);
262+
packet->src_addr.assign(buff);
263+
std::snprintf(buff, 128, "%s:%d", packet->dst_addr.c_str(), dst_port);
264+
packet->dst_addr.assign(buff);
261265

262266
/*
263267
std::cout<<"( " ANSI_COLOR_CYAN;
@@ -370,7 +374,7 @@ static bool process_ethernet(struct packet_info *packet, const u_char *content,
370374
static void save_http_request(const custom_parser *parser, const capture_config *conf, const std::string &join_addr) {
371375
if (!conf->output_path.empty()) {
372376
std::string save_filename = conf->output_path + "/" + parser->get_host();
373-
std::ofstream out(save_filename, std::ios::app | std::ios::out);
377+
std::ofstream out(save_filename.c_str(), std::ios::app | std::ios::out);
374378
if (out.is_open()) {
375379
out << *parser << std::endl;
376380
out.close();
@@ -487,7 +491,7 @@ int custom_parser::on_message_complete(http_parser *parser) {
487491
if (self->gzip_flag) {
488492
std::string new_body;
489493
if (gzip_decompress(self->response_body, new_body)) {
490-
self->response_body = std::move(new_body);
494+
self->response_body = new_body;
491495
} else {
492496
std::cerr << ANSI_COLOR_RED "uncompress error" ANSI_COLOR_RESET << std::endl;
493497
}

0 commit comments

Comments
 (0)