Commit 539e6168 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

add convert ipv4 to bstring

parent 58be070c
...@@ -22,6 +22,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) ...@@ -22,6 +22,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${SRC_TOP_DIR}/common) include_directories(${SRC_TOP_DIR}/common)
include_directories(${SRC_TOP_DIR}/common/msg) include_directories(${SRC_TOP_DIR}/common/msg)
include_directories(${SRC_TOP_DIR}/common/utils) include_directories(${SRC_TOP_DIR}/common/utils)
include_directories(${SRC_TOP_DIR}/common/utils/bstr)
include_directories(${SRC_TOP_DIR}/itti) include_directories(${SRC_TOP_DIR}/itti)
include_directories(${SRC_TOP_DIR}/../build/ext/spdlog/include) include_directories(${SRC_TOP_DIR}/../build/ext/spdlog/include)
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <string> #include <string>
#include <netinet/in.h> #include <netinet/in.h>
/* Used to format an uint32_t containing an ipv4 address */ /* Used to format an uint32_t containing an ipv4 address */
#define IN_ADDR_FMT "%u.%u.%u.%u" #define IN_ADDR_FMT "%u.%u.%u.%u"
#define PRI_IN_ADDR(aDDRESS) \ #define PRI_IN_ADDR(aDDRESS) \
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under * The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file * the OAI Public License, Version 1.1 (the "License"); you may not use this
* except in compliance with the License. * file except in compliance with the License. You may obtain a copy of the
* You may obtain a copy of the License at * License at
* *
* http://www.openairinterface.org/?page_id=698 * http://www.openairinterface.org/?page_id=698
* *
...@@ -20,13 +20,13 @@ ...@@ -20,13 +20,13 @@
*/ */
#include "string.hpp" #include "string.hpp"
#include <stdarg.h>
#include <algorithm> #include <algorithm>
#include <functional>
#include <cctype> #include <cctype>
#include <functional>
#include <locale> #include <locale>
#include <stdarg.h>
template<class T> template <class T>
class Buffer { class Buffer {
public: public:
explicit Buffer(size_t size) { explicit Buffer(size_t size) {
...@@ -34,12 +34,10 @@ class Buffer { ...@@ -34,12 +34,10 @@ class Buffer {
mbuf = new T[msize]; mbuf = new T[msize];
} }
~Buffer() { ~Buffer() {
if (mbuf) if (mbuf) delete[] mbuf;
delete[] mbuf;
}
T* get() {
return mbuf;
} }
T *get() { return mbuf; }
private: private:
Buffer(); Buffer();
size_t msize; size_t msize;
...@@ -50,7 +48,7 @@ std::string util::string_format(const char *format, ...) { ...@@ -50,7 +48,7 @@ std::string util::string_format(const char *format, ...) {
va_list args; va_list args;
va_start(args, format); va_start(args, format);
size_t size = vsnprintf( NULL, 0, format, args) + 1; // Extra space for '\0' size_t size = vsnprintf(NULL, 0, format, args) + 1; // Extra space for '\0'
va_end(args); va_end(args);
Buffer<char> buf(size); Buffer<char> buf(size);
...@@ -63,28 +61,41 @@ std::string util::string_format(const char *format, ...) { ...@@ -63,28 +61,41 @@ std::string util::string_format(const char *format, ...) {
} }
// Licence : https://creativecommons.org/licenses/by-sa/4.0/legalcode // Licence : https://creativecommons.org/licenses/by-sa/4.0/legalcode
//https://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring#217605 // https://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring#217605
// trim from start // trim from start
std::string& util::ltrim(std::string &s) { std::string &util::ltrim(std::string &s) {
s.erase( s.erase(s.begin(),
s.begin(), std::find_if(s.begin(), s.end(),
std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
std::not1(std::ptr_fun<int, int>(std::isspace))));
return s; return s;
} }
// trim from end // trim from end
std::string& util::rtrim(std::string &s) { std::string &util::rtrim(std::string &s) {
s.erase( s.erase(std::find_if(s.rbegin(), s.rend(),
std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace)))
std::not1(std::ptr_fun<int, int>(std::isspace))).base(), .base(),
s.end()); s.end());
return s; return s;
} }
// trim from both ends // trim from both ends
std::string& util::trim(std::string &s) { std::string &util::trim(std::string &s) { return util::ltrim(util::rtrim(s)); }
return util::ltrim(util::rtrim(s));
}
void util::ipv4_to_bstring(struct in_addr ipv4_address, bstring str) {
unsigned char bitstream_addr[4];
bitstream_addr[0] =
(uint8_t)((ipv4_address.s_addr) & 0x000000ff);
bitstream_addr[1] =
(uint8_t)(((ipv4_address.s_addr) & 0x0000ff00) >> 8);
bitstream_addr[2] =
(uint8_t)(((ipv4_address.s_addr) & 0x00ff0000) >> 16);
bitstream_addr[3] =
(uint8_t)(((ipv4_address.s_addr) & 0xff000000) >> 24);
str = bfromcstralloc(4, "\0");
str->slen = 4;
memcpy(str->data, bitstream_addr,
sizeof(bitstream_addr));
}
...@@ -29,6 +29,12 @@ ...@@ -29,6 +29,12 @@
#define FILE_STRING_HPP_FILE_SEEN #define FILE_STRING_HPP_FILE_SEEN
#include <string> #include <string>
#include <arpa/inet.h>
extern "C" {
# include "bstrlib.h"
}
namespace util { namespace util {
...@@ -39,5 +45,8 @@ std::string& ltrim(std::string &s); ...@@ -39,5 +45,8 @@ std::string& ltrim(std::string &s);
std::string& rtrim(std::string &s); std::string& rtrim(std::string &s);
// trim from both ends // trim from both ends
std::string& trim(std::string &s); std::string& trim(std::string &s);
void ipv4_to_bstring(struct in_addr ipv4_address, bstring str);
} }
#endif #endif
...@@ -169,7 +169,7 @@ bool smf_n1::create_n1_pdu_session_establishment_accept( ...@@ -169,7 +169,7 @@ bool smf_n1::create_n1_pdu_session_establishment_accept(
// PDUAddress // PDUAddress
paa_t paa = sm_context_res.get_paa(); paa_t paa = sm_context_res.get_paa();
unsigned char bitStream_pdu_address_information[4]; /* unsigned char bitStream_pdu_address_information[4];
bitStream_pdu_address_information[0] = bitStream_pdu_address_information[0] =
(uint8_t)((paa.ipv4_address.s_addr) & 0x000000ff); (uint8_t)((paa.ipv4_address.s_addr) & 0x000000ff);
bitStream_pdu_address_information[1] = bitStream_pdu_address_information[1] =
...@@ -188,6 +188,10 @@ bool smf_n1::create_n1_pdu_session_establishment_accept( ...@@ -188,6 +188,10 @@ bool smf_n1::create_n1_pdu_session_establishment_accept(
.pdu_address_information->data, .pdu_address_information->data,
bitStream_pdu_address_information, bitStream_pdu_address_information,
sizeof(bitStream_pdu_address_information)); sizeof(bitStream_pdu_address_information));
*/
util::ipv4_to_bstring(paa.ipv4_address, sm_msg->pdu_session_establishment_accept.pduaddress
.pdu_address_information);
sm_msg->pdu_session_establishment_accept.pduaddress.pdu_session_type_value = sm_msg->pdu_session_establishment_accept.pduaddress.pdu_session_type_value =
static_cast<uint8_t>(PDU_SESSION_TYPE_E_IPV4); static_cast<uint8_t>(PDU_SESSION_TYPE_E_IPV4);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment