diff --git a/tracer/stop_handler.go b/tracer/stop_handler.go index a2d16ec..9e07c11 100644 --- a/tracer/stop_handler.go +++ b/tracer/stop_handler.go @@ -258,9 +258,9 @@ func (t *Tracer) network(socketInfo *SocketMetadata) string { func (t *Tracer) handleINet4(socketInfo *SocketMetadata, bSockAddr []byte) (sockAddrToPock []byte, err error) { network := t.network(socketInfo) - port := t.port(socketInfo) + portSentTo := t.port(socketInfo) addr := *(*RawSockaddrInet4)(unsafe.Pointer(&bSockAddr[0])) - if ip := netaddr.IPFrom4(addr.Addr); ip.IsLoopback() && port != 53 { + if ip := netaddr.IPFrom4(addr.Addr); ip.IsLoopback() && binary.BigEndian.Uint16(addr.Port[:]) != 53 { // skip loopback t.log.Tracef("skip loopback: %v", netaddr.IPPortFrom(ip, binary.BigEndian.Uint16(addr.Port[:])).String()) return nil, nil @@ -280,7 +280,7 @@ func (t *Tracer) handleINet4(socketInfo *SocketMetadata, bSockAddr []byte) (sock } loopback := t.proxy.AllocProjection(originAddr) addr.Addr = loopback.As4() - binary.BigEndian.PutUint16(addr.Port[:], uint16(port)) + binary.BigEndian.PutUint16(addr.Port[:], uint16(portSentTo)) //logrus.Traceln("port", addr.Port) _bSockAddrToPock := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{ Data: uintptr(unsafe.Pointer(&addr)), @@ -289,20 +289,20 @@ func (t *Tracer) handleINet4(socketInfo *SocketMetadata, bSockAddr []byte) (sock })) bSockAddrToPock := make([]byte, len(_bSockAddrToPock)) copy(bSockAddrToPock, _bSockAddrToPock) - t.log.Tracef("handleINet4 (%v): origin: %v, after: %v", network, originAddr, net.JoinHostPort(loopback.String(), strconv.Itoa(port))) + t.log.Tracef("handleINet4 (%v): origin: %v, after: %v", network, originAddr, net.JoinHostPort(loopback.String(), strconv.Itoa(portSentTo))) return bSockAddrToPock, nil } func (t *Tracer) handleINet6(socketInfo *SocketMetadata, bSockAddr []byte) (sockAddrToPock []byte, err error) { network := t.network(socketInfo) - port := t.port(socketInfo) + portSentTo := t.port(socketInfo) addr := *(*RawSockaddrInet6)(unsafe.Pointer(&bSockAddr[0])) ip := netaddr.IPFrom16(addr.Addr) if ip.Is4in6() { ip = netaddr.IPFrom4(ip.As4()) } - if ip.IsLoopback() && port != 53 { + if ip.IsLoopback() && binary.BigEndian.Uint16(addr.Port[:]) != 53 { // skip loopback t.log.Tracef("skip loopback: %v", netaddr.IPPortFrom(ip, binary.BigEndian.Uint16(addr.Port[:])).String()) return nil, nil @@ -325,13 +325,13 @@ func (t *Tracer) handleINet6(socketInfo *SocketMetadata, bSockAddr []byte) (sock return nil, err } addr.Addr = ipv4MappedIPv6.As16() - binary.BigEndian.PutUint16(addr.Port[:], uint16(port)) + binary.BigEndian.PutUint16(addr.Port[:], uint16(portSentTo)) _bSockAddrToPock := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{ Data: uintptr(unsafe.Pointer(&addr)), Cap: binary.Size(addr), Len: binary.Size(addr), })) - t.log.Tracef("handleINet6 (%v): origin: %v, after: %v", network, originAddr, net.JoinHostPort(ipv4MappedIPv6.String(), strconv.Itoa(port))) + t.log.Tracef("handleINet6 (%v): origin: %v, after: %v", network, originAddr, net.JoinHostPort(ipv4MappedIPv6.String(), strconv.Itoa(portSentTo))) bSockAddrToPock := make([]byte, len(_bSockAddrToPock)) copy(bSockAddrToPock, _bSockAddrToPock) return bSockAddrToPock, nil