mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-24 01:21:29 +00:00
079d0bd8a9
* Refactor log * Add new log methods * Fix logger test * Change all logging code * Clean up pathObj * Rebase to latest main * Remove invoking method name after the dot
40 lines
794 B
Go
40 lines
794 B
Go
package domainsocket
|
|
|
|
import (
|
|
"github.com/xtls/xray-core/common"
|
|
"github.com/xtls/xray-core/common/errors"
|
|
"github.com/xtls/xray-core/common/net"
|
|
"github.com/xtls/xray-core/transport/internet"
|
|
)
|
|
|
|
const (
|
|
protocolName = "domainsocket"
|
|
sizeofSunPath = 108
|
|
)
|
|
|
|
func (c *Config) GetUnixAddr() (*net.UnixAddr, error) {
|
|
path := c.Path
|
|
if path == "" {
|
|
return nil, errors.New("empty domain socket path")
|
|
}
|
|
if c.Abstract && path[0] != '@' {
|
|
path = "@" + path
|
|
}
|
|
if c.Abstract && c.Padding {
|
|
raw := []byte(path)
|
|
addr := make([]byte, sizeofSunPath)
|
|
copy(addr, raw)
|
|
path = string(addr)
|
|
}
|
|
return &net.UnixAddr{
|
|
Name: path,
|
|
Net: "unix",
|
|
}, nil
|
|
}
|
|
|
|
func init() {
|
|
common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} {
|
|
return new(Config)
|
|
}))
|
|
}
|