فهرست منبع

Merge "icmp: prevent stripping off ipv4 header twice on darwin"

Mikio Hara 11 سال پیش
والد
کامیت
3329bfea7d
1فایلهای تغییر یافته به همراه10 افزوده شده و 0 حذف شده
  1. 10 0
      icmp/endpoint.go

+ 10 - 0
icmp/endpoint.go

@@ -6,6 +6,7 @@ package icmp
 
 import (
 	"net"
+	"runtime"
 	"syscall"
 	"time"
 
@@ -51,6 +52,15 @@ func (c *PacketConn) ReadFrom(b []byte) (int, net.Addr, error) {
 	if !c.ok() {
 		return 0, nil, syscall.EINVAL
 	}
+	// Please be informed that ipv4.NewPacketConn enables
+	// IP_STRIPHDR option by default on Darwin.
+	// See golang.org/issue/9395 for futher information.
+	if runtime.GOOS == "darwin" {
+		if p, _ := c.ipc.(*ipv4.PacketConn); p != nil {
+			n, _, peer, err := p.ReadFrom(b)
+			return n, peer, err
+		}
+	}
 	return c.c.ReadFrom(b)
 }