2019-02-01 14:08:21 -05:00
|
|
|
// +build !confonly
|
|
|
|
|
2018-04-09 11:09:24 -04:00
|
|
|
package domainsocket
|
|
|
|
|
2018-04-09 14:45:23 -04:00
|
|
|
import (
|
2021-02-16 15:31:50 -05:00
|
|
|
"github.com/v2fly/v2ray-core/v4/common"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/common/net"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/transport/internet"
|
2018-04-09 14:45:23 -04:00
|
|
|
)
|
2018-04-09 11:09:24 -04:00
|
|
|
|
2018-08-06 07:48:35 -04:00
|
|
|
const protocolName = "domainsocket"
|
2020-09-04 03:35:54 -04:00
|
|
|
const sizeofSunPath = 108
|
2018-08-06 07:48:35 -04:00
|
|
|
|
2018-04-09 11:09:24 -04:00
|
|
|
func (c *Config) GetUnixAddr() (*net.UnixAddr, error) {
|
|
|
|
path := c.Path
|
2019-06-14 09:47:28 -04:00
|
|
|
if path == "" {
|
2018-04-09 11:09:24 -04:00
|
|
|
return nil, newError("empty domain socket path")
|
|
|
|
}
|
2020-09-04 03:35:54 -04:00
|
|
|
if c.Abstract && path[0] != '@' {
|
|
|
|
path = "@" + path
|
|
|
|
}
|
|
|
|
if c.Abstract && c.Padding {
|
|
|
|
raw := []byte(path)
|
|
|
|
addr := make([]byte, sizeofSunPath)
|
2020-10-11 07:22:46 -04:00
|
|
|
copy(addr, raw)
|
2020-09-04 03:35:54 -04:00
|
|
|
path = string(addr)
|
2018-04-09 11:09:24 -04:00
|
|
|
}
|
|
|
|
return &net.UnixAddr{
|
|
|
|
Name: path,
|
|
|
|
Net: "unix",
|
|
|
|
}, nil
|
|
|
|
}
|
2018-04-09 14:45:23 -04:00
|
|
|
|
|
|
|
func init() {
|
2019-01-06 14:33:58 -05:00
|
|
|
common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} {
|
2018-04-09 14:45:23 -04:00
|
|
|
return new(Config)
|
|
|
|
}))
|
|
|
|
}
|