Skip to content

Commit

Permalink
Docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessOne91 committed Jun 12, 2024
1 parent 055cf39 commit cce2120
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion protocols/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type IPPacket interface {
Header() IPHeader
}

// IPHeader defines method supported both IPv4 and IPv6 headers
type IPHeader interface {
Len() int
TransportLayerProtocol() string
Expand Down Expand Up @@ -75,6 +76,8 @@ var errIPv4HeaderTooShort = errors.New("IPv4 header must be at least 20 bytes")
var errIPv4HeaderLenLessThanIHL = errors.New("IPv4 header length less than indicated IHL")
var errInvalidIPv6Header = errors.New("IPv6 header must be 40 bytes")

// IPPacketFromBytes parses an IPv4 or IPv6 packet's data from the passed raw data and return the interface representing it.
// An error is returned if the headers' constraints are not respected.
func IPPacketFromBytes(raw []byte) (IPPacket, error) {
if len(raw) < 15 {
return nil, errInvalidIPPacket
Expand Down Expand Up @@ -197,7 +200,7 @@ func ipv4HeaderFromBytes(raw []byte) (*ipv4Header, error) {
return h, nil
}

// ipv6PacketsFromFromBytes parses an array of bytes to extract headers and payload, returning a struct pointer.
// ipv6PacketsFromFromBytes parses a slice of bytes to extract headers and payload, returning a struct pointer.
func ipv6PacketFromBytes(raw []byte) (*ipv6Packet, error) {
frame, err := EthFrameFromBytes(raw)
if err != nil {
Expand Down

0 comments on commit cce2120

Please sign in to comment.