add stringer methods

This commit is contained in:
soypat
2025-02-20 23:41:27 -03:00
parent c9d1c4f239
commit d996040d92
6 changed files with 43 additions and 4 deletions
+15
View File
@@ -3,6 +3,8 @@ package ipv4
import (
"encoding/binary"
"errors"
"fmt"
"net/netip"
"github.com/soypat/lneto/lneto2"
)
@@ -218,3 +220,16 @@ func (ifrm Frame) ValidateExceptCRC(v *lneto2.Validator) {
v.AddError(errEvil)
}
}
func (ifrm Frame) String() string {
dst := netip.AddrFrom4(*ifrm.DestinationAddr())
src := netip.AddrFrom4(*ifrm.SourceAddr())
hl := ifrm.HeaderLength()
tl := int(ifrm.TotalLength())
ttl := ifrm.TTL()
id := ifrm.ID()
proto := ifrm.Protocol()
tos := ifrm.ToS()
return fmt.Sprintf("IP %s SRC=%s DST=%s LEN=%d OPT=%d TTL=%d ID=%d ToS=0x%x", proto.String(), src.String(), dst.String(), tl, tl-hl, ttl, id, tos)
}