summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-11-09 18:19:09 +0200
committerimarom <imarom@cisco.com>2016-11-09 18:19:09 +0200
commitab28fccc187c6134eeb0400ce0b113a77e498bb2 (patch)
tree8ac54ad7a53992fb25e48d14eee274a2fdab3f37 /src/common
parentd09b123992f990a6c219dd47707cc703fe9055b5 (diff)
RX features - added port attributes for IPv4 and DG
Signed-off-by: imarom <imarom@cisco.com>
Diffstat (limited to 'src/common')
-rwxr-xr-xsrc/common/basic_utils.cpp31
-rwxr-xr-xsrc/common/basic_utils.h5
2 files changed, 36 insertions, 0 deletions
diff --git a/src/common/basic_utils.cpp b/src/common/basic_utils.cpp
index f169c29f..52988131 100755
--- a/src/common/basic_utils.cpp
+++ b/src/common/basic_utils.cpp
@@ -20,6 +20,10 @@ limitations under the License.
#include <sstream>
#include <sys/resource.h>
+#include "pal_utl.h"
+
+int my_inet_pton4(const char *src, unsigned char *dst);
+
bool utl_is_file_exists (const std::string& name) {
if (FILE *file = fopen(name.c_str(), "r")) {
fclose(file);
@@ -190,6 +194,13 @@ void utl_macaddr_to_str(const uint8_t *macaddr, std::string &output) {
}
+std::string utl_macaddr_to_str(const uint8_t *macaddr) {
+ std::string tmp;
+ utl_macaddr_to_str(macaddr, tmp);
+
+ return tmp;
+}
+
/**
* generate a random connection handler
*
@@ -248,3 +259,23 @@ void utl_set_coredump_size(long size, bool map_huge_pages) {
fprintf(fp, "%08x\n", mask);
fclose(fp);
}
+
+uint32_t utl_ipv4_to_uint32(const char *ipv4_str, uint32_t &ipv4_num) {
+
+ uint32_t tmp;
+
+ int rc = my_inet_pton4(ipv4_str, (unsigned char *)&tmp);
+ if (!rc) {
+ return (0);
+ }
+
+ ipv4_num = PAL_NTOHL(tmp);
+
+ return (1);
+}
+
+std::string utl_uint32_to_ipv4(uint32_t ipv4_addr) {
+ std::stringstream ss;
+ ss << ((ipv4_addr >> 24) & 0xff) << "." << ((ipv4_addr >> 16) & 0xff) << "." << ((ipv4_addr >> 8) & 0xff) << "." << (ipv4_addr & 0xff);
+ return ss.str();
+}
diff --git a/src/common/basic_utils.h b/src/common/basic_utils.h
index f6250a2b..fdbd2f08 100755
--- a/src/common/basic_utils.h
+++ b/src/common/basic_utils.h
@@ -86,6 +86,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_macaddr_to_str(const uint8_t *macaddr);
+
std::string utl_generate_random_str(unsigned int &seed, int len);
/**
@@ -98,6 +100,9 @@ std::string utl_generate_random_str(unsigned int &seed, int len);
*/
void utl_set_coredump_size(long size, bool map_huge_pages = false);
+uint32_t utl_ipv4_to_uint32(const char *ipv4_str, uint32_t &ipv4_num);
+std::string utl_uint32_to_ipv4(uint32_t ipv4_addr);
+
#endif