1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-08 14:24:36 -04:00
v2fly/transport/internet/domainsocket/config.go

39 lines
784 B
Go
Raw Normal View History

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"
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
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)
}))
}