Skip to content

Commit

Permalink
icmp: drop the use of syscall package in platform-independent code
Browse files Browse the repository at this point in the history
Also re-adjusts build constraints on stubs.

Change-Id: I9c6d8487e17bb1f9e5204e363938a67a7f646c1c
Reviewed-on: https://go-review.googlesource.com/121881
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
  • Loading branch information
cixtor committed Jul 2, 2018
1 parent 87b3feb commit a46fb68
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
13 changes: 6 additions & 7 deletions icmp/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package icmp
import (
"net"
"runtime"
"syscall"
"time"

"golang.org/x/net/ipv4"
Expand Down Expand Up @@ -47,7 +46,7 @@ func (c *PacketConn) IPv6PacketConn() *ipv6.PacketConn {
// ReadFrom reads an ICMP message from the connection.
func (c *PacketConn) ReadFrom(b []byte) (int, net.Addr, error) {
if !c.ok() {
return 0, nil, syscall.EINVAL
return 0, nil, errInvalidConn
}
// Please be informed that ipv4.NewPacketConn enables
// IP_STRIPHDR option by default on Darwin.
Expand All @@ -64,15 +63,15 @@ func (c *PacketConn) ReadFrom(b []byte) (int, net.Addr, error) {
// datagram-oriented ICMP endpoint. Otherwise it must be net.IPAddr.
func (c *PacketConn) WriteTo(b []byte, dst net.Addr) (int, error) {
if !c.ok() {
return 0, syscall.EINVAL
return 0, errInvalidConn
}
return c.c.WriteTo(b, dst)
}

// Close closes the endpoint.
func (c *PacketConn) Close() error {
if !c.ok() {
return syscall.EINVAL
return errInvalidConn
}
return c.c.Close()
}
Expand All @@ -89,7 +88,7 @@ func (c *PacketConn) LocalAddr() net.Addr {
// endpoint.
func (c *PacketConn) SetDeadline(t time.Time) error {
if !c.ok() {
return syscall.EINVAL
return errInvalidConn
}
return c.c.SetDeadline(t)
}
Expand All @@ -98,7 +97,7 @@ func (c *PacketConn) SetDeadline(t time.Time) error {
// endpoint.
func (c *PacketConn) SetReadDeadline(t time.Time) error {
if !c.ok() {
return syscall.EINVAL
return errInvalidConn
}
return c.c.SetReadDeadline(t)
}
Expand All @@ -107,7 +106,7 @@ func (c *PacketConn) SetReadDeadline(t time.Time) error {
// endpoint.
func (c *PacketConn) SetWriteDeadline(t time.Time) error {
if !c.ok() {
return syscall.EINVAL
return errInvalidConn
}
return c.c.SetWriteDeadline(t)
}
2 changes: 1 addition & 1 deletion icmp/listen_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build js nacl plan9
// +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows

package icmp

Expand Down
6 changes: 3 additions & 3 deletions icmp/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"encoding/binary"
"errors"
"net"
"syscall"

"golang.org/x/net/internal/iana"
"golang.org/x/net/ipv4"
Expand All @@ -28,6 +27,7 @@ import (
// BUG(mikio): This package is not implemented on JS, NaCl and Plan 9.

var (
errInvalidConn = errors.New("invalid connection")
errMessageTooShort = errors.New("message too short")
errHeaderTooShort = errors.New("header too short")
errBufferTooShort = errors.New("buffer too short")
Expand Down Expand Up @@ -80,7 +80,7 @@ func (m *Message) Marshal(psh []byte) ([]byte, error) {
case ipv6.ICMPType:
mtype = int(typ)
default:
return nil, syscall.EINVAL
return nil, errInvalidConn
}
b := []byte{byte(mtype), byte(m.Code), 0, 0}
if m.Type.Protocol() == iana.ProtocolIPv6ICMP && psh != nil {
Expand Down Expand Up @@ -143,7 +143,7 @@ func ParseMessage(proto int, b []byte) (*Message, error) {
case iana.ProtocolIPv6ICMP:
m.Type = ipv6.ICMPType(b[0])
default:
return nil, syscall.EINVAL
return nil, errInvalidConn
}
if fn, ok := parseFns[m.Type]; !ok {
m.Body, err = parseDefaultMessageBody(proto, b[4:])
Expand Down

0 comments on commit a46fb68

Please sign in to comment.