Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(91)

Delta Between Two Patch Sets: src/pkg/net/lookup_unix.go

Issue 12898045: code review 12898045: net: use protocol number literals instead of names in r... (Closed)
Left Patch Set: diff -r 5600ebc3b0b1 https://code.google.com/p/go Created 11 years, 7 months ago
Right Patch Set: diff -r 3a166dbdf846 https://code.google.com/p/go Created 11 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
LEFTRIGHT
(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
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 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b