OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "remoting/jingle_glue/network_settings.h" | |
6 | |
7 #include <limits.h> | |
8 #include <stdlib.h> | |
9 | |
10 namespace remoting { | |
11 | |
12 bool ParsePortRange(const std::string& port_range, | |
13 int* out_min_port, | |
14 int* out_max_port) { | |
15 size_t separator_index = port_range.find('-'); | |
16 if (separator_index == std::string::npos) | |
17 return false; | |
18 | |
19 int min_port = atoi(port_range.substr(0, separator_index).c_str()); | |
Sergey Ulanov
2014/03/27 18:31:20
With atoi() this function will accept strings like
dcaiafa
2014/03/27 19:32:24
Done.
| |
20 int max_port = atoi(port_range.substr(separator_index + 1).c_str()); | |
21 | |
22 if (min_port <= 0 || min_port > max_port || max_port > USHRT_MAX) | |
23 return false; | |
24 | |
25 *out_min_port = min_port; | |
26 *out_max_port = max_port; | |
27 return true; | |
28 } | |
29 | |
30 } // namespace remoting | |
OLD | NEW |