sockopt_linux.go 858 B

1234567891011121314151617181920212223242526272829303132333435
  1. // +build linux
  2. package tcp
  3. import (
  4. "syscall"
  5. "v2ray.com/core/common/log"
  6. "v2ray.com/core/common/net"
  7. "v2ray.com/core/transport/internet"
  8. )
  9. const SO_ORIGINAL_DST = 80
  10. func GetOriginalDestination(conn internet.Connection) net.Destination {
  11. tcpConn, ok := conn.(internet.SysFd)
  12. if !ok {
  13. log.Info("Dokodemo: Failed to get sys fd.")
  14. return net.Destination{}
  15. }
  16. fd, err := tcpConn.SysFd()
  17. if err != nil {
  18. log.Info("Dokodemo: Failed to get original destination: ", err)
  19. return net.Destination{}
  20. }
  21. addr, err := syscall.GetsockoptIPv6Mreq(fd, syscall.IPPROTO_IP, SO_ORIGINAL_DST)
  22. if err != nil {
  23. log.Info("Dokodemo: Failed to call getsockopt: ", err)
  24. return net.Destination{}
  25. }
  26. ip := net.IPAddress(addr.Multiaddr[4:8])
  27. port := uint16(addr.Multiaddr[2])<<8 + uint16(addr.Multiaddr[3])
  28. return net.TCPDestination(ip, net.Port(port))
  29. }