github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/transport/internet/domainsocket/config.go (about)

     1  // +build !confonly
     2  
     3  package domainsocket
     4  
     5  import (
     6  	"v2ray.com/core/common"
     7  	"v2ray.com/core/common/net"
     8  	"v2ray.com/core/transport/internet"
     9  )
    10  
    11  const protocolName = "domainsocket"
    12  const sizeofSunPath = 108
    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] != '@' {
    20  		path = "@" + path
    21  	}
    22  	if c.Abstract && c.Padding {
    23  		raw := []byte(path)
    24  		addr := make([]byte, sizeofSunPath)
    25  		for i, c := range raw {
    26  			addr[i] = c
    27  		}
    28  		path = string(addr)
    29  	}
    30  	return &net.UnixAddr{
    31  		Name: path,
    32  		Net:  "unix",
    33  	}, nil
    34  }
    35  
    36  func init() {
    37  	common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} {
    38  		return new(Config)
    39  	}))
    40  }