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
This commit is contained in:
Akshat Kumar 2013-03-12 23:05:39 +01:00 committed by Ron Minnich
parent f7ad816c5c
commit a1b2d1404b
1 changed files with 19 additions and 3 deletions

View File

@ -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) {