// 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 aix darwin dragonfly freebsd js,wasm linux netbsd openbsd solaris

// Read system port mappings from /etc/services

package net

import (
	
	
)

var onceReadServices sync.Once

func readServices() {
	,  := open("/etc/services")
	if  != nil {
		return
	}
	defer .close()

	for ,  := .readLine(); ; ,  = .readLine() {
		// "http 80/tcp www www-http # World Wide Web HTTP"
		if  := bytealg.IndexByteString(, '#');  >= 0 {
			 = [:]
		}
		 := getFields()
		if len() < 2 {
			continue
		}
		 := [1] // "80/tcp"
		, ,  := dtoi()
		if ! ||  <= 0 ||  >= len() || [] != '/' {
			continue
		}
		 := [+1:] // "tcp"
		,  := services[]
		if ! {
			 = make(map[string]int)
			services[] = 
		}
		for  := 0;  < len(); ++ {
			if  != 1 { // f[1] was port/net
				[[]] = 
			}
		}
	}
}

// goLookupPort is the native Go implementation of LookupPort.
func goLookupPort(,  string) ( int,  error) {
	onceReadServices.Do(readServices)
	return lookupPortMap(, )
}