mirror of
https://github.com/jeremyd/ergo.git
synced 2026-04-26 15:40:00 -07:00
fix non-linux builds
This commit is contained in:
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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user