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