resolver.go 530 B

1234567891011121314151617181920212223
  1. package socks5
  2. import (
  3. "net"
  4. "golang.org/x/net/context"
  5. )
  6. // NameResolver is used to implement custom name resolution
  7. type NameResolver interface {
  8. Resolve(ctx context.Context, name string) (context.Context, net.IP, error)
  9. }
  10. // DNSResolver uses the system DNS to resolve host names
  11. type DNSResolver struct{}
  12. func (d DNSResolver) Resolve(ctx context.Context, name string) (context.Context, net.IP, error) {
  13. addr, err := net.ResolveIPAddr("ip", name)
  14. if err != nil {
  15. return ctx, nil, err
  16. }
  17. return ctx, addr.IP, err
  18. }