You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
560 B
30 lines
560 B
// Copyright (c) Tailscale Inc & contributors
|
|
// 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
|
|
}
|
|
|