Skip to content

Commit

Permalink
icmp: clarify the format used by raw ICMP socket
Browse files Browse the repository at this point in the history
On BSD variaints, for some historical reason, the data format used by raw
ICMP socket may differ from the IPv4 wire format and the format used by
raw IP socket. This change clarifies that input of ParseIPv4Header must
conform to the raw ICMP socket format.

Change-Id: I7288eccaaae0662d0437794098c8f7fc4a55d81e
Reviewed-on: https://go-review.googlesource.com/128216
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
cixtor committed Aug 8, 2018
1 parent b6095f6 commit f9ce57c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions icmp/ipv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ import (
// See http://www.freebsd.org/doc/en/books/porters-handbook/freebsd-versions.html.
var freebsdVersion uint32

// ParseIPv4Header parses b as an IPv4 header of ICMP error message
// invoking packet, which is contained in ICMP error message.
// ParseIPv4Header returns the IPv4 header of the IPv4 packet that
// triggered an ICMP error message.
// This is found in the Data field of the ICMP error message body.
//
// The provided b must be in the format used by a raw ICMP socket on
// the local system.
// This may differ from the wire format, and the format used by a raw
// IP socket, depending on the system.
//
// To parse an IPv6 header, use ipv6.ParseHeader.
func ParseIPv4Header(b []byte) (*ipv4.Header, error) {
if len(b) < ipv4.HeaderLen {
return nil, errHeaderTooShort
Expand Down

0 comments on commit f9ce57c

Please sign in to comment.