LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // +build darwin freebsd linux netbsd openbsd | 5 // +build darwin freebsd linux netbsd openbsd |
6 | 6 |
7 package net | 7 package net |
8 | 8 |
9 import ( | 9 import ( |
10 "errors" | 10 "errors" |
11 "sync" | 11 "sync" |
12 ) | 12 ) |
13 | 13 |
14 var ( | 14 var onceReadProtocols sync.Once |
15 » protocols map[string]int | |
16 » onceReadProtocols sync.Once | |
17 ) | |
18 | 15 |
19 // readProtocols loads contents of /etc/protocols into protocols map | 16 // readProtocols loads contents of /etc/protocols into protocols map |
20 // for quick access. | 17 // for quick access. |
21 func readProtocols() { | 18 func readProtocols() { |
22 protocols = make(map[string]int) | |
23 if file, err := open("/etc/protocols"); err == nil { | 19 if file, err := open("/etc/protocols"); err == nil { |
24 for line, ok := file.readLine(); ok; line, ok = file.readLine()
{ | 20 for line, ok := file.readLine(); ok; line, ok = file.readLine()
{ |
25 // tcp 6 TCP # transmission control protocol | 21 // tcp 6 TCP # transmission control protocol |
26 if i := byteIndex(line, '#'); i >= 0 { | 22 if i := byteIndex(line, '#'); i >= 0 { |
27 line = line[0:i] | 23 line = line[0:i] |
28 } | 24 } |
29 f := getFields(line) | 25 f := getFields(line) |
30 if len(f) < 2 { | 26 if len(f) < 2 { |
31 continue | 27 continue |
32 } | 28 } |
33 if proto, _, ok := dtoi(f[1], 0); ok { | 29 if proto, _, ok := dtoi(f[1], 0); ok { |
34 » » » » protocols[f[0]] = proto | 30 » » » » if _, ok := protocols[f[0]]; !ok { |
| 31 » » » » » protocols[f[0]] = proto |
| 32 » » » » } |
35 for _, alias := range f[2:] { | 33 for _, alias := range f[2:] { |
36 » » » » » protocols[alias] = proto | 34 » » » » » if _, ok := protocols[alias]; !ok { |
| 35 » » » » » » protocols[alias] = proto |
| 36 » » » » » } |
37 } | 37 } |
38 } | 38 } |
39 } | 39 } |
40 file.close() | 40 file.close() |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
44 // lookupProtocol looks up IP protocol name in /etc/protocols and | 44 // lookupProtocol looks up IP protocol name in /etc/protocols and |
45 // returns correspondent protocol number. | 45 // returns correspondent protocol number. |
46 func lookupProtocol(name string) (proto int, err error) { | 46 func lookupProtocol(name string) (proto int, err error) { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 if err != nil { | 159 if err != nil { |
160 return | 160 return |
161 } | 161 } |
162 name = make([]string, len(records)) | 162 name = make([]string, len(records)) |
163 for i := range records { | 163 for i := range records { |
164 r := records[i].(*dnsRR_PTR) | 164 r := records[i].(*dnsRR_PTR) |
165 name[i] = r.Ptr | 165 name[i] = r.Ptr |
166 } | 166 } |
167 return | 167 return |
168 } | 168 } |
LEFT | RIGHT |