config.go 764 B

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