OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/protocol/port_range.h" | 5 #include "remoting/protocol/port_range.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <stddef.h> |
8 #include <stdlib.h> | 9 #include <stdlib.h> |
9 | 10 |
10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
12 | 13 |
13 namespace remoting { | 14 namespace remoting { |
14 | 15 |
15 bool PortRange::Parse(const std::string& port_range, PortRange* result) { | 16 bool PortRange::Parse(const std::string& port_range, PortRange* result) { |
16 DCHECK(result); | 17 DCHECK(result); |
17 | 18 |
(...skipping 15 matching lines...) Expand all Loading... |
33 | 34 |
34 unsigned min_port, max_port; | 35 unsigned min_port, max_port; |
35 if (!base::StringToUint(min_port_string, &min_port) || | 36 if (!base::StringToUint(min_port_string, &min_port) || |
36 !base::StringToUint(max_port_string, &max_port)) { | 37 !base::StringToUint(max_port_string, &max_port)) { |
37 return false; | 38 return false; |
38 } | 39 } |
39 | 40 |
40 if (min_port == 0 || min_port > max_port || max_port > USHRT_MAX) | 41 if (min_port == 0 || min_port > max_port || max_port > USHRT_MAX) |
41 return false; | 42 return false; |
42 | 43 |
43 result->min_port = static_cast<uint16>(min_port); | 44 result->min_port = static_cast<uint16_t>(min_port); |
44 result->max_port = static_cast<uint16>(max_port); | 45 result->max_port = static_cast<uint16_t>(max_port); |
45 return true; | 46 return true; |
46 } | 47 } |
47 | 48 |
48 std::ostream& operator<<(std::ostream& os, const PortRange& port_range) { | 49 std::ostream& operator<<(std::ostream& os, const PortRange& port_range) { |
49 if (port_range.is_null()) { | 50 if (port_range.is_null()) { |
50 os << "<no port range specified>"; | 51 os << "<no port range specified>"; |
51 } else { | 52 } else { |
52 os << "[" << port_range.min_port << ", " << port_range.max_port << "]"; | 53 os << "[" << port_range.min_port << ", " << port_range.max_port << "]"; |
53 } | 54 } |
54 return os; | 55 return os; |
55 } | 56 } |
56 | 57 |
57 } // namespace remoting | 58 } // namespace remoting |
OLD | NEW |