pcap: Fix format warnings
Related to https://github.com/espressif/idf-extra-components/issues/65
This commit is contained in:
parent
a45de9cf24
commit
4691e54ffb
|
@ -1,3 +1,2 @@
|
||||||
idf_component_register(SRCS "src/pcap.c"
|
idf_component_register(SRCS "src/pcap.c"
|
||||||
INCLUDE_DIRS "include")
|
INCLUDE_DIRS "include")
|
||||||
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
version: "1.0.1"
|
version: "1.0.2"
|
||||||
description: PCAP file writer
|
description: PCAP file writer
|
||||||
url: https://github.com/espressif/idf-extra-components/tree/master/pcap
|
url: https://github.com/espressif/idf-extra-components/tree/master/pcap
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
@ -41,7 +41,8 @@ typedef enum {
|
||||||
PCAP_LINK_TYPE_CISCO_HDLC = 104, /*!< Cisco HDLC */
|
PCAP_LINK_TYPE_CISCO_HDLC = 104, /*!< Cisco HDLC */
|
||||||
PCAP_LINK_TYPE_802_11 = 105, /*!< 802.11 */
|
PCAP_LINK_TYPE_802_11 = 105, /*!< 802.11 */
|
||||||
PCAP_LINK_TYPE_BSD_LOOPBACK = 108, /*!< OpenBSD loopback devices(with AF_value in network byte order) */
|
PCAP_LINK_TYPE_BSD_LOOPBACK = 108, /*!< OpenBSD loopback devices(with AF_value in network byte order) */
|
||||||
PCAP_LINK_TYPE_LOCAL_TALK = 114 /*!< LocalTalk */
|
PCAP_LINK_TYPE_LOCAL_TALK = 114, /*!< LocalTalk */
|
||||||
|
PCAP_LINK_TYPE_USBPCAP = 249, /*!< USB packets, beginning with a USBPcap header */
|
||||||
} pcap_link_type_t;
|
} pcap_link_type_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
447
pcap/src/pcap.c
447
pcap/src/pcap.c
|
@ -1,223 +1,224 @@
|
||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "esp_log.h"
|
#include <inttypes.h>
|
||||||
#include "esp_check.h"
|
#include "esp_log.h"
|
||||||
#include "pcap.h"
|
#include "esp_check.h"
|
||||||
|
#include "pcap.h"
|
||||||
static const char *TAG = "pcap";
|
|
||||||
|
static const char *TAG = "pcap";
|
||||||
#define PCAP_MAGIC_BIG_ENDIAN 0xA1B2C3D4 /*!< Big-Endian */
|
|
||||||
#define PCAP_MAGIC_LITTLE_ENDIAN 0xD4C3B2A1 /*!< Little-Endian */
|
#define PCAP_MAGIC_BIG_ENDIAN 0xA1B2C3D4 /*!< Big-Endian */
|
||||||
|
#define PCAP_MAGIC_LITTLE_ENDIAN 0xD4C3B2A1 /*!< Little-Endian */
|
||||||
typedef struct pcap_file_t pcap_file_t;
|
|
||||||
|
typedef struct pcap_file_t pcap_file_t;
|
||||||
/**
|
|
||||||
* @brief Pcap File Header
|
/**
|
||||||
*
|
* @brief Pcap File Header
|
||||||
*/
|
*
|
||||||
typedef struct {
|
*/
|
||||||
uint32_t magic; /*!< Magic Number */
|
typedef struct {
|
||||||
uint16_t major; /*!< Major Version */
|
uint32_t magic; /*!< Magic Number */
|
||||||
uint16_t minor; /*!< Minor Version */
|
uint16_t major; /*!< Major Version */
|
||||||
uint32_t zone; /*!< Time Zone Offset */
|
uint16_t minor; /*!< Minor Version */
|
||||||
uint32_t sigfigs; /*!< Timestamp Accuracy */
|
uint32_t zone; /*!< Time Zone Offset */
|
||||||
uint32_t snaplen; /*!< Max Length to Capture */
|
uint32_t sigfigs; /*!< Timestamp Accuracy */
|
||||||
uint32_t link_type; /*!< Link Layer Type */
|
uint32_t snaplen; /*!< Max Length to Capture */
|
||||||
} pcap_file_header_t;
|
uint32_t link_type; /*!< Link Layer Type */
|
||||||
|
} pcap_file_header_t;
|
||||||
/**
|
|
||||||
* @brief Pcap Packet Header
|
/**
|
||||||
*
|
* @brief Pcap Packet Header
|
||||||
*/
|
*
|
||||||
typedef struct {
|
*/
|
||||||
uint32_t seconds; /*!< Number of seconds since January 1st, 1970, 00:00:00 GMT */
|
typedef struct {
|
||||||
uint32_t microseconds; /*!< Number of microseconds when the packet was captured (offset from seconds) */
|
uint32_t seconds; /*!< Number of seconds since January 1st, 1970, 00:00:00 GMT */
|
||||||
uint32_t capture_length; /*!< Number of bytes of captured data, no longer than packet_length */
|
uint32_t microseconds; /*!< Number of microseconds when the packet was captured (offset from seconds) */
|
||||||
uint32_t packet_length; /*!< Actual length of current packet */
|
uint32_t capture_length; /*!< Number of bytes of captured data, no longer than packet_length */
|
||||||
} pcap_packet_header_t;
|
uint32_t packet_length; /*!< Actual length of current packet */
|
||||||
|
} pcap_packet_header_t;
|
||||||
/**
|
|
||||||
* @brief Pcap Runtime Handle
|
/**
|
||||||
*
|
* @brief Pcap Runtime Handle
|
||||||
*/
|
*
|
||||||
struct pcap_file_t {
|
*/
|
||||||
FILE *file; /*!< File handle */
|
struct pcap_file_t {
|
||||||
pcap_link_type_t link_type; /*!< Pcap Link Type */
|
FILE *file; /*!< File handle */
|
||||||
unsigned int major_version; /*!< Pcap version: major */
|
pcap_link_type_t link_type; /*!< Pcap Link Type */
|
||||||
unsigned int minor_version; /*!< Pcap version: minor */
|
unsigned int major_version; /*!< Pcap version: major */
|
||||||
unsigned int time_zone; /*!< Pcap timezone code */
|
unsigned int minor_version; /*!< Pcap version: minor */
|
||||||
uint32_t endian_magic; /*!< Magic value related to endian format */
|
unsigned int time_zone; /*!< Pcap timezone code */
|
||||||
};
|
uint32_t endian_magic; /*!< Magic value related to endian format */
|
||||||
|
};
|
||||||
esp_err_t pcap_new_session(const pcap_config_t *config, pcap_file_handle_t *ret_pcap)
|
|
||||||
{
|
esp_err_t pcap_new_session(const pcap_config_t *config, pcap_file_handle_t *ret_pcap)
|
||||||
esp_err_t ret = ESP_OK;
|
{
|
||||||
pcap_file_t *pcap = NULL;
|
esp_err_t ret = ESP_OK;
|
||||||
ESP_GOTO_ON_FALSE(config && ret_pcap, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument");
|
pcap_file_t *pcap = NULL;
|
||||||
ESP_GOTO_ON_FALSE(config->fp, ESP_ERR_INVALID_ARG, err, TAG, "pcap file handle can't be NULL");
|
ESP_GOTO_ON_FALSE(config && ret_pcap, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument");
|
||||||
pcap = calloc(1, sizeof(pcap_file_t));
|
ESP_GOTO_ON_FALSE(config->fp, ESP_ERR_INVALID_ARG, err, TAG, "pcap file handle can't be NULL");
|
||||||
ESP_GOTO_ON_FALSE(pcap, ESP_ERR_NO_MEM, err, TAG, "no mem for pcap file object");
|
pcap = calloc(1, sizeof(pcap_file_t));
|
||||||
pcap->file = config->fp;
|
ESP_GOTO_ON_FALSE(pcap, ESP_ERR_NO_MEM, err, TAG, "no mem for pcap file object");
|
||||||
pcap->major_version = config->major_version;
|
pcap->file = config->fp;
|
||||||
pcap->minor_version = config->minor_version;
|
pcap->major_version = config->major_version;
|
||||||
pcap->endian_magic = config->flags.little_endian ? PCAP_MAGIC_LITTLE_ENDIAN : PCAP_MAGIC_BIG_ENDIAN;
|
pcap->minor_version = config->minor_version;
|
||||||
pcap->time_zone = config->time_zone;
|
pcap->endian_magic = config->flags.little_endian ? PCAP_MAGIC_LITTLE_ENDIAN : PCAP_MAGIC_BIG_ENDIAN;
|
||||||
*ret_pcap = pcap;
|
pcap->time_zone = config->time_zone;
|
||||||
return ret;
|
*ret_pcap = pcap;
|
||||||
err:
|
return ret;
|
||||||
if (pcap) {
|
err:
|
||||||
free(pcap);
|
if (pcap) {
|
||||||
}
|
free(pcap);
|
||||||
return ret;
|
}
|
||||||
}
|
return ret;
|
||||||
|
}
|
||||||
esp_err_t pcap_del_session(pcap_file_handle_t pcap)
|
|
||||||
{
|
esp_err_t pcap_del_session(pcap_file_handle_t pcap)
|
||||||
ESP_RETURN_ON_FALSE(pcap, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
{
|
||||||
if (pcap->file) {
|
ESP_RETURN_ON_FALSE(pcap, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
||||||
fclose(pcap->file);
|
if (pcap->file) {
|
||||||
pcap->file = NULL;
|
fclose(pcap->file);
|
||||||
}
|
pcap->file = NULL;
|
||||||
free(pcap);
|
}
|
||||||
return ESP_OK;
|
free(pcap);
|
||||||
}
|
return ESP_OK;
|
||||||
|
}
|
||||||
esp_err_t pcap_write_header(pcap_file_handle_t pcap, pcap_link_type_t link_type)
|
|
||||||
{
|
esp_err_t pcap_write_header(pcap_file_handle_t pcap, pcap_link_type_t link_type)
|
||||||
ESP_RETURN_ON_FALSE(pcap, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
{
|
||||||
/* Write Pcap File header */
|
ESP_RETURN_ON_FALSE(pcap, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
||||||
pcap_file_header_t header = {
|
/* Write Pcap File header */
|
||||||
.magic = pcap->endian_magic,
|
pcap_file_header_t header = {
|
||||||
.major = pcap->major_version,
|
.magic = pcap->endian_magic,
|
||||||
.minor = pcap->minor_version,
|
.major = pcap->major_version,
|
||||||
.zone = pcap->time_zone,
|
.minor = pcap->minor_version,
|
||||||
.sigfigs = 0,
|
.zone = pcap->time_zone,
|
||||||
.snaplen = 0x40000,
|
.sigfigs = 0,
|
||||||
.link_type = link_type,
|
.snaplen = 0x40000,
|
||||||
};
|
.link_type = link_type,
|
||||||
size_t real_write = fwrite(&header, sizeof(header), 1, pcap->file);
|
};
|
||||||
ESP_RETURN_ON_FALSE(real_write == 1, ESP_FAIL, TAG, "write pcap file header failed");
|
size_t real_write = fwrite(&header, sizeof(header), 1, pcap->file);
|
||||||
/* Save the link type to pcap file object */
|
ESP_RETURN_ON_FALSE(real_write == 1, ESP_FAIL, TAG, "write pcap file header failed");
|
||||||
pcap->link_type = link_type;
|
/* Save the link type to pcap file object */
|
||||||
/* Flush content in the buffer into device */
|
pcap->link_type = link_type;
|
||||||
fflush(pcap->file);
|
/* Flush content in the buffer into device */
|
||||||
return ESP_OK;
|
fflush(pcap->file);
|
||||||
}
|
return ESP_OK;
|
||||||
|
}
|
||||||
esp_err_t pcap_capture_packet(pcap_file_handle_t pcap, void *payload, uint32_t length, uint32_t seconds, uint32_t microseconds)
|
|
||||||
{
|
esp_err_t pcap_capture_packet(pcap_file_handle_t pcap, void *payload, uint32_t length, uint32_t seconds, uint32_t microseconds)
|
||||||
ESP_RETURN_ON_FALSE(pcap && payload, ESP_ERR_INVALID_ARG, TAG, "invalid argumnet");
|
{
|
||||||
size_t real_write = 0;
|
ESP_RETURN_ON_FALSE(pcap && payload, ESP_ERR_INVALID_ARG, TAG, "invalid argumnet");
|
||||||
pcap_packet_header_t header = {
|
size_t real_write = 0;
|
||||||
.seconds = seconds,
|
pcap_packet_header_t header = {
|
||||||
.microseconds = microseconds,
|
.seconds = seconds,
|
||||||
.capture_length = length,
|
.microseconds = microseconds,
|
||||||
.packet_length = length
|
.capture_length = length,
|
||||||
};
|
.packet_length = length
|
||||||
real_write = fwrite(&header, sizeof(header), 1, pcap->file);
|
};
|
||||||
ESP_RETURN_ON_FALSE(real_write == 1, ESP_FAIL, TAG, "write packet header failed");
|
real_write = fwrite(&header, sizeof(header), 1, pcap->file);
|
||||||
real_write = fwrite(payload, sizeof(uint8_t), length, pcap->file);
|
ESP_RETURN_ON_FALSE(real_write == 1, ESP_FAIL, TAG, "write packet header failed");
|
||||||
ESP_RETURN_ON_FALSE(real_write == length, ESP_FAIL, TAG, "write packet payload failed");
|
real_write = fwrite(payload, sizeof(uint8_t), length, pcap->file);
|
||||||
/* Flush content in the buffer into device */
|
ESP_RETURN_ON_FALSE(real_write == length, ESP_FAIL, TAG, "write packet payload failed");
|
||||||
fflush(pcap->file);
|
/* Flush content in the buffer into device */
|
||||||
return ESP_OK;
|
fflush(pcap->file);
|
||||||
}
|
return ESP_OK;
|
||||||
|
}
|
||||||
esp_err_t pcap_print_summary(pcap_file_handle_t pcap, FILE *print_file)
|
|
||||||
{
|
esp_err_t pcap_print_summary(pcap_file_handle_t pcap, FILE *print_file)
|
||||||
esp_err_t ret = ESP_OK;
|
{
|
||||||
long size = 0;
|
esp_err_t ret = ESP_OK;
|
||||||
char *packet_payload = NULL;
|
long size = 0;
|
||||||
ESP_RETURN_ON_FALSE(pcap && print_file, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
char *packet_payload = NULL;
|
||||||
// get file size
|
ESP_RETURN_ON_FALSE(pcap && print_file, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
||||||
fseek(pcap->file, 0L, SEEK_END);
|
// get file size
|
||||||
size = ftell(pcap->file);
|
fseek(pcap->file, 0L, SEEK_END);
|
||||||
fseek(pcap->file, 0L, SEEK_SET);
|
size = ftell(pcap->file);
|
||||||
// file empty is allowed, so return ESP_OK
|
fseek(pcap->file, 0L, SEEK_SET);
|
||||||
ESP_RETURN_ON_FALSE(size, ESP_OK, TAG, "pcap file is empty");
|
// file empty is allowed, so return ESP_OK
|
||||||
// packet index (by bytes)
|
ESP_RETURN_ON_FALSE(size, ESP_OK, TAG, "pcap file is empty");
|
||||||
uint32_t index = 0;
|
// packet index (by bytes)
|
||||||
pcap_file_header_t file_header;
|
uint32_t index = 0;
|
||||||
size_t real_read = fread(&file_header, sizeof(pcap_file_header_t), 1, pcap->file);
|
pcap_file_header_t file_header;
|
||||||
ESP_RETURN_ON_FALSE(real_read == 1, ESP_FAIL, TAG, "read pcap file header failed");
|
size_t real_read = fread(&file_header, sizeof(pcap_file_header_t), 1, pcap->file);
|
||||||
index += sizeof(pcap_file_header_t);
|
ESP_RETURN_ON_FALSE(real_read == 1, ESP_FAIL, TAG, "read pcap file header failed");
|
||||||
//print pcap header information
|
index += sizeof(pcap_file_header_t);
|
||||||
fprintf(print_file, "------------------------------------------------------------------------\n");
|
//print pcap header information
|
||||||
fprintf(print_file, "Pcap packet Head:\n");
|
fprintf(print_file, "------------------------------------------------------------------------\n");
|
||||||
fprintf(print_file, "------------------------------------------------------------------------\n");
|
fprintf(print_file, "Pcap packet Head:\n");
|
||||||
fprintf(print_file, "Magic Number: %x\n", file_header.magic);
|
fprintf(print_file, "------------------------------------------------------------------------\n");
|
||||||
fprintf(print_file, "Major Version: %d\n", file_header.major);
|
fprintf(print_file, "Magic Number: %"PRIx32"\n", file_header.magic);
|
||||||
fprintf(print_file, "Minor Version: %d\n", file_header.minor);
|
fprintf(print_file, "Major Version: %d\n", file_header.major);
|
||||||
fprintf(print_file, "SnapLen: %d\n", file_header.snaplen);
|
fprintf(print_file, "Minor Version: %d\n", file_header.minor);
|
||||||
fprintf(print_file, "LinkType: %d\n", file_header.link_type);
|
fprintf(print_file, "SnapLen: %"PRIu32"\n", file_header.snaplen);
|
||||||
fprintf(print_file, "------------------------------------------------------------------------\n");
|
fprintf(print_file, "LinkType: %"PRIu32"\n", file_header.link_type);
|
||||||
uint32_t packet_num = 0;
|
fprintf(print_file, "------------------------------------------------------------------------\n");
|
||||||
pcap_packet_header_t packet_header;
|
uint32_t packet_num = 0;
|
||||||
while (index < size) {
|
pcap_packet_header_t packet_header;
|
||||||
real_read = fread(&packet_header, sizeof(pcap_packet_header_t), 1, pcap->file);
|
while (index < size) {
|
||||||
ESP_GOTO_ON_FALSE(real_read == 1, ESP_FAIL, err, TAG, "read pcap packet header failed");
|
real_read = fread(&packet_header, sizeof(pcap_packet_header_t), 1, pcap->file);
|
||||||
// print packet header information
|
ESP_GOTO_ON_FALSE(real_read == 1, ESP_FAIL, err, TAG, "read pcap packet header failed");
|
||||||
fprintf(print_file, "Packet %d:\n", packet_num);
|
// print packet header information
|
||||||
fprintf(print_file, "Timestamp (Seconds): %d\n", packet_header.seconds);
|
fprintf(print_file, "Packet %"PRIu32":\n", packet_num);
|
||||||
fprintf(print_file, "Timestamp (Microseconds): %d\n", packet_header.microseconds);
|
fprintf(print_file, "Timestamp (Seconds): %"PRIu32"\n", packet_header.seconds);
|
||||||
fprintf(print_file, "Capture Length: %d\n", packet_header.capture_length);
|
fprintf(print_file, "Timestamp (Microseconds): %"PRIu32"\n", packet_header.microseconds);
|
||||||
fprintf(print_file, "Packet Length: %d\n", packet_header.packet_length);
|
fprintf(print_file, "Capture Length: %"PRIu32"\n", packet_header.capture_length);
|
||||||
size_t payload_length = packet_header.capture_length;
|
fprintf(print_file, "Packet Length: %"PRIu32"\n", packet_header.packet_length);
|
||||||
packet_payload = malloc(payload_length);
|
size_t payload_length = packet_header.capture_length;
|
||||||
ESP_GOTO_ON_FALSE(packet_payload, ESP_ERR_NO_MEM, err, TAG, "no mem to save packet payload");
|
packet_payload = malloc(payload_length);
|
||||||
real_read = fread(packet_payload, payload_length, 1, pcap->file);
|
ESP_GOTO_ON_FALSE(packet_payload, ESP_ERR_NO_MEM, err, TAG, "no mem to save packet payload");
|
||||||
ESP_GOTO_ON_FALSE(real_read == 1, ESP_FAIL, err, TAG, "read payload error");
|
real_read = fread(packet_payload, payload_length, 1, pcap->file);
|
||||||
// print packet information
|
ESP_GOTO_ON_FALSE(real_read == 1, ESP_FAIL, err, TAG, "read payload error");
|
||||||
if (file_header.link_type == PCAP_LINK_TYPE_802_11) {
|
// print packet information
|
||||||
// Frame Control Field is coded as LSB first
|
if (file_header.link_type == PCAP_LINK_TYPE_802_11) {
|
||||||
fprintf(print_file, "Frame Type: %2x\n", (packet_payload[0] >> 2) & 0x03);
|
// Frame Control Field is coded as LSB first
|
||||||
fprintf(print_file, "Frame Subtype: %2x\n", (packet_payload[0] >> 4) & 0x0F);
|
fprintf(print_file, "Frame Type: %2x\n", (packet_payload[0] >> 2) & 0x03);
|
||||||
fprintf(print_file, "Destination: ");
|
fprintf(print_file, "Frame Subtype: %2x\n", (packet_payload[0] >> 4) & 0x0F);
|
||||||
for (int j = 0; j < 5; j++) {
|
fprintf(print_file, "Destination: ");
|
||||||
fprintf(print_file, "%2x ", packet_payload[4 + j]);
|
for (int j = 0; j < 5; j++) {
|
||||||
}
|
fprintf(print_file, "%2x ", packet_payload[4 + j]);
|
||||||
fprintf(print_file, "%2x\n", packet_payload[9]);
|
}
|
||||||
fprintf(print_file, "Source: ");
|
fprintf(print_file, "%2x\n", packet_payload[9]);
|
||||||
for (int j = 0; j < 5; j++) {
|
fprintf(print_file, "Source: ");
|
||||||
fprintf(print_file, "%2x ", packet_payload[10 + j]);
|
for (int j = 0; j < 5; j++) {
|
||||||
}
|
fprintf(print_file, "%2x ", packet_payload[10 + j]);
|
||||||
fprintf(print_file, "%2x\n", packet_payload[15]);
|
}
|
||||||
fprintf(print_file, "------------------------------------------------------------------------\n");
|
fprintf(print_file, "%2x\n", packet_payload[15]);
|
||||||
} else if (file_header.link_type == PCAP_LINK_TYPE_ETHERNET) {
|
fprintf(print_file, "------------------------------------------------------------------------\n");
|
||||||
fprintf(print_file, "Destination: ");
|
} else if (file_header.link_type == PCAP_LINK_TYPE_ETHERNET) {
|
||||||
for (int j = 0; j < 5; j++) {
|
fprintf(print_file, "Destination: ");
|
||||||
fprintf(print_file, "%2x ", packet_payload[j]);
|
for (int j = 0; j < 5; j++) {
|
||||||
}
|
fprintf(print_file, "%2x ", packet_payload[j]);
|
||||||
fprintf(print_file, "%2x\n", packet_payload[5]);
|
}
|
||||||
fprintf(print_file, "Source: ");
|
fprintf(print_file, "%2x\n", packet_payload[5]);
|
||||||
for (int j = 0; j < 5; j++) {
|
fprintf(print_file, "Source: ");
|
||||||
fprintf(print_file, "%2x ", packet_payload[6 + j]);
|
for (int j = 0; j < 5; j++) {
|
||||||
}
|
fprintf(print_file, "%2x ", packet_payload[6 + j]);
|
||||||
fprintf(print_file, "%2x\n", packet_payload[11]);
|
}
|
||||||
fprintf(print_file, "Type: 0x%x\n", packet_payload[13] | (packet_payload[12] << 8));
|
fprintf(print_file, "%2x\n", packet_payload[11]);
|
||||||
fprintf(print_file, "------------------------------------------------------------------------\n");
|
fprintf(print_file, "Type: 0x%x\n", packet_payload[13] | (packet_payload[12] << 8));
|
||||||
} else {
|
fprintf(print_file, "------------------------------------------------------------------------\n");
|
||||||
fprintf(print_file, "Unknown link type:%d\n", file_header.link_type);
|
} else {
|
||||||
fprintf(print_file, "------------------------------------------------------------------------\n");
|
fprintf(print_file, "Unknown link type:%"PRIu32"\n", file_header.link_type);
|
||||||
}
|
fprintf(print_file, "------------------------------------------------------------------------\n");
|
||||||
free(packet_payload);
|
}
|
||||||
packet_payload = NULL;
|
free(packet_payload);
|
||||||
index += packet_header.capture_length + sizeof(pcap_packet_header_t);
|
packet_payload = NULL;
|
||||||
packet_num ++;
|
index += packet_header.capture_length + sizeof(pcap_packet_header_t);
|
||||||
}
|
packet_num ++;
|
||||||
fprintf(print_file, "Pcap packet Number: %d\n", packet_num);
|
}
|
||||||
fprintf(print_file, "------------------------------------------------------------------------\n");
|
fprintf(print_file, "Pcap packet Number: %"PRIu32"\n", packet_num);
|
||||||
return ret;
|
fprintf(print_file, "------------------------------------------------------------------------\n");
|
||||||
err:
|
return ret;
|
||||||
if (packet_payload) {
|
err:
|
||||||
free(packet_payload);
|
if (packet_payload) {
|
||||||
}
|
free(packet_payload);
|
||||||
return ret;
|
}
|
||||||
}
|
return ret;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue