mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-12-25 15:05:38 +08:00
27 lines
482 B
Go
27 lines
482 B
Go
package libbox
|
|
|
|
import (
|
|
"fmt"
|
|
"syscall"
|
|
"unsafe"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
const ifReqSize = unix.IFNAMSIZ + 64
|
|
|
|
func getTunnelName(fd int32) (string, error) {
|
|
var ifr [ifReqSize]byte
|
|
var errno syscall.Errno
|
|
_, _, errno = unix.Syscall(
|
|
unix.SYS_IOCTL,
|
|
uintptr(fd),
|
|
uintptr(unix.TUNGETIFF),
|
|
uintptr(unsafe.Pointer(&ifr[0])),
|
|
)
|
|
if errno != 0 {
|
|
return "", fmt.Errorf("failed to get name of TUN device: %w", errno)
|
|
}
|
|
return unix.ByteSliceToString(ifr[:]), nil
|
|
}
|