1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // +build aix darwin dragonfly freebsd hurd js,wasm linux netbsd openbsd solaris nacl
7 // Read system port mappings from /etc/services
16 var onceReadServices sync.Once
19 file, err := open("/etc/services")
25 for line, ok := file.readLine(); ok; line, ok = file.readLine() {
26 // "http 80/tcp www www-http # World Wide Web HTTP"
27 if i := bytealg.IndexByteString(line, '#'); i >= 0 {
34 portnet := f[1] // "80/tcp"
35 port, j, ok := dtoi(portnet)
36 if !ok || port <= 0 || j >= len(portnet) || portnet[j] != '/' {
39 netw := portnet[j+1:] // "tcp"
40 m, ok1 := services[netw]
42 m = make(map[string]int)
45 for i := 0; i < len(f); i++ {
46 if i != 1 { // f[1] was port/net
53 // goLookupPort is the native Go implementation of LookupPort.
54 func goLookupPort(network, service string) (port int, err error) {
55 onceReadServices.Do(readServices)
56 return lookupPortMap(network, service)