Index: remoting/base/util.cc |
diff --git a/remoting/base/util.cc b/remoting/base/util.cc |
index 8102cb9bf5bdd7b3c1f3b8c6591f9619b0c3955f..42674bee4e304312e1ecde3770ff814e9be7a1f9 100644 |
--- a/remoting/base/util.cc |
+++ b/remoting/base/util.cc |
@@ -4,7 +4,9 @@ |
#include "remoting/base/util.h" |
+#include <limits.h> |
#include <math.h> |
+#include <stdlib.h> |
#include "base/logging.h" |
#include "base/strings/stringprintf.h" |
@@ -314,4 +316,21 @@ bool DoesRectContain(const webrtc::DesktopRect& a, |
return intersection.equals(b); |
} |
+bool ParsePortRange(const std::string& port_range, int* out_min_port, |
+ int* out_max_port) { |
+ size_t separator_index = port_range.find('-'); |
+ if (separator_index == std::string::npos) |
+ return false; |
+ |
+ int min_port = atoi(port_range.substr(0, separator_index).c_str()); |
+ int max_port = atoi(port_range.substr(separator_index + 1).c_str()); |
+ |
+ if (min_port <= 0 || min_port > max_port || max_port > USHRT_MAX) |
+ return false; |
+ |
+ *out_min_port = min_port; |
+ *out_max_port = max_port; |
+ return true; |
+} |
+ |
} // namespace remoting |