JulianSchmid / etherparse

A rust library for parsing ethernet & ethernet using protocols.
Apache License 2.0
286 stars 54 forks source link

Add convenience method for parsing from ip headers and upwards #3

Closed razorheadfx closed 5 years ago

razorheadfx commented 5 years ago

First of all, lovely library you got here! While playing around with it I found that there is no apparent way of parsing an IP headers and all higher level headers in one go. So if you want it here it is:

PacketHeaders::from_ip_slice and an example/doctest.

I would have liked to add an integration test for it somewhere so as to excercise all the codepaths but could not decide on where to put it because everything in tests looks like unit tests. If you tell me where you'd put it i'd be happy to add that as well

Cheers

JulianSchmid commented 5 years ago

Thanks I wanted to add a function like this for a while, but I never got around to doing it.

Sadly I don't really have integration tests, but I have a test that tests most potentially parsable package compositions (tests/package_compositions/mod.rs). I added a test for your function there. If you have a good idea, how an integration test for a library like this would look like, let me know.

I fixed the small typo in the example, added the skipping of ipv6 header extensions & added a test to the composition tests on top of your commits.

I will probably publish your commits + mine tomorrow with the 0.8.0 release.

Thanks again for the pull request.

JulianSchmid commented 5 years ago

Your commit + a new method SlicedPacket::from_ip I added for slicing packets from to ip layer on are part of the 0.8.0 release.

Thanks for the pull request.