You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailscale/net/sockstats/sockstats_tsgo_darwin.go

31 lines
555 B
Go

// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
//go:build tailscale_go && (darwin || ios)
package sockstats
import (
"syscall"
"golang.org/x/sys/unix"
)
func init() {
tcpConnStats = darwinTcpConnStats
}
func darwinTcpConnStats(c syscall.RawConn) (tx, rx uint64) {
c.Control(func(fd uintptr) {
if rawInfo, err := unix.GetsockoptTCPConnectionInfo(
int(fd),
unix.IPPROTO_TCP,
unix.TCP_CONNECTION_INFO,
); err == nil {
tx = uint64(rawInfo.Txbytes)
rx = uint64(rawInfo.Rxbytes)
}
})
return
}