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.go11
3 files changed, 5 insertions, 86 deletions
diff --git a/utilities/tcpinfo_other.go b/utilities/tcpinfo_other.go
deleted file mode 100644
index 8dd070b..0000000
--- a/utilities/tcpinfo_other.go
+++ /dev/null
@@ -1,18 +0,0 @@
-//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
deleted file mode 100644
index b0b5252..0000000
--- a/utilities/tcpinfo_unix.go
+++ /dev/null
@@ -1,62 +0,0 @@
-//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 7e26ab9..76acbd2 100644
--- a/utilities/utilities.go
+++ b/utilities/utilities.go
@@ -123,10 +123,9 @@ func RandBetween(max int) int {
return rand.New(rand.NewSource(int64(time.Now().Nanosecond()))).Int() % max
}
-type NotImplemented struct {
- Functionality string
-}
-
-func (ni *NotImplemented) Error() string {
- return fmt.Sprintf("%v not implemented.\n", ni.Functionality)
+func Max(x, y uint64) uint64 {
+ if x > y {
+ return x
+ }
+ return y
}