seladb / PcapPlusPlus

PcapPlusPlus is a multiplatform C++ library for capturing, parsing and crafting of network packets. It is designed to be efficient, powerful and easy to use. It provides C++ wrappers for the most popular packet processing engines such as libpcap, Npcap, WinPcap, DPDK, AF_XDP and PF_RING.
https://pcapplusplus.github.io/
The Unlicense
2.68k stars 648 forks source link

getRawPacketReadOnly() const-correctness #1573

Open luizfeldmann opened 6 days ago

luizfeldmann commented 6 days ago

Hi,

It seems that both the read-only and non-read-only getters of the raw packet from the parsed packet have the exact same signature and behaviour:

RawPacket* getRawPacket() const;
RawPacket* getRawPacketReadOnly() const;

Wouldn't it be more correct to declare the read-only getter as returning a pointer-to-const, and similarly, the non-read-only method not be marked as const method as it can alter the underlying object ?

RawPacket* getRawPacket();
const RawPacket* getRawPacketReadOnly() const;

Best regards,

tigercosmos commented 6 days ago

Yes, it's a bug.

egecetin commented 2 days ago

@luizfeldmann Feel free to open a PR to fix it if you have time. Contributions are welcome!