mirror of
https://github.com/daeuniverse/dae.git
synced 2024-12-23 01:04:40 +07:00
e71c272693
Co-authored-by: Kevin Yu <yqlbu@Bu.edu>
28 lines
770 B
Go
28 lines
770 B
Go
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
* Copyright (c) 2022-2023, daeuniverse Organization <dae@v2raya.org>
|
|
*/
|
|
|
|
package control
|
|
|
|
import (
|
|
"net"
|
|
"net/netip"
|
|
"strconv"
|
|
|
|
"github.com/daeuniverse/dae/common/consts"
|
|
)
|
|
|
|
func RefineSourceToShow(src netip.AddrPort, dst netip.Addr, lanWanFlag consts.LanWanFlag) (srcToShow string) {
|
|
if lanWanFlag == consts.LanWanFlag_IsWan || src.Addr() == dst {
|
|
// 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())))
|
|
}
|