From: Akshat Kumar Date: Tue, 12 Mar 2013 22:05:39 +0000 (+0100) Subject: net: Plan 9: add lookupProtocol X-Git-Tag: go1.1rc2~540 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a1b2d1404be98284416e2a7ea6f55bc129222cc0;p=gostls13.git net: Plan 9: add lookupProtocol Needed by TestResolveIPAddr. This makes us pass tests again. R=rsc, rminnich, ality, bradfitz CC=golang-dev https://golang.org/cl/7737043 --- diff --git a/src/pkg/net/lookup_plan9.go b/src/pkg/net/lookup_plan9.go index ae7cf79421..94c5533286 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) {