Commit 94f86e2d authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Fix issue for PDU Address Information

parent e3362e99
...@@ -110,31 +110,19 @@ void util::ipv6_to_bstring(struct in6_addr ipv6_address, bstring str) { ...@@ -110,31 +110,19 @@ void util::ipv6_to_bstring(struct in6_addr ipv6_address, bstring str) {
void util::ipv4v6_to_bstring( void util::ipv4v6_to_bstring(
struct in_addr ipv4_address, struct in6_addr ipv6_address, bstring str) { struct in_addr ipv4_address, struct in6_addr ipv6_address, bstring str) {
unsigned char bitstream_addr[12]; unsigned char bitstream_addr[12];
bitstream_addr[0] = (uint8_t)((ipv4_address.s_addr) & 0x000000ff); // TODO: to be updated to remove the hardcoded value
bitstream_addr[1] = (uint8_t)(((ipv4_address.s_addr) & 0x0000ff00) >> 8); std::string ipv6_addr = "2001:4860:4860:0:0:0:0:2";
bitstream_addr[2] = (uint8_t)(((ipv4_address.s_addr) & 0x00ff0000) >> 16);
bitstream_addr[3] = (uint8_t)(((ipv4_address.s_addr) & 0xff000000) >> 24);
for (int i = 0; i <= 7; i++)
bitstream_addr[i + 4] = (uint8_t)(ipv6_address.s6_addr16[i]);
str->slen = 12;
memcpy(str->data, bitstream_addr, sizeof(bitstream_addr));
}
void util::ipv4v6_to_bstring(
struct in_addr ipv4_address, std::string ipv6_address, bstring str) {
unsigned char bitstream_addr[12];
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);
std::string ipv6_addr = "2001:4860:4860::2";
unsigned char buf_in6_addr[sizeof(struct in6_addr)]; unsigned char buf_in6_addr[sizeof(struct in6_addr)];
if (inet_pton(AF_INET6, util::trim(ipv6_addr).c_str(), buf_in6_addr) == 1) { if (inet_pton(AF_INET6, util::trim(ipv6_addr).c_str(), buf_in6_addr) == 1) {
// memcpy(&p, buf_in6_addr, sizeof(struct in6_addr)); // memcpy(&p, buf_in6_addr, sizeof(struct in6_addr));
for (int i = 0; i <= 7; i++) for (int i = 0; i <= 7; i++) bitstream_addr[i] = (uint8_t)(buf_in6_addr[i]);
bitstream_addr[i + 4] = (uint8_t)(buf_in6_addr[i]);
} }
bitstream_addr[8] = (uint8_t)((ipv4_address.s_addr) & 0x000000ff);
bitstream_addr[9] = (uint8_t)(((ipv4_address.s_addr) & 0x0000ff00) >> 8);
bitstream_addr[10] = (uint8_t)(((ipv4_address.s_addr) & 0x00ff0000) >> 16);
bitstream_addr[11] = (uint8_t)(((ipv4_address.s_addr) & 0xff000000) >> 24);
str->slen = 12; str->slen = 12;
memcpy(str->data, bitstream_addr, sizeof(bitstream_addr)); memcpy(str->data, bitstream_addr, sizeof(bitstream_addr));
} }
......
...@@ -49,8 +49,6 @@ void ipv4_to_bstring(struct in_addr ipv4_address, bstring str); ...@@ -49,8 +49,6 @@ void ipv4_to_bstring(struct in_addr ipv4_address, bstring str);
void ipv6_to_bstring(struct in6_addr ipv6_address, bstring str); void ipv6_to_bstring(struct in6_addr ipv6_address, bstring str);
void ipv4v6_to_bstring( void ipv4v6_to_bstring(
struct in_addr ipv4_address, struct in6_addr ipv6_address, bstring str); struct in_addr ipv4_address, struct in6_addr ipv6_address, bstring str);
void ipv4v6_to_bstring(
struct in_addr ipv4_address, std::string ipv6_address, bstring str);
void string_to_bstring(const std::string& str, bstring bstr); void string_to_bstring(const std::string& str, bstring bstr);
} // namespace util } // namespace util
......
...@@ -249,6 +249,7 @@ class paa_dynamic { ...@@ -249,6 +249,7 @@ class paa_dynamic {
if (inet_pton( if (inet_pton(
AF_INET6, util::trim(ipv6_addr).c_str(), buf_in6_addr) == 1) { AF_INET6, util::trim(ipv6_addr).c_str(), buf_in6_addr) == 1) {
memcpy(&paa.ipv6_address, buf_in6_addr, sizeof(struct in6_addr)); memcpy(&paa.ipv6_address, buf_in6_addr, sizeof(struct in6_addr));
return true;
} }
} }
Logger::smf_app().warn( Logger::smf_app().warn(
......
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