3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-11 06:29:29 +01:00

fix non-linux builds

This commit is contained in:
Shivaram Lingamneni 2020-09-29 15:22:12 -04:00
parent b876c296eb
commit 475d7ba418
3 changed files with 45 additions and 24 deletions

View File

@ -5,11 +5,9 @@
package utils package utils
import ( import (
"fmt"
"net" "net"
"regexp" "regexp"
"strings" "strings"
"syscall"
) )
var ( var (
@ -195,25 +193,3 @@ func HandleXForwardedFor(remoteAddr string, xForwardedFor string, whitelist []ne
// or nil: // or nil:
return return
} }
// Output a description of a connection that can identify it to other systems
// administration tools.
func DescribeConn(c net.Conn) (description string) {
description = "<error>"
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())
}
}

31
irc/utils/net_linux.go Normal file
View File

@ -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 = "<error>"
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())
}
}

14
irc/utils/net_nonlinux.go Normal file
View File

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