JulianSchmid / etherparse

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

Why is ip_payload_ref optional? #89

Closed pronebird closed 4 months ago

pronebird commented 4 months ago

Hi,

Noticed today that NetSlice::ip_payload_ref() returns Option<&IpPayloadSlice<'a>> but can't really figure out the reason why because it seems that both IPv4/6 have payload. Is it some smart trick or a genuine omission?

impl<'a> NetSlice<'a> {
    /// Returns a reference to ip payload if the net slice contains
    /// an ipv4 or ipv6 slice.
    #[inline]
    pub fn ip_payload_ref(&self) -> Option<&IpPayloadSlice<'a>> {
        match self {
            NetSlice::Ipv4(s) => Some(&s.payload),
            NetSlice::Ipv6(s) => Some(&s.payload),
        }
    }
}
JulianSchmid commented 4 months ago

Hi @pronebird ,

I made it an optional as ARP might be added as a value to NetSlice in the future (see https://github.com/JulianSchmid/etherparse/issues/81 for more details).

Greets Julian

pronebird commented 4 months ago

Got it. Thanks