config.go 748 B

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