port_range.h 1.2 KB

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