Browse Source

fix non-linux builds

tags/v2.4.0-rc1
Shivaram Lingamneni 3 years ago
parent
commit
475d7ba418
3 changed files with 45 additions and 24 deletions
  1. 0
    24
      irc/utils/net.go
  2. 31
    0
      irc/utils/net_linux.go
  3. 14
    0
      irc/utils/net_nonlinux.go

+ 0
- 24
irc/utils/net.go View File

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

+ 31
- 0
irc/utils/net_linux.go View File

@@ -0,0 +1,31 @@
1
+// +build linux
2
+
3
+package utils
4
+
5
+import (
6
+	"fmt"
7
+	"net"
8
+	"syscall"
9
+)
10
+
11
+// Output a description of a connection that can identify it to other systems
12
+// administration tools.
13
+func DescribeConn(c net.Conn) (description string) {
14
+	description = "<error>"
15
+	switch conn := c.(type) {
16
+	case *net.UnixConn:
17
+		f, err := conn.File()
18
+		if err != nil {
19
+			return
20
+		}
21
+		defer f.Close()
22
+		ucred, err := syscall.GetsockoptUcred(int(f.Fd()), syscall.SOL_SOCKET, syscall.SO_PEERCRED)
23
+		if err != nil {
24
+			return
25
+		}
26
+		return fmt.Sprintf("%s <-> %s [pid=%d, uid=%d]", conn.LocalAddr().String(), conn.RemoteAddr().String(), ucred.Pid, ucred.Uid)
27
+	default:
28
+		// *net.TCPConn or *tls.Conn
29
+		return fmt.Sprintf("%s <-> %s", conn.LocalAddr().String(), conn.RemoteAddr().String())
30
+	}
31
+}

+ 14
- 0
irc/utils/net_nonlinux.go View File

@@ -0,0 +1,14 @@
1
+// +build !linux
2
+
3
+package utils
4
+
5
+import (
6
+	"fmt"
7
+	"net"
8
+)
9
+
10
+// Output a description of a connection that can identify it to other systems
11
+// administration tools.
12
+func DescribeConn(conn net.Conn) (description string) {
13
+	return fmt.Sprintf("%s <-> %s", conn.LocalAddr().String(), conn.RemoteAddr().String())
14
+}

Loading…
Cancel
Save