summaryrefslogtreecommitdiff
path: root/utilities
diff options
context:
space:
mode:
Diffstat (limited to 'utilities')
-rw-r--r--utilities/tcpinfo_other.go18
-rw-r--r--utilities/tcpinfo_unix.go62
-rw-r--r--utilities/utilities.go54
3 files changed, 84 insertions, 50 deletions
diff --git a/utilities/tcpinfo_other.go b/utilities/tcpinfo_other.go
new file mode 100644
index 0000000..8dd070b
--- /dev/null
+++ b/utilities/tcpinfo_other.go
@@ -0,0 +1,18 @@
+//go:build !darwin && !dragonfly && !freebsd && !linux && !netbsd && !openbsd
+// +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd
+
+package utilities
+
+import (
+ "net"
+
+ "golang.org/x/sys/unix"
+)
+
+func GetTCPInfo(connection net.Conn) (*unix.TCPInfo, error) {
+ return nil, NotImplemented{Functionality: "GetTCPInfo"}
+}
+
+func PrintTCPInfo(info *unix.TCPInfo) {
+ return
+}
diff --git a/utilities/tcpinfo_unix.go b/utilities/tcpinfo_unix.go
new file mode 100644
index 0000000..b0b5252
--- /dev/null
+++ b/utilities/tcpinfo_unix.go
@@ -0,0 +1,62 @@
+//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
+
+package utilities
+
+import (
+ "fmt"
+ "net"
+
+ "golang.org/x/sys/unix"
+)
+
+func GetTCPInfo(connection net.Conn) (*unix.TCPInfo, error) {
+ tcpConn, ok := connection.(*net.TCPConn)
+ if !ok {
+ return nil, fmt.Errorf("connection is not a net.TCPConn")
+ }
+ rawConn, err := tcpConn.SyscallConn()
+ if err != nil {
+ return nil, err
+ }
+
+ var info *unix.TCPInfo = nil
+ rawConn.Control(func(fd uintptr) {
+ info, err = unix.GetsockoptTCPInfo(int(fd), unix.SOL_TCP, unix.TCP_INFO)
+ })
+ return info, err
+}
+
+func PrintTCPInfo(info *unix.TCPInfo) {
+ fmt.Printf("TCPInfo: \n")
+ fmt.Printf(" State: %v\n", info.State)
+ fmt.Printf(" Ca_state: %v\n", info.Ca_state)
+ fmt.Printf(" Retransmits: %v\n", info.Retransmits)
+ fmt.Printf(" Probes: %v\n", info.Probes)
+ fmt.Printf(" Backoff: %v\n", info.Backoff)
+ fmt.Printf(" Options: %v\n", info.Options)
+ fmt.Printf(" Rto: %v\n", info.Rto)
+ fmt.Printf(" Ato: %v\n", info.Ato)
+ fmt.Printf(" Snd_mss: %v\n", info.Snd_mss)
+ fmt.Printf(" Rcv_mss: %v\n", info.Rcv_mss)
+ fmt.Printf(" Unacked: %v\n", info.Unacked)
+ fmt.Printf(" Sacked: %v\n", info.Sacked)
+ fmt.Printf(" Lost: %v\n", info.Lost)
+ fmt.Printf(" Retrans: %v\n", info.Retrans)
+ fmt.Printf(" Fackets: %v\n", info.Fackets)
+ fmt.Printf(" Last_data_sent: %v\n", info.Last_data_sent)
+ fmt.Printf(" Last_ack_sent: %v\n", info.Last_ack_sent)
+ fmt.Printf(" Last_data_recv: %v\n", info.Last_data_recv)
+ fmt.Printf(" Last_ack_recv: %v\n", info.Last_ack_recv)
+ fmt.Printf(" Pmtu: %v\n", info.Pmtu)
+ fmt.Printf(" Rcv_ssthresh: %v\n", info.Rcv_ssthresh)
+ fmt.Printf(" Rtt: %v\n", info.Rtt)
+ fmt.Printf(" Rttvar: %v\n", info.Rttvar)
+ fmt.Printf(" Snd_ssthresh: %v\n", info.Snd_ssthresh)
+ fmt.Printf(" Snd_cwnd: %v\n", info.Snd_cwnd)
+ fmt.Printf(" Advmss: %v\n", info.Advmss)
+ fmt.Printf(" Reordering: %v\n", info.Reordering)
+ fmt.Printf(" Rcv_rtt: %v\n", info.Rcv_rtt)
+ fmt.Printf(" Rcv_space: %v\n", info.Rcv_space)
+ fmt.Printf(" Total_retrans: %v\n", info.Total_retrans)
+}
diff --git a/utilities/utilities.go b/utilities/utilities.go
index e4c8a0d..7e26ab9 100644
--- a/utilities/utilities.go
+++ b/utilities/utilities.go
@@ -18,13 +18,10 @@ import (
"fmt"
"math"
"math/rand"
- "net"
"os"
"reflect"
"sync/atomic"
"time"
-
- "golang.org/x/sys/unix"
)
func IsInterfaceNil(ifc interface{}) bool {
@@ -126,53 +123,10 @@ func RandBetween(max int) int {
return rand.New(rand.NewSource(int64(time.Now().Nanosecond()))).Int() % max
}
-func GetTCPInfo(connection net.Conn) (*unix.TCPInfo, error) {
- tcpConn, ok := connection.(*net.TCPConn)
- if !ok {
- return nil, fmt.Errorf("connection is not a net.TCPConn")
- }
- rawConn, err := tcpConn.SyscallConn()
- if err != nil {
- return nil, err
- }
-
- var info *unix.TCPInfo = nil
- rawConn.Control(func(fd uintptr) {
- info, err = unix.GetsockoptTCPInfo(int(fd), unix.SOL_TCP, unix.TCP_INFO)
- })
- return info, err
+type NotImplemented struct {
+ Functionality string
}
-func PrintTCPInfo(info *unix.TCPInfo) {
- fmt.Printf("TCPInfo: \n")
- fmt.Printf(" State: %v\n", info.State)
- fmt.Printf(" Ca_state: %v\n", info.Ca_state)
- fmt.Printf(" Retransmits: %v\n", info.Retransmits)
- fmt.Printf(" Probes: %v\n", info.Probes)
- fmt.Printf(" Backoff: %v\n", info.Backoff)
- fmt.Printf(" Options: %v\n", info.Options)
- fmt.Printf(" Rto: %v\n", info.Rto)
- fmt.Printf(" Ato: %v\n", info.Ato)
- fmt.Printf(" Snd_mss: %v\n", info.Snd_mss)
- fmt.Printf(" Rcv_mss: %v\n", info.Rcv_mss)
- fmt.Printf(" Unacked: %v\n", info.Unacked)
- fmt.Printf(" Sacked: %v\n", info.Sacked)
- fmt.Printf(" Lost: %v\n", info.Lost)
- fmt.Printf(" Retrans: %v\n", info.Retrans)
- fmt.Printf(" Fackets: %v\n", info.Fackets)
- fmt.Printf(" Last_data_sent: %v\n", info.Last_data_sent)
- fmt.Printf(" Last_ack_sent: %v\n", info.Last_ack_sent)
- fmt.Printf(" Last_data_recv: %v\n", info.Last_data_recv)
- fmt.Printf(" Last_ack_recv: %v\n", info.Last_ack_recv)
- fmt.Printf(" Pmtu: %v\n", info.Pmtu)
- fmt.Printf(" Rcv_ssthresh: %v\n", info.Rcv_ssthresh)
- fmt.Printf(" Rtt: %v\n", info.Rtt)
- fmt.Printf(" Rttvar: %v\n", info.Rttvar)
- fmt.Printf(" Snd_ssthresh: %v\n", info.Snd_ssthresh)
- fmt.Printf(" Snd_cwnd: %v\n", info.Snd_cwnd)
- fmt.Printf(" Advmss: %v\n", info.Advmss)
- fmt.Printf(" Reordering: %v\n", info.Reordering)
- fmt.Printf(" Rcv_rtt: %v\n", info.Rcv_rtt)
- fmt.Printf(" Rcv_space: %v\n", info.Rcv_space)
- fmt.Printf(" Total_retrans: %v\n", info.Total_retrans)
+func (ni *NotImplemented) Error() string {
+ return fmt.Sprintf("%v not implemented.\n", ni.Functionality)
}