Skip to content

Instantly share code, notes, and snippets.

@lancethepants
Created August 24, 2022 13:10
Show Gist options
  • Save lancethepants/2e2a12456a6d5756bae8c310b2e21b4a to your computer and use it in GitHub Desktop.
Save lancethepants/2e2a12456a6d5756bae8c310b2e21b4a to your computer and use it in GitHub Desktop.
patch to compile voipmonitor for aarch64 musl
From def3aeb005942ba7c87ac49db7e18a51015c4e61 Mon Sep 17 00:00:00 2001
From: admin <admin@RT-AX88U-6860>
Date: Tue, 23 Aug 2022 14:49:01 -0600
Subject: [PATCH] MUSL
---
heap_safe.cpp | 7 +++---
heap_safe.h | 22 ++++++++---------
ip.cpp | 8 +++----
ip.h | 64 ++++++++++++++++++++++++-------------------------
manager.cpp | 5 +++-
pstat.h | 2 +-
tools.cpp | 12 +++++-----
voipmonitor.cpp | 2 +-
8 files changed, 63 insertions(+), 59 deletions(-)
diff --git a/heap_safe.cpp b/heap_safe.cpp
index 4dcf8768..a1db715f 100644
--- a/heap_safe.cpp
+++ b/heap_safe.cpp
@@ -15,6 +15,7 @@
#include "heap_chunk.h"
//#endif
+
extern sVerbose sverb;
extern int opt_abort_if_alloc_gt_gb;
@@ -791,9 +792,9 @@ std::string addThousandSeparators(u_int64_t num) {
}
void printMemoryStat(bool all) {
-#ifndef FREEBSD
- malloc_trim(0);
-#endif
+///#ifndef FREEBSD
+/// malloc_trim(0);
+///#endif
std::cout << getMemoryStat(all);
}
diff --git a/heap_safe.h b/heap_safe.h
index 08567a71..0a552f32 100644
--- a/heap_safe.h
+++ b/heap_safe.h
@@ -66,24 +66,24 @@ enum eHeapSafeErrors {
struct sHeapSafeMemoryControlBlock {
char stringInfo[3];
- u_int32_t length;
- u_int32_t memory_type;
+ uint32_t length;
+ uint32_t memory_type;
};
struct sHeapSafeMemoryControlBlockPlus : public sHeapSafeMemoryControlBlock {
void *block_addr;
char memory_type1[20];
- u_int16_t memory_type2;
- u_int16_t check_sum;
+ uint16_t memory_type2;
+ uint16_t check_sum;
};
struct sHeapSafeMemoryControlBlockEx : public sHeapSafeMemoryControlBlock {
- u_int32_t memory_type_other;
+ uint32_t memory_type_other;
};
struct sMemoryStatQuickBlock {
- u_int32_t alloc_number;
- u_int32_t size;
+ uint32_t alloc_number;
+ uint32_t size;
};
@@ -99,7 +99,7 @@ inline void *memcpy_heapsafe(void *destination, const void *destination_begin, c
if(HeapSafeCheck & _HeapSafeErrorBeginEnd) {
bool error = false;
sHeapSafeMemoryControlBlock *destination_beginMemoryBlock;
- u_int32_t destinationLength = 0;
+ uint32_t destinationLength = 0;
if(destination_begin) {
destination_beginMemoryBlock = (sHeapSafeMemoryControlBlock*)((unsigned char*)destination_begin - SIZEOF_MCB);
if(HEAPSAFE_CMP_BEGIN_MEMORY_CONTROL_BLOCK(destination_beginMemoryBlock->stringInfo)) {
@@ -110,7 +110,7 @@ inline void *memcpy_heapsafe(void *destination, const void *destination_begin, c
}
}
sHeapSafeMemoryControlBlock *source_beginMemoryBlock;
- u_int32_t sourceLength = 0;
+ uint32_t sourceLength = 0;
if(source_begin) {
source_beginMemoryBlock = (sHeapSafeMemoryControlBlock*)((unsigned char*)source_begin - SIZEOF_MCB);
if(HEAPSAFE_CMP_BEGIN_MEMORY_CONTROL_BLOCK(source_beginMemoryBlock->stringInfo)) {
@@ -156,7 +156,7 @@ inline void *memset_heapsafe(void *ptr, void *ptr_begin, int value, size_t lengt
if(HeapSafeCheck & _HeapSafeErrorBeginEnd) {
bool error = false;
sHeapSafeMemoryControlBlock *ptr_beginMemoryBlock;
- u_int32_t ptrLength = 0;
+ uint32_t ptrLength = 0;
if(ptr_begin) {
ptr_beginMemoryBlock = (sHeapSafeMemoryControlBlock*)((unsigned char*)ptr_begin - SIZEOF_MCB);
if(HEAPSAFE_CMP_BEGIN_MEMORY_CONTROL_BLOCK(ptr_beginMemoryBlock->stringInfo)) {
@@ -190,7 +190,7 @@ inline void *memset_heapsafe(void *ptr, int value, size_t length,
std::string getMemoryStat(bool all = false);
std::string getMemoryStatQuick(bool all = false);
-std::string addThousandSeparators(u_int64_t num);
+std::string addThousandSeparators(uint64_t num);
void printMemoryStat(bool all = false);
void memoryStatInit();
diff --git a/ip.cpp b/ip.cpp
index 67dab967..975ee5c3 100644
--- a/ip.cpp
+++ b/ip.cpp
@@ -29,7 +29,7 @@ bool vmIP::setFromString(const char *ip_str) {
ip_str_tmp[min(ip_str_length - 2, (unsigned)sizeof(ip_str_tmp))] = 0;
if(inet_pton(AF_INET6, ip_str_tmp, &ip.v6)) {
for(unsigned i = 0; i < 4; i++) {
- ip.v6.__in6_u.__u6_addr32[i] = ntohl(ip.v6.__in6_u.__u6_addr32[i]);
+ ip.v6.s6_addr[i] = ntohl(ip.v6.s6_addr[i]);
}
return(true);
}
@@ -37,7 +37,7 @@ bool vmIP::setFromString(const char *ip_str) {
} else {
if(inet_pton(AF_INET6, ip_str, &ip.v6)) {
for(unsigned i = 0; i < 4; i++) {
- ip.v6.__in6_u.__u6_addr32[i] = ntohl(ip.v6.__in6_u.__u6_addr32[i]);
+ ip.v6.s6_addr[i] = ntohl(ip.v6.s6_addr[i]);
}
return(true);
}
@@ -83,7 +83,7 @@ bool vmIP::setFromString(const char *ip_str, const char **end_ptr) {
ip_str_tmp[min(ip_str_length, (unsigned)sizeof(ip_str_tmp))] = 0;
if(inet_pton(AF_INET6, ip_str_tmp, &ip.v6)) {
for(unsigned i = 0; i < 4; i++) {
- ip.v6.__in6_u.__u6_addr32[i] = ntohl(ip.v6.__in6_u.__u6_addr32[i]);
+ ip.v6.s6_addr[i] = ntohl(ip.v6.s6_addr[i]);
}
if(end_ptr) {
*end_ptr = ip_str + ip_str_length + (ip_str[ip_str_length] == ']' ? 1 : 0);
@@ -122,7 +122,7 @@ std::string vmIP::getString(bool ipv6_in_brackets) const {
char ip_str[IP_STR_MAX_LENGTH];
in6_addr ip_v6;
for(unsigned i = 0; i < 4; i++) {
- ip_v6.__in6_u.__u6_addr32[i] = htonl(ip.v6.__in6_u.__u6_addr32[i]);
+ ip_v6.s6_addr[i] = htonl(ip.v6.s6_addr[i]);
}
inet_ntop(AF_INET6, &ip_v6, ip_str, IP_STR_MAX_LENGTH);
return(ipv6_in_brackets ?
diff --git a/ip.h b/ip.h
index d5bccd28..301d1dd0 100644
--- a/ip.h
+++ b/ip.h
@@ -81,7 +81,7 @@ struct vmIP {
case 16:
memcpy((u_char*)&ip.v6 + (sizeof(ip.v6) - data_ip_length), data_ip, data_ip_length);
for(unsigned i = 0; i < 4; i++) {
- ip.v6.__in6_u.__u6_addr32[i] = ntohl(ip.v6.__in6_u.__u6_addr32[i]);
+ ip.v6.s6_addr[i] = ntohl(ip.v6.s6_addr[i]);
}
v6 = true;
break;
@@ -108,7 +108,7 @@ struct vmIP {
this->ip.v6 = ip;
if(ntoh) {
for(unsigned i = 0; i < 4; i++) {
- this->ip.v6.__in6_u.__u6_addr32[i] = ntohl(this->ip.v6.__in6_u.__u6_addr32[i]);
+ this->ip.v6.s6_addr[i] = ntohl(this->ip.v6.s6_addr[i]);
}
}
v6 = true;
@@ -124,7 +124,7 @@ struct vmIP {
if(hton) {
in6_addr _ip = this->ip.v6;
for(unsigned i = 0; i < 4; i++) {
- _ip.__in6_u.__u6_addr32[i] = htonl(_ip.__in6_u.__u6_addr32[i]);
+ _ip.s6_addr[i] = htonl(_ip.s6_addr[i]);
}
return(_ip);
} else {
@@ -144,14 +144,14 @@ struct vmIP {
return((ip.v4.n >> 8) == 0x7F0000);
#if VM_IPV6
} else {
- return((ip.v6.__in6_u.__u6_addr32[0] == 0 &&
- ip.v6.__in6_u.__u6_addr32[1] == 0 &&
- ip.v6.__in6_u.__u6_addr32[2] == 0 &&
- ip.v6.__in6_u.__u6_addr32[3] == 1) ||
- (ip.v6.__in6_u.__u6_addr32[0] == 0 &&
- ip.v6.__in6_u.__u6_addr32[1] == 0 &&
- ip.v6.__in6_u.__u6_addr32[2] == 0xFFFF &&
- (ip.v6.__in6_u.__u6_addr32[3] >> 8) == 0x7F0000));
+ return((ip.v6.s6_addr[0] == 0 &&
+ ip.v6.s6_addr[1] == 0 &&
+ ip.v6.s6_addr[2] == 0 &&
+ ip.v6.s6_addr[3] == 1) ||
+ (ip.v6.s6_addr[0] == 0 &&
+ ip.v6.s6_addr[1] == 0 &&
+ ip.v6.s6_addr[2] == 0xFFFF &&
+ (ip.v6.s6_addr[3] >> 8) == 0x7F0000));
}
#endif
}
@@ -198,20 +198,20 @@ struct vmIP {
return(ip.v4.n != 0);
#if VM_IPV6
} else {
- return(ip.v6.__in6_u.__u6_addr32[0] != 0 ||
- ip.v6.__in6_u.__u6_addr32[1] != 0 ||
- ip.v6.__in6_u.__u6_addr32[2] != 0 ||
- ip.v6.__in6_u.__u6_addr32[3] != 0);
+ return(ip.v6.s6_addr[0] != 0 ||
+ ip.v6.s6_addr[1] != 0 ||
+ ip.v6.s6_addr[2] != 0 ||
+ ip.v6.s6_addr[3] != 0);
}
#endif
}
inline void clear(u_int32_t set = 0) {
#if VM_IPV6
v6 = false;
- ip.v6.__in6_u.__u6_addr32[0] = set;
- ip.v6.__in6_u.__u6_addr32[1] = set;
- ip.v6.__in6_u.__u6_addr32[2] = set;
- ip.v6.__in6_u.__u6_addr32[3] = set;
+ ip.v6.s6_addr[0] = set;
+ ip.v6.s6_addr[1] = set;
+ ip.v6.s6_addr[2] = set;
+ ip.v6.s6_addr[3] = set;
#else
ip.v4.n = set;
#endif
@@ -225,7 +225,7 @@ struct vmIP {
#if VM_IPV6
} else {
for(unsigned i = 0; i < 4; i++) {
- ip.ip.v6.__in6_u.__u6_addr32[i] &= mask.ip.v6.__in6_u.__u6_addr32[i];
+ ip.ip.v6.s6_addr[i] &= mask.ip.v6.s6_addr[i];
}
}
#endif
@@ -240,7 +240,7 @@ struct vmIP {
#if VM_IPV6
} else {
for(unsigned i = 0; i < 4; i++) {
- ip.ip.v6.__in6_u.__u6_addr32[i] |= mask.ip.v6.__in6_u.__u6_addr32[i];
+ ip.ip.v6.s6_addr[i] |= mask.ip.v6.s6_addr[i];
}
}
#endif
@@ -268,11 +268,11 @@ struct vmIP {
for(unsigned i = 0; i < 4; i++) {
int _mask = mask - i * 32;
if(mask == 0 || _mask <= 0) {
- ip.ip.v6.__in6_u.__u6_addr32[i] = 0;
+ ip.ip.v6.s6_addr[i] = 0;
} else if(_mask >= 32) {
- ip.ip.v6.__in6_u.__u6_addr32[i] = (u_int32_t)-1;
+ ip.ip.v6.s6_addr[i] = (u_int32_t)-1;
} else {
- ip.ip.v6.__in6_u.__u6_addr32[i] = ((u_int32_t)-1 << (32 - _mask)) & (u_int32_t)-1;
+ ip.ip.v6.s6_addr[i] = ((u_int32_t)-1 << (32 - _mask)) & (u_int32_t)-1;
}
}
}
@@ -298,11 +298,11 @@ struct vmIP {
for(unsigned i = 0; i < 4; i++) {
int _mask = mask - i * 32;
if(mask == 0 || _mask <= 0) {
- ip.ip.v6.__in6_u.__u6_addr32[i] = (u_int32_t)-1;
+ ip.ip.v6.s6_addr[i] = (u_int32_t)-1;
} else if(_mask >= 32) {
- ip.ip.v6.__in6_u.__u6_addr32[i] = 0;
+ ip.ip.v6.s6_addr[i] = 0;
} else {
- ip.ip.v6.__in6_u.__u6_addr32[i] = (u_int32_t)(pow(2, 32 -_mask) - 1);
+ ip.ip.v6.s6_addr[i] = (u_int32_t)(pow(2, 32 -_mask) - 1);
}
}
}
@@ -322,7 +322,7 @@ struct vmIP {
return(ip.v4.n);
#if VM_IPV6
} else {
- return(ip.v6.__in6_u.__u6_addr32[3]);
+ return(ip.v6.s6_addr[3]);
}
#endif
}
@@ -399,27 +399,27 @@ struct ip6hdr2 {
inline vmIP get_saddr() {
in6_addr __saddr = _saddr;
for(unsigned i = 0; i < 4; i++) {
- __saddr.__in6_u.__u6_addr32[i] = ntohl(__saddr.__in6_u.__u6_addr32[i]);
+ __saddr.s6_addr[i] = ntohl(__saddr.s6_addr[i]);
}
return(__saddr);
}
inline vmIP get_daddr() {
in6_addr __daddr = _daddr;
for(unsigned i = 0; i < 4; i++) {
- __daddr.__in6_u.__u6_addr32[i] = ntohl(__daddr.__in6_u.__u6_addr32[i]);
+ __daddr.s6_addr[i] = ntohl(__daddr.s6_addr[i]);
}
return(__daddr);
}
inline void set_saddr(vmIP &ip) {
_saddr = ip.getIPv6();
for(unsigned i = 0; i < 4; i++) {
- _saddr.__in6_u.__u6_addr32[i] = htonl(_saddr.__in6_u.__u6_addr32[i]);
+ _saddr.s6_addr[i] = htonl(_saddr.s6_addr[i]);
}
}
inline void set_daddr(vmIP &ip) {
_daddr = ip.getIPv6();
for(unsigned i = 0; i < 4; i++) {
- _daddr.__in6_u.__u6_addr32[i] = htonl(_daddr.__in6_u.__u6_addr32[i]);
+ _daddr.s6_addr[i] = htonl(_daddr.s6_addr[i]);
}
}
static inline bool is_ext_header(u_int8_t header_id) {
diff --git a/manager.cpp b/manager.cpp
index b087e706..097a1267 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -66,6 +66,9 @@
//define BUFSIZE 20480
#define BUFSIZE 4096 //block size?
+double min(double a, double b){ return a<b ? a : b; }
+double max(double a, double b){ return a>b ? a : b; }
+
extern Calltable *calltable;
extern volatile int terminating;
extern int opt_manager_port;
@@ -175,7 +178,7 @@ int Mgmt_params::sendString(string *str) {
unsigned chunkLength = 4096;
unsigned processedLength = 0;
while(processedLength < str->length()) {
- unsigned processLength = MIN(chunkLength, str->length() - processedLength);
+ unsigned processLength = min(chunkLength, str->length() - processedLength);
if(compressStream) {
compressStream->compress((char*)str->c_str() + processedLength, processLength, false, compressStream);
if(compressStream->isError()) {
diff --git a/pstat.h b/pstat.h
index 6b9aa64e..fe4ae38d 100644
--- a/pstat.h
+++ b/pstat.h
@@ -32,7 +32,7 @@ std::string getLoadAvgStr();
bool get_cpu_ht();
int get_cpu_count();
-bool get_interrupts_counters(std::map<std::string, std::pair<std::string, u_int64_t> > *counters);
+bool get_interrupts_counters(std::map<std::string, std::pair<std::string, uint64_t> > *counters);
#endif
diff --git a/tools.cpp b/tools.cpp
index 52e0b1cc..292dc0ad 100644
--- a/tools.cpp
+++ b/tools.cpp
@@ -8679,12 +8679,12 @@ unsigned RTPSENSOR_VERSION_INT() {
void rss_purge(bool force) {
- #ifndef FREEBSD
- malloc_trim(0);
- if(sverb.malloc_trim) {
- syslog(LOG_NOTICE, "malloc trim");
- }
- #endif
+// #ifndef FREEBSD
+// malloc_trim(0);
+// if(sverb.malloc_trim) {
+// syslog(LOG_NOTICE, "malloc trim");
+// }
+// #endif
#if HAVE_LIBTCMALLOC
bool tcmalloc_need_purge = false;
diff --git a/voipmonitor.cpp b/voipmonitor.cpp
index ec46223d..7d1ab9c3 100644
--- a/voipmonitor.cpp
+++ b/voipmonitor.cpp
@@ -152,7 +152,7 @@ signal_def signal_data[] =
{ "SIGTERM", SIGTERM, "Termination (ANSI)" },
{ "SIGSTKFLT", SIGSTKFLT, "Stack fault" },
{ "SIGCHLD", SIGCHLD, "Child status has changed (POSIX)" },
- { "SIGCLD", SIGCLD, "Same as SIGCHLD (System V)" },
+ { "SIGCLD", SIGCHLD, "Same as SIGCHLD (System V)" },
{ "SIGCONT", SIGCONT, "Continue (POSIX)" },
{ "SIGSTOP", SIGSTOP, "Stop, unblockable (POSIX)" },
{ "SIGTSTP", SIGTSTP, "Keyboard stop (POSIX)" },
--
2.37.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment