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 #ifndef REMOTING_PROTOCOL_PORT_RANGE_H_ | 5 #ifndef REMOTING_PROTOCOL_PORT_RANGE_H_ |
6 #define REMOTING_PROTOCOL_PORT_RANGE_H_ | 6 #define REMOTING_PROTOCOL_PORT_RANGE_H_ |
7 | 7 |
| 8 #include <stdint.h> |
| 9 |
8 #include <ostream> | 10 #include <ostream> |
9 #include <string> | 11 #include <string> |
10 | 12 |
11 #include "base/basictypes.h" | |
12 | 13 |
13 namespace remoting { | 14 namespace remoting { |
14 | 15 |
15 // Wrapper for a value of UdpPortRange policy. | 16 // Wrapper for a value of UdpPortRange policy. |
16 struct PortRange { | 17 struct PortRange { |
17 // Both |min_port| and |max_port| are inclusive. | 18 // Both |min_port| and |max_port| are inclusive. |
18 uint16 min_port; | 19 uint16_t min_port; |
19 uint16 max_port; | 20 uint16_t max_port; |
20 | 21 |
21 // Returns true if |port_range| passed to Parse was an empty string | 22 // Returns true if |port_range| passed to Parse was an empty string |
22 // (or if |this| has been initialized by the default constructor below). | 23 // (or if |this| has been initialized by the default constructor below). |
23 inline bool is_null() const { return (min_port == 0) && (max_port == 0); } | 24 inline bool is_null() const { return (min_port == 0) && (max_port == 0); } |
24 | 25 |
25 // Parse string in the form "<min_port>-<max_port>". E.g. "12400-12409". | 26 // Parse string in the form "<min_port>-<max_port>". E.g. "12400-12409". |
26 // Returns true if string was parsed successfuly. | 27 // Returns true if string was parsed successfuly. |
27 // | 28 // |
28 // Returns false and doesn't modify |result| if parsing fails (i.e. when | 29 // Returns false and doesn't modify |result| if parsing fails (i.e. when |
29 // |port_range| doesn't represent a valid port range). | 30 // |port_range| doesn't represent a valid port range). |
30 static bool Parse(const std::string& port_range, PortRange* result); | 31 static bool Parse(const std::string& port_range, PortRange* result); |
31 | 32 |
32 PortRange() : min_port(0), max_port(0) {} | 33 PortRange() : min_port(0), max_port(0) {} |
33 }; | 34 }; |
34 | 35 |
35 std::ostream& operator<<(std::ostream& os, const PortRange& port_range); | 36 std::ostream& operator<<(std::ostream& os, const PortRange& port_range); |
36 | 37 |
37 } // namespace remoting | 38 } // namespace remoting |
38 | 39 |
39 #endif // REMOTING_PROTOCOL_PORT_RANGE_H_ | 40 #endif // REMOTING_PROTOCOL_PORT_RANGE_H_ |
OLD | NEW |