summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-04-03 18:19:20 +0300
committerimarom <imarom@cisco.com>2016-04-04 09:49:54 +0300
commit4eacb570cf24927de536d23671f50609f1a9ffa5 (patch)
tree83b8dcd86994c7668a054413d0ba0449a1cf2816 /src/common
parent0eb15b2e851b5f50669633678143c5a1d3a7d95b (diff)
API classes (versions)
Diffstat (limited to 'src/common')
-rwxr-xr-xsrc/common/basic_utils.cpp23
-rwxr-xr-xsrc/common/basic_utils.h4
2 files changed, 25 insertions, 2 deletions
diff --git a/src/common/basic_utils.cpp b/src/common/basic_utils.cpp
index 34c37755..4f5578a6 100755
--- a/src/common/basic_utils.cpp
+++ b/src/common/basic_utils.cpp
@@ -17,6 +17,7 @@ limitations under the License.
#include <ctype.h>
#include <stdio.h>
#include <string>
+#include <sstream>
bool utl_is_file_exists (const std::string& name) {
if (FILE *file = fopen(name.c_str(), "r")) {
@@ -175,3 +176,25 @@ void utl_macaddr_to_str(const uint8_t *macaddr, std::string &output) {
}
}
+
+/**
+ * generate a random connection handler
+ *
+ */
+std::string
+utl_generate_random_str(unsigned int &seed, int len) {
+ std::stringstream ss;
+
+ static const char alphanum[] =
+ "0123456789"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz";
+
+ /* generate 8 bytes of random handler */
+ for (int i = 0; i < len; ++i) {
+ ss << alphanum[rand_r(&seed) % (sizeof(alphanum) - 1)];
+ }
+
+ return (ss.str());
+}
+
diff --git a/src/common/basic_utils.h b/src/common/basic_utils.h
index 77282eea..63e858ab 100755
--- a/src/common/basic_utils.h
+++ b/src/common/basic_utils.h
@@ -21,8 +21,6 @@ limitations under the License.
#include <stdio.h>
#include <string>
-
-
/**
* the round must be power 2 e.g 2,4,8...
*
@@ -87,6 +85,8 @@ bool utl_is_file_exists (const std::string& name) ;
void utl_macaddr_to_str(const uint8_t *macaddr, std::string &output);
+std::string utl_generate_random_str(unsigned int &seed, int len);
+
#endif