mirror of
https://github.com/golang/go
synced 2024-10-05 18:31:28 -06:00
7c8280c9ef
See golang.org/s/go13nacl for design overview. This CL is the mostly mechanical changes from rsc's Go 1.2 based NaCl branch, specifically 39cb35750369 to 500771b477cf from https://code.google.com/r/rsc-go13nacl. This CL does not include working NaCl support, there are probably two or three more large merges to come. CL 15750044 is not included as it involves more invasive changes to the linker which will need to be merged separately. The exact change lists included are 15050047: syscall: support for Native Client 15360044: syscall: unzip implementation for Native Client 15370044: syscall: Native Client SRPC implementation 15400047: cmd/dist, cmd/go, go/build, test: support for Native Client 15410048: runtime: support for Native Client 15410049: syscall: file descriptor table for Native Client 15410050: syscall: in-memory file system for Native Client 15440048: all: update +build lines for Native Client port 15540045: cmd/6g, cmd/8g, cmd/gc: support for Native Client 15570045: os: support for Native Client 15680044: crypto/..., hash/crc32, reflect, sync/atomic: support for amd64p32 15690044: net: support for Native Client 15690048: runtime: support for fake time like on Go Playground 15690051: build: disable various tests on Native Client LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/68150047
106 lines
2.6 KiB
Go
106 lines
2.6 KiB
Go
// Copyright 2009 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
|
|
|
|
// Read system DNS config from /etc/resolv.conf
|
|
|
|
package net
|
|
|
|
type dnsConfig struct {
|
|
servers []string // servers to use
|
|
search []string // suffixes to append to local name
|
|
ndots int // number of dots in name to trigger absolute lookup
|
|
timeout int // seconds before giving up on packet
|
|
attempts int // lost packets before giving up on server
|
|
rotate bool // round robin among servers
|
|
}
|
|
|
|
// See resolv.conf(5) on a Linux machine.
|
|
// TODO(rsc): Supposed to call uname() and chop the beginning
|
|
// of the host name to get the default search domain.
|
|
func dnsReadConfig(filename string) (*dnsConfig, error) {
|
|
file, err := open(filename)
|
|
if err != nil {
|
|
return nil, &DNSConfigError{err}
|
|
}
|
|
conf := new(dnsConfig)
|
|
conf.servers = make([]string, 0, 3) // small, but the standard limit
|
|
conf.search = make([]string, 0)
|
|
conf.ndots = 1
|
|
conf.timeout = 5
|
|
conf.attempts = 2
|
|
conf.rotate = false
|
|
for line, ok := file.readLine(); ok; line, ok = file.readLine() {
|
|
f := getFields(line)
|
|
if len(f) < 1 {
|
|
continue
|
|
}
|
|
switch f[0] {
|
|
case "nameserver": // add one name server
|
|
a := conf.servers
|
|
n := len(a)
|
|
if len(f) > 1 && n < cap(a) {
|
|
// One more check: make sure server name is
|
|
// just an IP address. Otherwise we need DNS
|
|
// to look it up.
|
|
name := f[1]
|
|
switch len(ParseIP(name)) {
|
|
case 16:
|
|
name = "[" + name + "]"
|
|
fallthrough
|
|
case 4:
|
|
a = a[0 : n+1]
|
|
a[n] = name
|
|
conf.servers = a
|
|
}
|
|
}
|
|
|
|
case "domain": // set search path to just this domain
|
|
if len(f) > 1 {
|
|
conf.search = make([]string, 1)
|
|
conf.search[0] = f[1]
|
|
} else {
|
|
conf.search = make([]string, 0)
|
|
}
|
|
|
|
case "search": // set search path to given servers
|
|
conf.search = make([]string, len(f)-1)
|
|
for i := 0; i < len(conf.search); i++ {
|
|
conf.search[i] = f[i+1]
|
|
}
|
|
|
|
case "options": // magic options
|
|
for i := 1; i < len(f); i++ {
|
|
s := f[i]
|
|
switch {
|
|
case len(s) >= 6 && s[0:6] == "ndots:":
|
|
n, _, _ := dtoi(s, 6)
|
|
if n < 1 {
|
|
n = 1
|
|
}
|
|
conf.ndots = n
|
|
case len(s) >= 8 && s[0:8] == "timeout:":
|
|
n, _, _ := dtoi(s, 8)
|
|
if n < 1 {
|
|
n = 1
|
|
}
|
|
conf.timeout = n
|
|
case len(s) >= 8 && s[0:9] == "attempts:":
|
|
n, _, _ := dtoi(s, 9)
|
|
if n < 1 {
|
|
n = 1
|
|
}
|
|
conf.attempts = n
|
|
case s == "rotate":
|
|
conf.rotate = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
file.close()
|
|
|
|
return conf, nil
|
|
}
|