2012-10-23 06:31:11 +02:00
|
|
|
// Copyright 2012 The Go Authors. All rights reserved.
|
2010-12-03 05:34:57 +01:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2012-10-23 06:31:11 +02:00
|
|
|
// Network service port manipulations
|
2010-12-03 05:34:57 +01:00
|
|
|
|
|
|
|
package net
|
|
|
|
|
2012-10-23 06:31:11 +02:00
|
|
|
// parsePort parses port as a network service port number for both
|
|
|
|
// TCP and UDP.
|
|
|
|
func parsePort(net, port string) (int, error) {
|
|
|
|
p, i, ok := dtoi(port, 0)
|
|
|
|
if !ok || i != len(port) {
|
|
|
|
var err error
|
|
|
|
p, err = LookupPort(net, port)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
|
|
|
}
|
2012-10-23 06:31:11 +02:00
|
|
|
if p < 0 || p > 0xFFFF {
|
|
|
|
return 0, &AddrError{"invalid port", port}
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
2012-10-23 06:31:11 +02:00
|
|
|
return p, nil
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|