diff options
| author | 童宗振 <[email protected]> | 2024-04-23 02:26:47 +0000 |
|---|---|---|
| committer | 童宗振 <[email protected]> | 2024-04-23 02:26:47 +0000 |
| commit | 5d6fa40f1b05d44bb60edc9f1564422730abf531 (patch) | |
| tree | fa32ff0ee1106e074960449650ad5ed686254a93 | |
| parent | f36644de967ba18917907b4aa86484936c14c4ad (diff) | |
| parent | 9e35015f8333fa4d255c9936c702568d82cb7143 (diff) | |
Merge branch 'fix_pcapng_align_error' into 'master'v0.1.3-20240423
Fix pcapng align error
See merge request tsg/dp_telemetry_app!20
| -rw-r--r-- | support/pcapng/README.md | 8 | ||||
| -rw-r--r-- | support/pcapng/pcapng.c | 13 |
2 files changed, 16 insertions, 5 deletions
diff --git a/support/pcapng/README.md b/support/pcapng/README.md new file mode 100644 index 0000000..7cc1b09 --- /dev/null +++ b/support/pcapng/README.md @@ -0,0 +1,8 @@ +## introduce + +1. This code is transplanted from [dpdk-pcapng](https://github.com/DPDK/dpdk/tree/v21.11/lib/pcapng) and depends on marsio.h + +## todo + +1. Documentation supplement for the migration process +2. Unit testing -- this is a bit difficult
\ No newline at end of file diff --git a/support/pcapng/pcapng.c b/support/pcapng/pcapng.c index b0bf050..5d2afd3 100644 --- a/support/pcapng/pcapng.c +++ b/support/pcapng/pcapng.c @@ -190,22 +190,25 @@ int pcapng_copy(marsio_buff_t * mbuf, uint32_t snaplen, const char * comment, { uint32_t orig_len = 0; uint32_t data_len = 0; + uint32_t pedding_data_len = 0; uint64_t timestamp; uint32_t len = 0; + uint32_t optlen = 0; struct pcapng_option * opt = NULL; orig_len = marsio_buff_buflen(mbuf); data_len = marsio_buff_datalen(mbuf); data_len = snaplen < data_len ? snaplen : data_len; - len += sizeof(struct pcapng_enhance_packet_block); - len += data_len; + // All blocks in a PcapNG file must be aligned to a 32 bit boundary. + pedding_data_len = ALIGN(data_len, sizeof(uint32_t)); if (comment) { - len += pcapng_optlen(strlen(comment)); + optlen += pcapng_optlen(strlen(comment)); } - len += sizeof(uint32_t); /* Block length */ + + len = sizeof(struct pcapng_enhance_packet_block) + pedding_data_len + optlen + sizeof(uint32_t); /* Note: END_OPT necessary here. Wireshark doesn't do it. */ @@ -229,7 +232,7 @@ int pcapng_copy(marsio_buff_t * mbuf, uint32_t snaplen, const char * comment, memcpy((char *)epb + sizeof(*epb), marsio_buff_mtod(mbuf), data_len); - opt = (struct pcapng_option *)((char *)epb + sizeof(*epb) + data_len); + opt = (struct pcapng_option *)((char *)epb + sizeof(*epb) + pedding_data_len); if (comment) { |
