-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnector-local_unix.go
44 lines (39 loc) · 1.04 KB
/
connector-local_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//go:build darwin || linux || freebsd || netbsd || openbsd || dragonfly || illumos
// +build darwin linux freebsd netbsd openbsd dragonfly illumos
package syslog5424 // import "github.com/nathanaelle/syslog5424/v2"
import (
"net"
)
func (c *localConn) osGuessConnnector() (*net.UnixConn, error) {
logTypes := []string{"unix", "unixgram"}
logPaths := []string{"/var/run/syslog", "/var/run/log", "/dev/log"}
if c.address != "" {
for _, network := range logTypes {
uAddr, err := net.ResolveUnixAddr(network, c.address)
if err != nil {
continue
}
conn, err := net.DialUnix(network, nil, uAddr)
if err == nil {
c.network = network
return conn, nil
}
}
return nil, ErrNoConnection
}
for _, network := range logTypes {
for _, path := range logPaths {
uAddr, err := net.ResolveUnixAddr(network, path)
if err != nil {
continue
}
conn, err := net.DialUnix(network, nil, uAddr)
if err == nil {
c.network = network
c.address = path
return conn, nil
}
}
}
return nil, ErrNoConnection
}