From b053ee646bbac0d6d26315bef6509e431f9d91b5 Mon Sep 17 00:00:00 2001 From: tsosunchia <59512455+tsosunchia@users.noreply.github.com> Date: Mon, 13 May 2024 20:39:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trace/icmp_ipv4.go | 10 ++++++++-- trace/icmp_ipv6.go | 10 ++++++++-- trace/internal/icmp_darwin.go | 10 ++++++++-- trace/tcp_ipv4.go | 5 ++++- trace/tcp_ipv6.go | 5 ++++- trace/udp.go | 5 ++++- 6 files changed, 36 insertions(+), 9 deletions(-) diff --git a/trace/icmp_ipv4.go b/trace/icmp_ipv4.go index d93aa25..6adb64f 100644 --- a/trace/icmp_ipv4.go +++ b/trace/icmp_ipv4.go @@ -286,7 +286,10 @@ func (t *ICMPTracer) send(ttl int) error { }, } - ipv4.NewPacketConn(t.icmpListen).SetTTL(ttl) + err := ipv4.NewPacketConn(t.icmpListen).SetTTL(ttl) + if err != nil { + return err + } wb, err := icmpHeader.Marshal(nil) if err != nil { @@ -328,7 +331,10 @@ func (t *ICMPTracer) send(ttl int) error { t.fetchLock.Lock() defer t.fetchLock.Unlock() - h.fetchIPData(t.Config) + err := h.fetchIPData(t.Config) + if err != nil { + return err + } t.res.add(h) case <-time.After(t.Timeout): diff --git a/trace/icmp_ipv6.go b/trace/icmp_ipv6.go index f46be27..dfd9f83 100644 --- a/trace/icmp_ipv6.go +++ b/trace/icmp_ipv6.go @@ -282,7 +282,10 @@ func (t *ICMPTracerv6) send(ttl int) error { p := ipv6.NewPacketConn(t.icmpListen) icmpHeader.Body.(*icmp.Echo).Seq = ttl - p.SetHopLimit(ttl) + err := p.SetHopLimit(ttl) + if err != nil { + return err + } wb, err := icmpHeader.Marshal(nil) if err != nil { @@ -324,7 +327,10 @@ func (t *ICMPTracerv6) send(ttl int) error { t.fetchLock.Lock() defer t.fetchLock.Unlock() - h.fetchIPData(t.Config) + err := h.fetchIPData(t.Config) + if err != nil { + return err + } t.res.add(h) diff --git a/trace/internal/icmp_darwin.go b/trace/internal/icmp_darwin.go index e919bc1..384038c 100644 --- a/trace/internal/icmp_darwin.go +++ b/trace/internal/icmp_darwin.go @@ -70,11 +70,17 @@ func ListenICMP(network string, laddr string) (net.PacketConn, error) { if ifIndex != -1 { if proto == syscall.IPPROTO_ICMP { return c.Control(func(fd uintptr) { - syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IP, syscall.IP_BOUND_IF, ifIndex) + err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IP, syscall.IP_BOUND_IF, ifIndex) + if err != nil { + return + } }) } else { return c.Control(func(fd uintptr) { - syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IPV6, syscall.IPV6_BOUND_IF, ifIndex) + err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IPV6, syscall.IPV6_BOUND_IF, ifIndex) + if err != nil { + return + } }) } } diff --git a/trace/tcp_ipv4.go b/trace/tcp_ipv4.go index cd7b32e..e173a7d 100644 --- a/trace/tcp_ipv4.go +++ b/trace/tcp_ipv4.go @@ -293,7 +293,10 @@ func (t *TCPTracer) send(ttl int) error { t.fetchLock.Lock() defer t.fetchLock.Unlock() - h.fetchIPData(t.Config) + err := h.fetchIPData(t.Config) + if err != nil { + return err + } t.res.add(h) diff --git a/trace/tcp_ipv6.go b/trace/tcp_ipv6.go index 75b6e0d..7161fe0 100644 --- a/trace/tcp_ipv6.go +++ b/trace/tcp_ipv6.go @@ -233,7 +233,10 @@ func (t *TCPTracerv6) send(ttl int) error { return err } - ipv6.NewPacketConn(t.tcp).SetHopLimit(ttl) + err := ipv6.NewPacketConn(t.tcp).SetHopLimit(ttl) + if err != nil { + return err + } if err != nil { return err } diff --git a/trace/udp.go b/trace/udp.go index ace186e..50f5622 100644 --- a/trace/udp.go +++ b/trace/udp.go @@ -264,7 +264,10 @@ func (t *UDPTracer) send(ttl int) error { t.fetchLock.Lock() defer t.fetchLock.Unlock() - h.fetchIPData(t.Config) + err := h.fetchIPData(t.Config) + if err != nil { + return err + } t.res.add(h)