github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/transport/internet/domainsocket/config.go (about)

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