diff options
| author | Michael Stapelberg <michael@stapelberg.de> | 2013-03-23 11:29:06 +0100 |
|---|---|---|
| committer | Michael Stapelberg <michael@stapelberg.de> | 2013-03-23 11:29:06 +0100 |
| commit | cc71238f4c5d23ee2ebffd0d6c307e308ea163c1 (patch) | |
| tree | dd0b57254871fac715258385f5485ba136d6b62a /src/pkg/net/lookup_plan9.go | |
| parent | b32e37d71adab0e2a2b7c4433e7bad169a9a4f98 (diff) | |
| parent | b39e15dde5ec7b96c15da9faf4ab5892501c1aae (diff) | |
| download | golang-cc71238f4c5d23ee2ebffd0d6c307e308ea163c1.tar.gz | |
Merge tag 'upstream/1.1_hg20130323' into debian-sid
Upstream version 1.1~hg20130323
Diffstat (limited to 'src/pkg/net/lookup_plan9.go')
| -rw-r--r-- | src/pkg/net/lookup_plan9.go | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/pkg/net/lookup_plan9.go b/src/pkg/net/lookup_plan9.go index ae7cf7942..94c553328 100644 --- a/src/pkg/net/lookup_plan9.go +++ b/src/pkg/net/lookup_plan9.go @@ -7,7 +7,6 @@ package net import ( "errors" "os" - "syscall" ) func query(filename, query string, bufSize int) (res []string, err error) { @@ -70,9 +69,26 @@ func queryDNS(addr string, typ string) (res []string, err error) { return query("/net/dns", addr+" "+typ, 1024) } +// lookupProtocol looks up IP protocol name and returns +// the corresponding protocol number. func lookupProtocol(name string) (proto int, err error) { - // TODO: Implement this - return 0, syscall.EPLAN9 + lines, err := query("/net/cs", "!protocol="+name, 128) + if err != nil { + return 0, err + } + unknownProtoError := errors.New("unknown IP protocol specified: " + name) + if len(lines) == 0 { + return 0, unknownProtoError + } + f := getFields(lines[0]) + if len(f) < 2 { + return 0, unknownProtoError + } + s := f[1] + if n, _, ok := dtoi(s, byteIndex(s, '=')+1); ok { + return n, nil + } + return 0, unknownProtoError } func lookupHost(host string) (addrs []string, err error) { |
