Add tools packet_parser
This commit is contained in:
@@ -6,6 +6,7 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#define __FAVOR_BSD 1
|
||||
@@ -261,6 +262,23 @@ static inline void tcp_hdr_set_opt_data(struct tcphdr *hdr, const char *ptr)
|
||||
memcpy((char *)hdr + sizeof(struct tcphdr), ptr, tcp_hdr_get_opt_len(hdr));
|
||||
}
|
||||
|
||||
static inline int tcp_hdr_to_str(const struct tcphdr *hdr, char *buf, size_t size)
|
||||
{
|
||||
memset(buf, 0, size);
|
||||
return snprintf(buf, size, "TCP: src_port=%u dst_port=%u seq=%u ack=%u hdr_len=%u flags=0x%02x(%s%s%s%s%s%s) window=%u checksum=%u urg_ptr=%u opt_len=%u",
|
||||
tcp_hdr_get_src_port(hdr), tcp_hdr_get_dst_port(hdr),
|
||||
tcp_hdr_get_seq(hdr), tcp_hdr_get_ack(hdr),
|
||||
tcp_hdr_get_hdr_len(hdr), tcp_hdr_get_flags(hdr),
|
||||
tcp_hdr_get_urg_flag(hdr) ? "URG " : "",
|
||||
tcp_hdr_get_ack_flag(hdr) ? "ACK " : "",
|
||||
tcp_hdr_get_push_flag(hdr) ? "PSH " : "",
|
||||
tcp_hdr_get_rst_flag(hdr) ? "RST " : "",
|
||||
tcp_hdr_get_syn_flag(hdr) ? "SYN " : "",
|
||||
tcp_hdr_get_fin_flag(hdr) ? "FIN " : "",
|
||||
tcp_hdr_get_window(hdr), tcp_hdr_get_checksum(hdr),
|
||||
tcp_hdr_get_urg_ptr(hdr), tcp_hdr_get_opt_len(hdr));
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user