Skip to content

Commit

Permalink
Add support for IPv6 packet
Browse files Browse the repository at this point in the history
Signed-off-by: wenyingd <[email protected]>
  • Loading branch information
wenyingd committed Jul 2, 2020
1 parent 3a6722c commit f1a5f0e
Show file tree
Hide file tree
Showing 4 changed files with 692 additions and 5 deletions.
7 changes: 3 additions & 4 deletions protocol/icmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ func (i *ICMP) MarshalBinary() (data []byte, err error) {

func (i *ICMP) UnmarshalBinary(data []byte) error {
if len(data) < 4 {
return errors.New("The []byte is too short to unmarshal a full ARP message.")
return errors.New("The []byte is too short to unmarshal a full ICMP message.")
}
i.Type = data[0]
i.Code = data[1]
i.Checksum = binary.BigEndian.Uint16(data[2:4])

for n := range data[4:] {
i.Data = append(i.Data, data[n])
}
i.Data = make([]byte, len(data)-4)
copy(i.Data, data[4:])
return nil
}
5 changes: 4 additions & 1 deletion protocol/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ func (i *IPv4) UnmarshalBinary(data []byte) error {
i.NWDst = data[n : n+4]
n += 4

i.Options.UnmarshalBinary(data[n:int(i.IHL*4)])
err := i.Options.UnmarshalBinary(data[n:int(i.IHL*4)])
if err != nil {
return err
}
n += int(i.IHL*4) - n

switch i.Protocol {
Expand Down
Loading

0 comments on commit f1a5f0e

Please sign in to comment.