1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-10 06:16:53 -05:00
v2fly/transport/internet/domainsocket/config.go

39 lines
764 B
Go
Raw Normal View History

2018-04-09 11:09:24 -04:00
package domainsocket
2018-04-09 14:45:23 -04:00
import (
"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
if path == "" {
2018-04-09 11:09:24 -04:00
return nil, newError("empty domain socket path")
}
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)
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)
}))
}