enhance: imitate_tcp_packet() support setting tcp options
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "log.h"
|
||||
#include "packet_dump.h"
|
||||
#include "packet_utils.h"
|
||||
|
||||
#define PACKET_DUMP_LOG_ERROR(format, ...) LOG_ERROR("packet dump", format, ##__VA_ARGS__)
|
||||
|
||||
@@ -30,8 +31,11 @@ struct pcap_file_hdr
|
||||
|
||||
// return 0: success
|
||||
// return -1: failed
|
||||
int packet_dump(const char *file, const char *data, uint16_t len)
|
||||
int packet_dump_pcap(const struct packet *pkt, const char *file)
|
||||
{
|
||||
const char *data = packet_get_raw_data(pkt);
|
||||
uint16_t len = packet_get_raw_len(pkt);
|
||||
|
||||
struct pcap_pkt_hdr pkt_hdr = {0};
|
||||
struct pcap_file_hdr file_hdr = {
|
||||
.magic = 0xA1B2C3D4,
|
||||
@@ -71,3 +75,19 @@ int packet_dump(const char *file, const char *data, uint16_t len)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void packet_dump_hex(const struct packet *pkt, int fd)
|
||||
{
|
||||
const char *data = packet_get_raw_data(pkt);
|
||||
uint16_t len = packet_get_raw_len(pkt);
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i % 16 == 0)
|
||||
{
|
||||
dprintf(fd, "\n");
|
||||
}
|
||||
dprintf(fd, "%02x ", (unsigned char)data[i]);
|
||||
}
|
||||
dprintf(fd, "\n");
|
||||
}
|
||||
Reference in New Issue
Block a user