|
@@ -5,11 +5,9 @@
|
5
|
5
|
package utils
|
6
|
6
|
|
7
|
7
|
import (
|
8
|
|
- "fmt"
|
9
|
8
|
"net"
|
10
|
9
|
"regexp"
|
11
|
10
|
"strings"
|
12
|
|
- "syscall"
|
13
|
11
|
)
|
14
|
12
|
|
15
|
13
|
var (
|
|
@@ -195,25 +193,3 @@ func HandleXForwardedFor(remoteAddr string, xForwardedFor string, whitelist []ne
|
195
|
193
|
// or nil:
|
196
|
194
|
return
|
197
|
195
|
}
|
198
|
|
-
|
199
|
|
-// Output a description of a connection that can identify it to other systems
|
200
|
|
-// administration tools.
|
201
|
|
-func DescribeConn(c net.Conn) (description string) {
|
202
|
|
- description = "<error>"
|
203
|
|
- switch conn := c.(type) {
|
204
|
|
- case *net.UnixConn:
|
205
|
|
- f, err := conn.File()
|
206
|
|
- if err != nil {
|
207
|
|
- return
|
208
|
|
- }
|
209
|
|
- defer f.Close()
|
210
|
|
- ucred, err := syscall.GetsockoptUcred(int(f.Fd()), syscall.SOL_SOCKET, syscall.SO_PEERCRED)
|
211
|
|
- if err != nil {
|
212
|
|
- return
|
213
|
|
- }
|
214
|
|
- return fmt.Sprintf("%s <-> %s [pid=%d, uid=%d]", conn.LocalAddr().String(), conn.RemoteAddr().String(), ucred.Pid, ucred.Uid)
|
215
|
|
- default:
|
216
|
|
- // *net.TCPConn or *tls.Conn
|
217
|
|
- return fmt.Sprintf("%s <-> %s", conn.LocalAddr().String(), conn.RemoteAddr().String())
|
218
|
|
- }
|
219
|
|
-}
|