Xray-core/transport/internet/domainsocket/config.go
2021-10-20 00:57:14 +08:00

39 lines
749 B
Go

package domainsocket
import (
"github.com/xtls/xray-core/common"
"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, newError("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)
}))
}