github.com/v2fly/v2ray-core/v4@v4.45.2/transport/internet/domainsocket/config.go (about)

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