blob: c24f4ed5b17733da84c7a34e61f909b6ae5309d6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
// Copyright 2012 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.
// Network service port manipulations
package net
// 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
}
}
if p < 0 || p > 0xFFFF {
return 0, &AddrError{"invalid port", port}
}
return p, nil
}
|