Skip to content

Commit

Permalink
Merge branch 'V5-9-patches'
Browse files Browse the repository at this point in the history
* V5-9-patches:
  libsnmp: Remove a cast
  TCP-MIB: Fix several memory leaks
  Use #ifdef instead of #if to test HAVE_* macros
  libsnmp: Improve the netsnmp_getaddrinfo() debug output
  win32/build.pl: Improve the menu script further
  Windows, MSVC: Use getaddrinfo()
  Revert "Windows, MSVC: Use getaddrinfo() if it is available"
  Python: Use % NETSNMP_PRIo u instead of %lu
  Use #ifdef instead of #if to test HAVE_* macros
  win32/build.pl: Fix menu system
  • Loading branch information
bvanassche committed Jun 23, 2021
2 parents ec3cf02 + a7aa206 commit 1410430
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 99 deletions.
2 changes: 1 addition & 1 deletion agent/agent_read_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#if HAVE_SYS_SOCKETVAR_H
#ifdef HAVE_SYS_SOCKETVAR_H
#ifndef dynix
#include <sys/socketvar.h>
#else
Expand Down
2 changes: 1 addition & 1 deletion agent/mibgroup/hardware/fsys/fsys_mntent.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ netsnmp_fsys_arch_load( void )

if ( _fsys_remote( entry->device, entry->type ))
entry->flags |= NETSNMP_FS_FLAG_REMOTE;
#if HAVE_HASMNTOPT
#ifdef HAVE_HASMNTOPT
if (hasmntopt( m, NETSNMP_REMOVE_CONST(char *, "ro") ))
entry->flags |= NETSNMP_FS_FLAG_RONLY;
else
Expand Down
8 changes: 6 additions & 2 deletions agent/mibgroup/tcp-mib/data_access/tcpConn_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ _load4(netsnmp_container *container, u_int load_flags)
* add entry to container
*/
entry->arbitrary_index = CONTAINER_SIZE(container) + 1;
CONTAINER_INSERT(container, entry);
if (CONTAINER_INSERT(container, entry) < 0) {
netsnmp_access_tcpconn_entry_free(entry);
}
}

fclose(in);
Expand Down Expand Up @@ -389,7 +391,9 @@ _load6(netsnmp_container *container, u_int load_flags)
* add entry to container
*/
entry->arbitrary_index = CONTAINER_SIZE(container) + 1;
CONTAINER_INSERT(container, entry);
if (CONTAINER_INSERT(container, entry) < 0) {
netsnmp_access_tcpconn_entry_free(entry);
}
}

fclose(in);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,23 +178,23 @@ _add_connection(netsnmp_tcpconn_entry *entry, netsnmp_container *container)
* the container
*/
rowreq_ctx = tcpListenerTable_allocate_rowreq_ctx(entry, NULL);
if ((NULL != rowreq_ctx) &&
(MFD_SUCCESS == tcpListenerTable_indexes_set(rowreq_ctx,
entry->loc_addr_len,
(char *) entry->loc_addr,
entry->loc_addr_len,
entry->loc_port))) {
CONTAINER_INSERT(container, rowreq_ctx);
} else {
if (rowreq_ctx) {
snmp_log(LOG_ERR, "error setting index while loading "
"tcpListenerTable cache.\n");
tcpListenerTable_release_rowreq_ctx(rowreq_ctx);
} else {
snmp_log(LOG_ERR, "memory allocation failed while loading "
"tcpListenerTable cache.\n");
netsnmp_access_tcpconn_entry_free(entry);
}
if (!rowreq_ctx) {
snmp_log(LOG_ERR,
"memory allocation failed while loading tcpListenerTable cache.\n");
netsnmp_access_tcpconn_entry_free(entry);
return;
}
if (tcpListenerTable_indexes_set(rowreq_ctx, entry->loc_addr_len,
(char *)entry->loc_addr, entry->loc_addr_len, entry->loc_port) !=
MFD_SUCCESS) {
snmp_log(LOG_ERR,
"error setting index while loading tcpListenerTable cache.\n");
tcpListenerTable_release_rowreq_ctx(rowreq_ctx);
return;
}
if (CONTAINER_INSERT(container, rowreq_ctx) < 0) {
snmp_log(LOG_ERR, "tcpListenerTable insert failed.\n");
tcpListenerTable_release_rowreq_ctx(rowreq_ctx);
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/snmpping.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ start_ping(netsnmp_session *ss, oid * index, size_t indexlen, char *pingDest)

memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
status = netsnmp_getaddrinfo(pingDest, NULL, &hints, &dest);
status = getaddrinfo(pingDest, NULL, &hints, &dest);
if (status != 0) {
fprintf(stderr, "snmpping: %s: %s\n", pingDest, gai_strerror(status));
return 1;
Expand Down
2 changes: 1 addition & 1 deletion include/net-snmp/library/mt_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extern "C" {

#if defined(NETSNMP_REENTRANT) || defined(WIN32)

#if HAVE_PTHREAD_H
#ifdef HAVE_PTHREAD_H
#include <pthread.h>
typedef pthread_mutex_t mutex_type;
#ifdef pthread_mutexattr_default
Expand Down
8 changes: 4 additions & 4 deletions python/netsnmp/client_intf.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ __sprint_num_objid(char **buf, size_t *buf_len, const oid *objid, int len)
end = *buf + *buf_len;
(*buf)[0] = '\0';
for (i = 0; i < len; i++)
p += snprintf(p, end - p, ".%lu", *objid++);
p += snprintf(p, end - p, ".%" NETSNMP_PRIo "u", *objid++);

return SUCCESS;
}
Expand Down Expand Up @@ -348,7 +348,7 @@ __scan_num_objid(const char *buf, oid *objid, size_t *len)
cp = buf;
while (*buf) {
if (*buf++ == '.') {
sscanf(cp, "%lu", objid++);
sscanf(cp, "%" NETSNMP_PRIo "u", objid++);
/* *objid++ = atoi(cp); */
(*len)++;
cp = buf;
Expand All @@ -358,7 +358,7 @@ __scan_num_objid(const char *buf, oid *objid, size_t *len)
}
}
}
sscanf(cp, "%lu", objid++);
sscanf(cp, "%" NETSNMP_PRIo "u", objid++);
/* *objid++ = atoi(cp); */
(*len)++;
return SUCCESS;
Expand Down Expand Up @@ -495,7 +495,7 @@ __concat_oid_str(oid *doid_arr, size_t *doid_arr_len, const char *soid_str)
return FAILURE;
cp = strtok_r(soid_buf,".",&st);
while (cp) {
sscanf(cp, "%lu", &(doid_arr[(*doid_arr_len)++]));
sscanf(cp, "%" NETSNMP_PRIo "u", &(doid_arr[(*doid_arr_len)++]));
/* doid_arr[(*doid_arr_len)++] = atoi(cp); */
cp = strtok_r(NULL,".",&st);
}
Expand Down
8 changes: 4 additions & 4 deletions snmplib/mt_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static int
snmp_res_init_mutex(mutex_type *mutex)
{
int rc = 0;
#if HAVE_PTHREAD_H
#ifdef HAVE_PTHREAD_H
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
Expand Down Expand Up @@ -84,7 +84,7 @@ snmp_res_destroy_mutex(int groupID, int resourceID)
return EFAULT;
}

#if HAVE_PTHREAD_H
#ifdef HAVE_PTHREAD_H
rc = pthread_mutex_destroy(mutex);
#elif defined(WIN32)
DeleteCriticalSection(mutex);
Expand All @@ -103,7 +103,7 @@ snmp_res_lock(int groupID, int resourceID)
return EFAULT;
}

#if HAVE_PTHREAD_H
#ifdef HAVE_PTHREAD_H
rc = pthread_mutex_lock(mutex);
#elif defined(WIN32)
EnterCriticalSection(mutex);
Expand All @@ -122,7 +122,7 @@ snmp_res_unlock(int groupID, int resourceID)
return EFAULT;
}

#if HAVE_PTHREAD_H
#ifdef HAVE_PTHREAD_H
rc = pthread_mutex_unlock(mutex);
#elif defined(WIN32)
LeaveCriticalSection(mutex);
Expand Down
4 changes: 2 additions & 2 deletions snmplib/snmp_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ netsnmp_tdomain_transport_tspec(netsnmp_tdomain_spec *tspec)
const char * const *spec = NULL;
int any_found = 0;
char buf[SNMP_MAXPATH];
char **lspec = NULL;
const char **lspec = NULL;
char *tokenized_domain = NULL;

application = tspec->application;
Expand Down Expand Up @@ -749,7 +749,7 @@ netsnmp_tdomain_transport_tspec(netsnmp_tdomain_spec *tspec)
lspec[0] = strtok_r(tokenized_domain, ",", &ptr);
while ((lspec[commas++] = strtok_r(NULL, ",", &ptr)))
;
spec = (const char * const *)lspec;
spec = lspec;
}
} else {
spec = netsnmp_lookup_default_domains(application);
Expand Down
80 changes: 33 additions & 47 deletions snmplib/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,48 +768,6 @@ netsnmp_validator_context(void)
}
#endif /* DNSSEC_LOCAL_VALIDATION */

#if (defined(_MSC_VER) || defined(__MINGW32__)) && !defined(HAVE_GETADDRINFO)
static int getaddrinfo_wrapper(const char *nodename, const char *servname,
const struct addrinfo *hints, struct addrinfo **res)
{
typedef int (WSAAPI * pf_getaddrinfo)
(const char *pNodeName, const char *pServiceName,
const struct addrinfo *pHints, struct addrinfo **ppResult);
pf_getaddrinfo getaddrinfo_ptr;

getaddrinfo_ptr = (pf_getaddrinfo)(uintptr_t)
GetProcAddress(GetModuleHandle("ws2_32"), "getaddrinfo");
if (getaddrinfo_ptr)
return getaddrinfo_ptr(nodename, servname, hints, res);
/* For Windows 7 and older, fall back to gethostbyname(). */
{
struct hostent *hp = gethostbyname(nodename);
struct addrinfo result;

if (!hp ||
(hints && hints->ai_family && hp->h_addrtype != hints->ai_family))
return EAI_FAIL;
memset(&result, 0, sizeof(result));
result.ai_family = hp->h_addrtype;
result.ai_addr = (void *)hp->h_addr_list[0];
switch (hp->h_addrtype) {
case AF_INET:
result.ai_addrlen = sizeof(struct sockaddr_in);
break;
case AF_INET6:
result.ai_addrlen = sizeof(struct sockaddr_in6);
break;
default:
return EAI_FAIL;
}
*res = netsnmp_memdup(&result, sizeof(result));
return *res ? 0 : EAI_MEMORY;
}
}
#define HAVE_GETADDRINFO 1
#define getaddrinfo getaddrinfo_wrapper
#endif

int
netsnmp_gethostbyname_v4(const char* name, in_addr_t *addr_out)
{
Expand Down Expand Up @@ -901,7 +859,11 @@ netsnmp_getaddrinfo(const char *name, const char *service,
DEBUGMSG(("dns:getaddrinfo", ":\"%s\"", service));

if (hints)
DEBUGMSG(("dns:getaddrinfo", " with hint ({ ... })"));
DEBUGMSG(("dns:getaddrinfo",
" with hints ({.ai_flags = %#x, .ai_family = %s})",
hints->ai_flags, hints->ai_family == 0 ? "0" :
hints->ai_family == AF_INET ? "AF_INET" :
hints->ai_family == AF_INET6 ? "AF_INET6" : "?"));
else
DEBUGMSG(("dns:getaddrinfo", " with no hint"));

Expand Down Expand Up @@ -948,10 +910,34 @@ netsnmp_getaddrinfo(const char *name, const char *service,

#endif /* DNSSEC_LOCAL_VALIDATION */
*res = addrs;
if ((0 == err) && addrs && addrs->ai_addr) {
DEBUGMSGTL(("dns:getaddrinfo", "answer { AF_INET, %s:%hu }\n",
inet_ntoa(((struct sockaddr_in*)addrs->ai_addr)->sin_addr),
ntohs(((struct sockaddr_in*)addrs->ai_addr)->sin_port)));
DEBUGIF("dns:getaddrinfo") {
if (err == 0 && addrs && addrs->ai_addr) {
const char *fam = "?";
char dst[64] = "?";
uint16_t port = 0;

switch (addrs->ai_addr->sa_family) {
case AF_INET: {
struct sockaddr_in *sin = (struct sockaddr_in *)addrs->ai_addr;

fam = "AF_INET";
inet_ntop(AF_INET, &sin->sin_addr, dst, sizeof(dst));
port = ntohs(sin->sin_port);
break;
}
case AF_INET6: {
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
addrs->ai_addr;

fam = "AF_INET6";
inet_ntop(AF_INET6, &sin6->sin6_addr, dst, sizeof(dst));
port = ntohs(sin6->sin6_port);
break;
}
}
DEBUGMSGTL(("dns:getaddrinfo", "answer { %s, %s:%hu }\n", fam, dst,
port));
}
}
return err;
#else
Expand Down
31 changes: 14 additions & 17 deletions win32/build.pl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
my @perl_arch = split(/-/, $Config{archname});
my $openssl = false;
my $default_openssldir = $target_arch eq "x64" ?
"C:\\OpenSSL-Win64" : "C:\\OpenSSL-Win32";
"C:\\Progra~1\\OpenSSL-Win64" : "C:\\Progra~1\\OpenSSL-Win32";
my $default_opensslincdir = $default_openssldir . "\\include";
my $opensslincdir = $default_opensslincdir;
my $default_openssllibdir = $default_openssldir . "\\lib\\VC";
Expand Down Expand Up @@ -66,10 +66,10 @@
print "7. Install perl modules: " . ($perl_install ? "enabled" : "disabled") . "\n";
print "\n";
print "8. Quiet build (logged): " . ($logging ? "enabled" : "disabled") . "\n";
print "9. Debug mode: " . ($debug ? "enabled" : "disabled") . "\n";
print "9. Debug mode: " . ($debug ? "enabled" : "disabled") . "\n";
print "\n";
print "10. IPv6 transports (requires SDK): " . ($b_ipv6 ? "enabled" : "disabled") . "\n";
print "11. winExtDLL agent (requires SDK): " . ($b_winextdll ? "enabled" : "disabled") . "\n";
print "10. IPv6 transports: " . ($b_ipv6 ? "enabled" : "disabled") . "\n";
print "11. winExtDLL agent: " . ($b_winextdll ? "enabled" : "disabled") . "\n";
print "\n";
print "12. Link type: " . ($link_dynamic ? "dynamic" : "static") . "\n";
print "\n";
Expand All @@ -94,48 +94,45 @@
$openssllibdir =~ s/\\/\//g;
$openssllibdir = $default_openssllibdir if ($openssllibdir eq "");
}
elsif ($option eq "4") {
$sdk = !$sdk;
}
elsif ($option eq "11") {
elsif ($option eq "10") {
$b_ipv6 = !$b_ipv6;
if ($b_ipv6 && !$sdk) {
print "\n\n* SDK required for IPv6 and has been automatically enabled";
$sdk = true;
}
}
elsif ($option eq "12") {
elsif ($option eq "11") {
$b_winextdll = !$b_winextdll;
if ($b_winextdll && !$sdk) {
print "\n\n* SDK required for IPv6 and has been automatically enabled";
$sdk = true;
}
}
elsif ($option eq "5") {
elsif ($option eq "4") {
print "Please enter the new install path [$default_install_base]: ";
chomp ($install_base = <>);
$install_base =~ s/\\/\//g;
$install_base = $default_install_base if ($install_base eq "");
}
elsif ($option eq "6") {
elsif ($option eq "5") {
$install = !$install;
}
elsif ($option eq "14") {
elsif ($option eq "13") {
$install_devel = !$install_devel;
}
elsif ($option eq "7") {
elsif ($option eq "6") {
$perl = !$perl;
}
elsif ($option eq "8") {
elsif ($option eq "7") {
$perl_install = !$perl_install;
}
elsif ($option eq "9") {
elsif ($option eq "8") {
$logging = !$logging;
}
elsif ($option eq "10") {
elsif ($option eq "9") {
$debug = !$debug;
}
elsif ($option eq "13") {
elsif ($option eq "12") {
$link_dynamic = !$link_dynamic;
}
elsif (lc($option) eq "f") {
Expand Down
2 changes: 1 addition & 1 deletion win32/net-snmp/net-snmp-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@
/* #undef HAVE_FSTAB_H */

/* Define to 1 if you have the `getaddrinfo' function. */
/* #undef HAVE_GETADDRINFO */
#define HAVE_GETADDRINFO 1

/* Define to 1 if you have the `getdtablesize' function. */
/* #undef HAVE_GETDTABLESIZE */
Expand Down
2 changes: 1 addition & 1 deletion win32/net-snmp/net-snmp-config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@
/* #undef HAVE_FSTAB_H */

/* Define to 1 if you have the `getaddrinfo' function. */
/* #undef HAVE_GETADDRINFO */
#define HAVE_GETADDRINFO 1

/* Define to 1 if you have the `getdtablesize' function. */
/* #undef HAVE_GETDTABLESIZE */
Expand Down

0 comments on commit 1410430

Please sign in to comment.