Xray-core/transport/internet/domainsocket/config.go

40 lines
794 B
Go
Raw Normal View History

2020-11-25 11:01:53 +00:00
package domainsocket
import (
2020-12-04 01:36:16 +00:00
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/errors"
2020-12-04 01:36:16 +00:00
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/transport/internet"
2020-11-25 11:01:53 +00:00
)
2021-10-19 16:57:14 +00:00
const (
protocolName = "domainsocket"
sizeofSunPath = 108
)
2020-11-25 11:01:53 +00:00
func (c *Config) GetUnixAddr() (*net.UnixAddr, error) {
path := c.Path
if path == "" {
return nil, errors.New("empty domain socket path")
2020-11-25 11:01:53 +00:00
}
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)
}))
}