github.com/peggyl/go@v0.0.0-20151008231540-ae315999c2d5/src/net/port.go (about)

     1  // Copyright 2012 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.
     4  
     5  // Network service port manipulations
     6  
     7  package net
     8  
     9  // parsePort parses port as a network service port number for both
    10  // TCP and UDP.
    11  func parsePort(net, port string) (int, error) {
    12  	p, i, ok := dtoi(port, 0)
    13  	if !ok || i != len(port) {
    14  		var err error
    15  		p, err = LookupPort(net, port)
    16  		if err != nil {
    17  			return 0, err
    18  		}
    19  	}
    20  	if p < 0 || p > 0xFFFF {
    21  		return 0, &AddrError{Err: "invalid port", Addr: port}
    22  	}
    23  	return p, nil
    24  }