File: resolver.go

package info (click to toggle)
golang-github-armon-go-socks5 0.0~git20160902.e753329-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 136 kB
  • sloc: makefile: 2
file content (23 lines) | stat: -rw-r--r-- 530 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package socks5

import (
	"net"

	"golang.org/x/net/context"
)

// NameResolver is used to implement custom name resolution
type NameResolver interface {
	Resolve(ctx context.Context, name string) (context.Context, net.IP, error)
}

// DNSResolver uses the system DNS to resolve host names
type DNSResolver struct{}

func (d DNSResolver) Resolve(ctx context.Context, name string) (context.Context, net.IP, error) {
	addr, err := net.ResolveIPAddr("ip", name)
	if err != nil {
		return ctx, nil, err
	}
	return ctx, addr.IP, err
}