2018-04-09 11:09:24 -04:00
|
|
|
package domainsocket
|
|
|
|
|
2018-04-09 14:45:23 -04:00
|
|
|
import (
|
2022-01-02 10:16:23 -05:00
|
|
|
"github.com/v2fly/v2ray-core/v5/common"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common/net"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/transport/internet"
|
2018-04-09 14:45:23 -04:00
|
|
|
)
|
2018-04-09 11:09:24 -04:00
|
|
|
|
2021-05-19 17:28:52 -04:00
|
|
|
const (
|
|
|
|
protocolName = "domainsocket"
|
|
|
|
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)
|
|
|
|
}))
|
|
|
|
}
|