Allow users to access IP/TCP/UDP headers
This will allow users to access packet metadata without needing to parse the "parsedPacket" string, and will also allow them to access the packet data present after the headers for further computation, because the header addresses are now exposed.
The IPHeader, TCPHeader, UDPHeader structs have been moved outside PacketFragmentArgs to allow definition of properties with the same name. They have been converted from structs to class to make them into reference types and therefore have the homonymic properties return null if the corresponding header was not successfully parsed by ParsePacket().
I am proposing this change because I need to parse DNS request/response in packets, and it is almost impossible to do it with the current class structure without duplicating the code of FIndIpHeader(), and I think that it's much cleaner to expose the headers themselves rather than just exposing FindIpHeader() and having the users duplicate the parsing logic.
@brianrob could you please review? This is the last bit I need for my own ETL parsing tool which interprets DNS data. Thanks! :)
@lupino3 thanks for submitting. I will need a bit of time to look through this, but consider this an ack.
Sure, thanks @brianrob. Note that the diff algorithm is fooled by my addition of two extra properties. I didn't change a lot in the body of the existing ParsedPacket getter, which is now moved to ParsePacket() to make sure it's invoked for any of the properties that need parsing.
The only changes there are storing the parsed packet, IP/TCP/UDP headers in a private class attribute, which is then returned by the corresponding property.
I also added a parsed boolean to avoid running the parsing code multiple times for no reason (the result will always be the same).
Hope the change makes sense! Thanks.