Skip to content

Commit

Permalink
fix RST flag
Browse files Browse the repository at this point in the history
  • Loading branch information
six-ddc committed Jun 24, 2017
1 parent ea9a482 commit 20e8eed
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions custom_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ int custom_parser::on_message_complete(http_parser *parser) {
if (gzip_decompress(self->response_body, new_body)) {
self->response_body = new_body;
} else {
std::cerr << ANSI_COLOR_RED << "uncompress error" << ANSI_COLOR_RESET << std::endl;
std::cerr << ANSI_COLOR_RED << "[decompress error]" << ANSI_COLOR_RESET << std::endl;
}
}
return 0;
Expand Down Expand Up @@ -153,7 +153,9 @@ std::ostream& operator<<(std::ostream& out, const custom_parser& parser) {
<< ANSI_COLOR_BLUE
<< parser.response_header
<< ANSI_COLOR_RESET;
if (!is_atty || is_plain_text(parser.response_body)) {
if (parser.response_body.empty()) {
out << ANSI_COLOR_RED << "[empty response body]" << ANSI_COLOR_RESET;
} else if (!is_atty || is_plain_text(parser.response_body)) {
out << parser.response_body;
} else {
out << ANSI_COLOR_RED << "[binary response body]" << ANSI_COLOR_RESET;
Expand Down
4 changes: 2 additions & 2 deletions http_flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static bool process_tcp(struct packet_info *packet, const u_char *content, size_
packet->src_addr.assign(buff);
std::snprintf(buff, 128, "%s:%d", packet->dst_addr.c_str(), dst_port);
packet->dst_addr.assign(buff);
packet->is_fin = !!(tcp_header->th_flags & TH_FIN);
packet->is_fin = !!(tcp_header->th_flags & (TH_FIN | TH_RST));

content += tcp_header_len;
packet->body = std::string(reinterpret_cast<const char *>(content), len - tcp_header_len);
Expand Down Expand Up @@ -396,7 +396,7 @@ int main(int argc, char **argv) {
datalink_id = pcap_datalink(handle);
datalink_str = datalink2str(datalink_id);
cap_conf->datalink_size = datalink2off(datalink_id);
std::cerr << "datalink: " << datalink_str << " header size: " << cap_conf->datalink_size << std::endl;
std::cerr << "datalink: " << datalink_id << "(" << datalink_str << ") header size: " << cap_conf->datalink_size << std::endl;

if (-1 == pcap_loop(handle, -1, pcap_callback, reinterpret_cast<u_char *>(cap_conf))) {
std::cerr << "pcap_loop(): " << pcap_geterr(handle) << std::endl;
Expand Down

0 comments on commit 20e8eed

Please sign in to comment.