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()) +}