Index: remoting/jingle_glue/network_settings.cc |
diff --git a/remoting/jingle_glue/network_settings.cc b/remoting/jingle_glue/network_settings.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3bde3ee9f911754fc1a3822214824fc0a7a2fc64 |
--- /dev/null |
+++ b/remoting/jingle_glue/network_settings.cc |
@@ -0,0 +1,30 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "remoting/jingle_glue/network_settings.h" |
+ |
+#include <limits.h> |
+#include <stdlib.h> |
+ |
+namespace remoting { |
+ |
+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()); |
Sergey Ulanov
2014/03/27 18:31:20
With atoi() this function will accept strings like
dcaiafa
2014/03/27 19:32:24
Done.
|
+ 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 |