2018-04-09 11:09:24 -04:00
|
|
|
package domainsocket
|
|
|
|
|
2018-04-09 14:45:23 -04:00
|
|
|
import (
|
|
|
|
"v2ray.com/core/common"
|
|
|
|
"v2ray.com/core/common/net"
|
|
|
|
"v2ray.com/core/transport/internet"
|
|
|
|
)
|
2018-04-09 11:09:24 -04:00
|
|
|
|
2018-08-06 07:48:35 -04:00
|
|
|
const protocolName = "domainsocket"
|
|
|
|
|
2018-04-09 11:09:24 -04:00
|
|
|
func (c *Config) GetUnixAddr() (*net.UnixAddr, error) {
|
|
|
|
path := c.Path
|
|
|
|
if len(path) == 0 {
|
|
|
|
return nil, newError("empty domain socket path")
|
|
|
|
}
|
|
|
|
if c.Abstract && path[0] != '\x00' {
|
|
|
|
path = "\x00" + path
|
|
|
|
}
|
|
|
|
return &net.UnixAddr{
|
|
|
|
Name: path,
|
|
|
|
Net: "unix",
|
|
|
|
}, nil
|
|
|
|
}
|
2018-04-09 14:45:23 -04:00
|
|
|
|
|
|
|
func init() {
|
2018-08-06 07:48:35 -04:00
|
|
|
common.Must(internet.RegisterProtocolConfigCreatorByName(protocolName, func() interface{} {
|
2018-04-09 14:45:23 -04:00
|
|
|
return new(Config)
|
|
|
|
}))
|
|
|
|
}
|