@@ -28,6 +28,9 @@ var protocols = map[string]int{
28
28
// services contains minimal mappings between services names and port
29
29
// numbers for platforms that don't have a complete list of port numbers
30
30
// (some Solaris distros, nacl, etc).
31
+ //
32
+ // See https://www.iana.org/assignments/service-names-port-numbers
33
+ //
31
34
// On Unix, this map is augmented by readServices via goLookupPort.
32
35
var services = map [string ]map [string ]int {
33
36
"udp" : {
@@ -63,7 +66,12 @@ func lookupProtocolMap(name string) (int, error) {
63
66
return proto , nil
64
67
}
65
68
66
- const maxServiceLength = len ("mobility-header" ) + 10 // with room to grow
69
+ // maxPortBufSize is the longest reasonable name of a service
70
+ // (non-numeric port).
71
+ // Currently the longest known IANA-unregistered name is
72
+ // "mobility-header", so we use that length, plus some slop in case
73
+ // something longer is added in the future.
74
+ const maxPortBufSize = len ("mobility-header" ) + 10
67
75
68
76
func lookupPortMap (network , service string ) (port int , error error ) {
69
77
switch network {
@@ -74,7 +82,7 @@ func lookupPortMap(network, service string) (port int, error error) {
74
82
}
75
83
76
84
if m , ok := services [network ]; ok {
77
- var lowerService [maxServiceLength ]byte
85
+ var lowerService [maxPortBufSize ]byte
78
86
n := copy (lowerService [:], service )
79
87
lowerASCIIBytes (lowerService [:n ])
80
88
if port , ok := m [string (lowerService [:n ])]; ok && n == len (service ) {
0 commit comments