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})
include_directories(${SRC_TOP_DIR}/common)
include_directories(${SRC_TOP_DIR}/common/msg)
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}/../build/ext/spdlog/include)
......
......@@ -32,6 +32,7 @@
#include <string>
#include <netinet/in.h>
/* Used to format an uint32_t containing an ipv4 address */
#define IN_ADDR_FMT "%u.%u.%u.%u"
#define PRI_IN_ADDR(aDDRESS) \
......
......@@ -3,9 +3,9 @@
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* 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
* except in compliance with the License.
* You may obtain a copy of the License at
* the OAI Public License, Version 1.1 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
......@@ -20,13 +20,13 @@
*/
#include "string.hpp"
#include <stdarg.h>
#include <algorithm>
#include <functional>
#include <cctype>
#include <functional>
#include <locale>
#include <stdarg.h>
template<class T>
template <class T>
class Buffer {
public:
explicit Buffer(size_t size) {
......@@ -34,12 +34,10 @@ class Buffer {
mbuf = new T[msize];
}
~Buffer() {
if (mbuf)
delete[] mbuf;
}
T* get() {
return mbuf;
if (mbuf) delete[] mbuf;
}
T *get() { return mbuf; }
private:
Buffer();
size_t msize;
......@@ -50,7 +48,7 @@ std::string util::string_format(const char *format, ...) {
va_list args;
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);
Buffer<char> buf(size);
......@@ -63,28 +61,41 @@ std::string util::string_format(const char *format, ...) {
}
// 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
std::string& util::ltrim(std::string &s) {
s.erase(
s.begin(),
std::find_if(s.begin(), s.end(),
std::not1(std::ptr_fun<int, int>(std::isspace))));
std::string &util::ltrim(std::string &s) {
s.erase(s.begin(),
std::find_if(s.begin(), s.end(),
std::not1(std::ptr_fun<int, int>(std::isspace))));
return s;
}
// trim from end
std::string& util::rtrim(std::string &s) {
s.erase(
std::find_if(s.rbegin(), s.rend(),
std::not1(std::ptr_fun<int, int>(std::isspace))).base(),
s.end());
std::string &util::rtrim(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(),
std::not1(std::ptr_fun<int, int>(std::isspace)))
.base(),
s.end());
return s;
}
// trim from both ends
std::string& util::trim(std::string &s) {
return util::ltrim(util::rtrim(s));
}
std::string &util::trim(std::string &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 @@
#define FILE_STRING_HPP_FILE_SEEN
#include <string>
#include <arpa/inet.h>
extern "C" {
# include "bstrlib.h"
}
namespace util {
......@@ -39,5 +45,8 @@ std::string& ltrim(std::string &s);
std::string& rtrim(std::string &s);
// trim from both ends
std::string& trim(std::string &s);
void ipv4_to_bstring(struct in_addr ipv4_address, bstring str);
}
#endif
......@@ -169,7 +169,7 @@ bool smf_n1::create_n1_pdu_session_establishment_accept(
// PDUAddress
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] =
(uint8_t)((paa.ipv4_address.s_addr) & 0x000000ff);
bitStream_pdu_address_information[1] =
......@@ -188,6 +188,10 @@ bool smf_n1::create_n1_pdu_session_establishment_accept(
.pdu_address_information->data,
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 =
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