aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/net/ipv4/header.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/golang.org/x/net/ipv4/header.go')
-rw-r--r--vendor/golang.org/x/net/ipv4/header.go35
1 files changed, 24 insertions, 11 deletions
diff --git a/vendor/golang.org/x/net/ipv4/header.go b/vendor/golang.org/x/net/ipv4/header.go
index 8bb0f0f..a00a3ea 100644
--- a/vendor/golang.org/x/net/ipv4/header.go
+++ b/vendor/golang.org/x/net/ipv4/header.go
@@ -9,15 +9,13 @@ import (
"fmt"
"net"
"runtime"
- "syscall"
"golang.org/x/net/internal/socket"
)
const (
- Version = 4 // protocol version
- HeaderLen = 20 // header length without extension headers
- maxHeaderLen = 60 // sensible default, revisit if later RFCs define new usage of version and header length fields
+ Version = 4 // protocol version
+ HeaderLen = 20 // header length without extension headers
)
type HeaderFlags int
@@ -52,9 +50,13 @@ func (h *Header) String() string {
}
// Marshal returns the binary encoding of h.
+//
+// The returned slice is in the format used by a raw IP socket on the
+// local system.
+// This may differ from the wire format, depending on the system.
func (h *Header) Marshal() ([]byte, error) {
if h == nil {
- return nil, syscall.EINVAL
+ return nil, errNilHeader
}
if h.Len < HeaderLen {
return nil, errHeaderTooShort
@@ -65,7 +67,7 @@ func (h *Header) Marshal() ([]byte, error) {
b[1] = byte(h.TOS)
flagsAndFragOff := (h.FragOff & 0x1fff) | int(h.Flags<<13)
switch runtime.GOOS {
- case "darwin", "dragonfly", "netbsd":
+ case "darwin", "ios", "dragonfly", "netbsd":
socket.NativeEndian.PutUint16(b[2:4], uint16(h.TotalLen))
socket.NativeEndian.PutUint16(b[6:8], uint16(flagsAndFragOff))
case "freebsd":
@@ -98,14 +100,21 @@ func (h *Header) Marshal() ([]byte, error) {
return b, nil
}
-// Parse parses b as an IPv4 header and sotres the result in h.
+// Parse parses b as an IPv4 header and stores the result in h.
+//
+// The provided b must be in the format used by a raw IP socket on the
+// local system.
+// This may differ from the wire format, depending on the system.
func (h *Header) Parse(b []byte) error {
- if h == nil || len(b) < HeaderLen {
+ if h == nil || b == nil {
+ return errNilHeader
+ }
+ if len(b) < HeaderLen {
return errHeaderTooShort
}
hdrlen := int(b[0]&0x0f) << 2
- if hdrlen > len(b) {
- return errBufferTooShort
+ if len(b) < hdrlen {
+ return errExtHeaderTooShort
}
h.Version = int(b[0] >> 4)
h.Len = hdrlen
@@ -117,7 +126,7 @@ func (h *Header) Parse(b []byte) error {
h.Src = net.IPv4(b[12], b[13], b[14], b[15])
h.Dst = net.IPv4(b[16], b[17], b[18], b[19])
switch runtime.GOOS {
- case "darwin", "dragonfly", "netbsd":
+ case "darwin", "ios", "dragonfly", "netbsd":
h.TotalLen = int(socket.NativeEndian.Uint16(b[2:4])) + hdrlen
h.FragOff = int(socket.NativeEndian.Uint16(b[6:8]))
case "freebsd":
@@ -150,6 +159,10 @@ func (h *Header) Parse(b []byte) error {
}
// ParseHeader parses b as an IPv4 header.
+//
+// The provided b must be in the format used by a raw IP socket on the
+// local system.
+// This may differ from the wire format, depending on the system.
func ParseHeader(b []byte) (*Header, error) {
h := new(Header)
if err := h.Parse(b); err != nil {