github.com/moqsien/xraycore@v1.8.5/transport/internet/domainsocket/config.go (about) 1 package domainsocket 2 3 import ( 4 "github.com/moqsien/xraycore/common" 5 "github.com/moqsien/xraycore/common/net" 6 "github.com/moqsien/xraycore/transport/internet" 7 ) 8 9 const ( 10 protocolName = "domainsocket" 11 sizeofSunPath = 108 12 ) 13 14 func (c *Config) GetUnixAddr() (*net.UnixAddr, error) { 15 path := c.Path 16 if path == "" { 17 return nil, newError("empty domain socket path") 18 } 19 if c.Abstract && path[0] != '@' { 20 path = "@" + path 21 } 22 if c.Abstract && c.Padding { 23 raw := []byte(path) 24 addr := make([]byte, sizeofSunPath) 25 copy(addr, raw) 26 path = string(addr) 27 } 28 return &net.UnixAddr{ 29 Name: path, 30 Net: "unix", 31 }, nil 32 } 33 34 func init() { 35 common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} { 36 return new(Config) 37 })) 38 }