LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 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 package net | 5 package net |
6 | 6 |
7 import ( | 7 import ( |
8 "math/rand" | 8 "math/rand" |
9 "sort" | 9 "sort" |
10 ) | 10 ) |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 115 } |
116 | 116 |
117 func isDomainName(s string) bool { | 117 func isDomainName(s string) bool { |
118 // See RFC 1035, RFC 3696. | 118 // See RFC 1035, RFC 3696. |
119 if len(s) == 0 { | 119 if len(s) == 0 { |
120 return false | 120 return false |
121 } | 121 } |
122 if len(s) > 255 { | 122 if len(s) > 255 { |
123 return false | 123 return false |
124 } | 124 } |
125 if s[len(s)-1] != '.' { // simplify checking loop: make name end in dot | |
126 s += "." | |
127 } | |
128 | 125 |
129 last := byte('.') | 126 last := byte('.') |
130 » ok := false // ok once we've seen a letter | 127 » ok := false // Ok once we've seen a letter. |
131 partlen := 0 | 128 partlen := 0 |
132 for i := 0; i < len(s); i++ { | 129 for i := 0; i < len(s); i++ { |
133 c := s[i] | 130 c := s[i] |
134 switch { | 131 switch { |
135 default: | 132 default: |
136 return false | 133 return false |
137 case 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || c == '_': | 134 case 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || c == '_': |
138 ok = true | 135 ok = true |
139 partlen++ | 136 partlen++ |
140 case '0' <= c && c <= '9': | 137 case '0' <= c && c <= '9': |
141 // fine | 138 // fine |
142 partlen++ | 139 partlen++ |
143 case c == '-': | 140 case c == '-': |
144 » » » // byte before dash cannot be dot | 141 » » » // Byte before dash cannot be dot. |
145 if last == '.' { | 142 if last == '.' { |
146 return false | 143 return false |
147 } | 144 } |
148 partlen++ | 145 partlen++ |
149 case c == '.': | 146 case c == '.': |
150 » » » // byte before dot cannot be dot, dash | 147 » » » // Byte before dot cannot be dot, dash. |
151 if last == '.' || last == '-' { | 148 if last == '.' || last == '-' { |
152 return false | 149 return false |
153 } | 150 } |
154 if partlen > 63 || partlen == 0 { | 151 if partlen > 63 || partlen == 0 { |
155 return false | 152 return false |
156 } | 153 } |
157 partlen = 0 | 154 partlen = 0 |
158 } | 155 } |
159 last = c | 156 last = c |
| 157 } |
| 158 if last == '-' || partlen > 63 { |
| 159 return false |
160 } | 160 } |
161 | 161 |
162 return ok | 162 return ok |
163 } | 163 } |
164 | 164 |
165 // An SRV represents a single DNS SRV record. | 165 // An SRV represents a single DNS SRV record. |
166 type SRV struct { | 166 type SRV struct { |
167 Target string | 167 Target string |
168 Port uint16 | 168 Port uint16 |
169 Priority uint16 | 169 Priority uint16 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 j := rand.Intn(i + 1) | 242 j := rand.Intn(i + 1) |
243 s[i], s[j] = s[j], s[i] | 243 s[i], s[j] = s[j], s[i] |
244 } | 244 } |
245 sort.Sort(s) | 245 sort.Sort(s) |
246 } | 246 } |
247 | 247 |
248 // An NS represents a single DNS NS record. | 248 // An NS represents a single DNS NS record. |
249 type NS struct { | 249 type NS struct { |
250 Host string | 250 Host string |
251 } | 251 } |
LEFT | RIGHT |