mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-25 21:39:25 +01:00
fix non-linux builds
This commit is contained in:
parent
b876c296eb
commit
475d7ba418
@ -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 = "<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
31
irc/utils/net_linux.go
Normal 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
14
irc/utils/net_nonlinux.go
Normal 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())
|
||||
}
|
Loading…
Reference in New Issue
Block a user