Skip to content

Commit

Permalink
MacOS Compilation
Browse files Browse the repository at this point in the history
- this compiles on my MacOS 15 system. But do the tests pass ?
  • Loading branch information
carlkidcrypto committed Dec 17, 2024
1 parent 4a84c67 commit 73f1361
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 2 deletions.
10 changes: 9 additions & 1 deletion ezsnmp/include/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,13 @@ std::vector<Result> parse_results(std::vector<std::string> const &inputs);
void remove_v3_user_from_cache(std::string const &security_name_str,
std::string const &context_engine_id_str);
std::string print_objid_to_string(oid const *objid, size_t objidlen);

#if NETSNMP_VERSION_MAJOR < 5 || \
(NETSNMP_VERSION_MAJOR == 5 && \
(NETSNMP_VERSION_MINOR < 6 || \
(NETSNMP_VERSION_MINOR == 6 && \
NETSNMP_VERSION_PATCH <= 2 )))
#define NETSNMP_APPLICATION_CONFIG_TYPE "snmpapp"
void netsnmp_cleanup_session(netsnmp_session *s);
void netsnmp_get_monotonic_clock(struct timeval* tv);
#endif
#endif // HELPERS_H
97 changes: 97 additions & 0 deletions ezsnmp/src/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,100 @@ std::string print_objid_to_string(oid const *objid, size_t objidlen) {
SNMP_FREE(buf);
return ss.str();
}


#if NETSNMP_VERSION_MAJOR < 5 || \
(NETSNMP_VERSION_MAJOR == 5 && \
(NETSNMP_VERSION_MINOR < 6 || \
(NETSNMP_VERSION_MINOR == 6 && \
NETSNMP_VERSION_PATCH <= 2 )))

/* Free the memory owned by a session but not the session object itself. */
void netsnmp_cleanup_session(netsnmp_session *s)
{
free(s->localname);
free(s->peername);
free(s->community);
free(s->contextEngineID);
free(s->contextName);
free(s->securityEngineID);
free(s->securityName);
free(s->securityAuthProto);
free(s->securityAuthLocalKey);
free(s->securityPrivProto);
free(s->securityPrivLocalKey);
free(s->paramName);
// #ifndef NETSNMP_NO_TRAP_STATS
// free(s->trap_stats);
// #endif /* NETSNMP_NO_TRAP_STATS */
// usm_free_user(s->sessUser);
memset(s, 0, sizeof(*s));
}

/**
* Query the current value of the monotonic clock.
*
* Returns the current value of a monotonic clock if such a clock is provided by
* the operating system or the wall clock time if no such clock is provided by
* the operating system. A monotonic clock is a clock that is never adjusted
* backwards and that proceeds at the same rate as wall clock time.
*
* @param[out] tv Pointer to monotonic clock time.
*/
void netsnmp_get_monotonic_clock(struct timeval* tv)
{
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
struct timespec ts;
int res;

res = clock_gettime(CLOCK_MONOTONIC, &ts);
if (res >= 0) {
tv->tv_sec = ts.tv_sec;
tv->tv_usec = ts.tv_nsec / 1000;
} else {
gettimeofday(tv, NULL);
}
#elif defined(WIN32)
/*
* Windows: return tick count. Note: the rate at which the tick count
* increases is not adjusted by the time synchronization algorithm, so
* expect an error of <= 100 ppm for the rate at which this clock
* increases.
*/
typedef ULONGLONG (WINAPI * pfGetTickCount64)(void);
static int s_initialized;
static pfGetTickCount64 s_pfGetTickCount64;
uint64_t now64;

if (!s_initialized) {
HMODULE hKernel32 = GetModuleHandle("kernel32");
s_pfGetTickCount64 =
(pfGetTickCount64) GetProcAddress(hKernel32, "GetTickCount64");
s_initialized = TRUE;
}

if (s_pfGetTickCount64) {
/* Windows Vista, Windows 2008 or any later Windows version */
now64 = (*s_pfGetTickCount64)();
} else {
/* Windows XP, Windows 2003 or any earlier Windows version */
static uint32_t s_wraps, s_last;
uint32_t now;

now = GetTickCount();
if (now < s_last)
s_wraps++;
s_last = now;
now64 = ((uint64_t)s_wraps << 32) | now;
}
tv->tv_sec = now64 / 1000;
tv->tv_usec = (now64 % 1000) * 1000;
#else
/* At least FreeBSD 4 doesn't provide monotonic clock support. */
#warning Not sure how to query a monotonically increasing clock on your system. \
Timers will not work correctly if the system clock is adjusted by e.g. ntpd.
gettimeofday(tv, NULL);
#endif
}

#endif /* NETSNMP_VERSION <= 5.6.2 */
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def is_net_snmp_installed_macports():
# Determine if a base directory has been provided with the --basedir option
basedir = None
in_tree = False
compile_args = ["-std=c++17", "-Werror"]
compile_args = ["-std=c++17", "-Werror", "-Wno-error=#warnings"]
link_args = []
system_netsnmp_version = check_output("net-snmp-config --version", shell=True).decode()
homebrew_version = None
Expand Down

0 comments on commit 73f1361

Please sign in to comment.