2023-02-01 12:14:22 +07:00
|
|
|
/*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2023-03-14 14:01:55 +07:00
|
|
|
* Copyright (c) 2022-2023, daeuniverse Organization <dae@v2raya.org>
|
2023-02-01 12:14:22 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"net/netip"
|
|
|
|
"strconv"
|
2023-04-23 12:27:29 +07:00
|
|
|
|
|
|
|
"github.com/daeuniverse/dae/common/consts"
|
2023-02-01 12:14:22 +07:00
|
|
|
)
|
|
|
|
|
2023-02-13 11:54:04 +07:00
|
|
|
func RefineSourceToShow(src netip.AddrPort, dst netip.Addr, lanWanFlag consts.LanWanFlag) (srcToShow string) {
|
|
|
|
if lanWanFlag == consts.LanWanFlag_IsWan || src.Addr() == dst {
|
2023-02-01 12:14:22 +07:00
|
|
|
// If nothing else, this means this packet is sent from localhost.
|
|
|
|
return net.JoinHostPort("localhost", strconv.Itoa(int(src.Port())))
|
|
|
|
} else {
|
|
|
|
return RefineAddrPortToShow(src)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func RefineAddrPortToShow(addrPort netip.AddrPort) (srcToShow string) {
|
|
|
|
return net.JoinHostPort(net.IP(addrPort.Addr().AsSlice()).String(), strconv.Itoa(int(addrPort.Port())))
|
|
|
|
}
|