From 475d7ba4182b5f1c1b3d57714a282e09dfcbd896 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Tue, 29 Sep 2020 15:22:12 -0400 Subject: [PATCH] fix non-linux builds --- irc/utils/net.go | 24 ------------------------ irc/utils/net_linux.go | 31 +++++++++++++++++++++++++++++++ irc/utils/net_nonlinux.go | 14 ++++++++++++++ 3 files changed, 45 insertions(+), 24 deletions(-) create mode 100644 irc/utils/net_linux.go create mode 100644 irc/utils/net_nonlinux.go diff --git a/irc/utils/net.go b/irc/utils/net.go index c323c2dc..451c56a0 100644 --- a/irc/utils/net.go +++ b/irc/utils/net.go @@ -5,11 +5,9 @@ package utils import ( - "fmt" "net" "regexp" "strings" - "syscall" ) var ( @@ -195,25 +193,3 @@ func HandleXForwardedFor(remoteAddr string, xForwardedFor string, whitelist []ne // or nil: return } - -// Output a description of a connection that can identify it to other systems -// administration tools. -func DescribeConn(c net.Conn) (description string) { - description = "" - switch conn := c.(type) { - case *net.UnixConn: - f, err := conn.File() - if err != nil { - return - } - defer f.Close() - ucred, err := syscall.GetsockoptUcred(int(f.Fd()), syscall.SOL_SOCKET, syscall.SO_PEERCRED) - if err != nil { - return - } - return fmt.Sprintf("%s <-> %s [pid=%d, uid=%d]", conn.LocalAddr().String(), conn.RemoteAddr().String(), ucred.Pid, ucred.Uid) - default: - // *net.TCPConn or *tls.Conn - return fmt.Sprintf("%s <-> %s", conn.LocalAddr().String(), conn.RemoteAddr().String()) - } -} diff --git a/irc/utils/net_linux.go b/irc/utils/net_linux.go new file mode 100644 index 00000000..30daeefe --- /dev/null +++ b/irc/utils/net_linux.go @@ -0,0 +1,31 @@ +// +build linux + +package utils + +import ( + "fmt" + "net" + "syscall" +) + +// Output a description of a connection that can identify it to other systems +// administration tools. +func DescribeConn(c net.Conn) (description string) { + description = "" + switch conn := c.(type) { + case *net.UnixConn: + f, err := conn.File() + if err != nil { + return + } + defer f.Close() + ucred, err := syscall.GetsockoptUcred(int(f.Fd()), syscall.SOL_SOCKET, syscall.SO_PEERCRED) + if err != nil { + return + } + return fmt.Sprintf("%s <-> %s [pid=%d, uid=%d]", conn.LocalAddr().String(), conn.RemoteAddr().String(), ucred.Pid, ucred.Uid) + default: + // *net.TCPConn or *tls.Conn + return fmt.Sprintf("%s <-> %s", conn.LocalAddr().String(), conn.RemoteAddr().String()) + } +} diff --git a/irc/utils/net_nonlinux.go b/irc/utils/net_nonlinux.go new file mode 100644 index 00000000..6084078c --- /dev/null +++ b/irc/utils/net_nonlinux.go @@ -0,0 +1,14 @@ +// +build !linux + +package utils + +import ( + "fmt" + "net" +) + +// Output a description of a connection that can identify it to other systems +// administration tools. +func DescribeConn(conn net.Conn) (description string) { + return fmt.Sprintf("%s <-> %s", conn.LocalAddr().String(), conn.RemoteAddr().String()) +}