github.com/eagleql/xray-core@v1.4.4/transport/internet/domainsocket/config.go (about)

     1  package domainsocket
     2  
     3  import (
     4  	"github.com/eagleql/xray-core/common"
     5  	"github.com/eagleql/xray-core/common/net"
     6  	"github.com/eagleql/xray-core/transport/internet"
     7  )
     8  
     9  const protocolName = "domainsocket"
    10  const sizeofSunPath = 108
    11  
    12  func (c *Config) GetUnixAddr() (*net.UnixAddr, error) {
    13  	path := c.Path
    14  	if path == "" {
    15  		return nil, newError("empty domain socket path")
    16  	}
    17  	if c.Abstract && path[0] != '@' {
    18  		path = "@" + path
    19  	}
    20  	if c.Abstract && c.Padding {
    21  		raw := []byte(path)
    22  		addr := make([]byte, sizeofSunPath)
    23  		copy(addr, raw)
    24  		path = string(addr)
    25  	}
    26  	return &net.UnixAddr{
    27  		Name: path,
    28  		Net:  "unix",
    29  	}, nil
    30  }
    31  
    32  func init() {
    33  	common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} {
    34  		return new(Config)
    35  	}))
    36  }