|
4 | 4 | #include <memory.h> |
5 | 5 | #include <stdlib.h> |
6 | 6 | #include <getopt.h> |
| 7 | +#include <errno.h> |
7 | 8 | #include <iostream> |
8 | 9 | #include <fstream> |
9 | 10 | #include <string> |
@@ -256,8 +257,11 @@ static bool process_tcp(struct packet_info *packet, const u_char *content, size_ |
256 | 257 | uint16_t src_port = ntohs(tcp_header->th_sport); |
257 | 258 | uint16_t dst_port = ntohs(tcp_header->th_dport); |
258 | 259 |
|
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); |
261 | 265 |
|
262 | 266 | /* |
263 | 267 | std::cout<<"( " ANSI_COLOR_CYAN; |
@@ -370,7 +374,7 @@ static bool process_ethernet(struct packet_info *packet, const u_char *content, |
370 | 374 | static void save_http_request(const custom_parser *parser, const capture_config *conf, const std::string &join_addr) { |
371 | 375 | if (!conf->output_path.empty()) { |
372 | 376 | 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); |
374 | 378 | if (out.is_open()) { |
375 | 379 | out << *parser << std::endl; |
376 | 380 | out.close(); |
@@ -487,7 +491,7 @@ int custom_parser::on_message_complete(http_parser *parser) { |
487 | 491 | if (self->gzip_flag) { |
488 | 492 | std::string new_body; |
489 | 493 | if (gzip_decompress(self->response_body, new_body)) { |
490 | | - self->response_body = std::move(new_body); |
| 494 | + self->response_body = new_body; |
491 | 495 | } else { |
492 | 496 | std::cerr << ANSI_COLOR_RED "uncompress error" ANSI_COLOR_RESET << std::endl; |
493 | 497 | } |
|
0 commit comments