summaryrefslogtreecommitdiff
path: root/support/dktools/prmonsnmp.c
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-09-20 03:03:26 +0000
committerNorbert Preining <norbert@preining.info>2020-09-20 03:03:26 +0000
commit1f457376b478257b88d4a857f5ec1b6155442dd7 (patch)
tree2a06a60551dea362cf8cb0cb0ba66c78608717c4 /support/dktools/prmonsnmp.c
parentac690ca29ad5bf8a5203a65fd6252f7b564f4727 (diff)
CTAN sync 202009200303
Diffstat (limited to 'support/dktools/prmonsnmp.c')
-rw-r--r--support/dktools/prmonsnmp.c192
1 files changed, 77 insertions, 115 deletions
diff --git a/support/dktools/prmonsnmp.c b/support/dktools/prmonsnmp.c
index 5842a9ca1a..0864bcaadd 100644
--- a/support/dktools/prmonsnmp.c
+++ b/support/dktools/prmonsnmp.c
@@ -1,36 +1,14 @@
/*
- WARNING: This file was generated by dkct.
- Changes you make here will be lost if dkct is run again!
- You should modify the original source and run dkct on it.
- Original source: prmonsnmp.ctr
+Copyright (C) 2016-2020, Dirk Krause
+SPDX-License-Identifier: BSD-3-Clause
*/
/*
-Copyright (C) 2016-2017, Dirk Krause
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-* Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-* Redistributions in binary form must reproduce the above opyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-* Neither the name of the author nor the names of contributors may be used
- to endorse or promote products derived from this software without specific
- prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ WARNING: This file was generated by the dkct program (see
+ http://dktools.sourceforge.net/ for details).
+ Changes you make here will be lost if dkct is run again!
+ You should modify the original source and run dkct on it.
+ Original source: prmonsnmp.ctr
*/
/** @file prmonsnmp.c The prmonsnmp module.
@@ -236,12 +214,13 @@ NULL
#include "dk4enc.h"
#include "dk4loc.h"
#include "dk4vers.h"
+#include "dk4unused.h"
-#line 181 "prmonsnmp.ctr"
+#line 182 "prmonsnmp.ctr"
@@ -272,7 +251,7 @@ static const char * const long_options[] = {
NULL
-#line 204 "prmonsnmp.ctr"
+#line 205 "prmonsnmp.ctr"
};
@@ -288,10 +267,6 @@ static const oid prmonsnmp_oid_ds[] = {
*/
static size_t const pjsnmp_sz_oid_ds = sizeof(prmonsnmp_oid_ds)/sizeof(oid);
-/** Size of device status OID (number of bytes).
-*/
-static size_t const pjsnmp_bytes_oid_ds = sizeof(prmonsnmp_oid_ds);
-
/** OID for printer status.
*/
@@ -304,10 +279,6 @@ static const oid prmonsnmp_oid_ps[] = {
*/
static size_t const pjsnmp_sz_oid_ps = sizeof(prmonsnmp_oid_ps)/sizeof(oid);
-/** Size of printer status OID (number of bytes).
-*/
-static size_t const pjsnmp_bytes_oid_ps = sizeof(prmonsnmp_oid_ps);
-
/** OID for pagecount value.
*/
@@ -320,10 +291,6 @@ static const oid prmonsnmp_oid_pc[] = {
*/
static size_t const pjsnmp_sz_oid_pc = sizeof(prmonsnmp_oid_pc)/sizeof(oid);
-/** Size of page counter OID (number of bytes).
-*/
-static size_t const pjsnmp_bytes_oid_pc = sizeof(prmonsnmp_oid_pc);
-
/** Printer error OID.
*/
@@ -336,10 +303,6 @@ static const oid prmonsnmp_oid_pe[] = {
*/
static size_t const pjsnmp_sz_oid_pe = sizeof(prmonsnmp_oid_pe)/sizeof(oid);
-/** Size of printer error OID (number of bytes).
-*/
-static size_t const pjsnmp_bytes_oid_pe = sizeof(prmonsnmp_oid_pe);
-
/** Status text OID.
*/
static const oid prmonsnmp_oid_st[] = {
@@ -351,11 +314,6 @@ static const oid prmonsnmp_oid_st[] = {
*/
static size_t const pjsnmp_sz_oid_st = sizeof(prmonsnmp_oid_st)/sizeof(oid);
-/** Size of printer error OID (number of bytes).
-*/
-static size_t const pjsnmp_bytes_oid_st = sizeof(prmonsnmp_oid_st);
-
-
/** Help text.
*/
@@ -378,7 +336,7 @@ static const char * const help_text[] = {
NULL
-#line 308 "prmonsnmp.ctr"
+#line 288 "prmonsnmp.ctr"
};
@@ -391,7 +349,8 @@ static const char * const license_text[] = {
"a library:",
"",
"dktools\t\tDirk Krause's tools and libraries.",
-"\t\tSee http://dktools.sourceforge.net/ for more information.",
+"\t\tSee http://sourceforge.net/p/dktools/wiki/Home/",
+"\t\tfor more information.",
#if DK4_HAVE_LIBNETSNMP
"Net-SNMP\tSNMP access library.",
"\t\tSee http://net-snmp.sourceforge.net/ for more information.",
@@ -428,27 +387,27 @@ static const char * const license_text[] = {
"Redistribution and use in source and binary forms, with or without",
"modification, are permitted provided that the following conditions are met:",
"",
-"* Redistributions of source code must retain the above copyright notice,",
-" this list of conditions and the following disclaimer.",
-"* Redistributions in binary form must reproduce the above copyright",
-" notice, this list of conditions and the following disclaimer in the",
-" documentation and/or other materials provided with the distribution.",
-"* Neither the name of the Dirk Krause nor the names of contributors may be",
-" used to endorse or promote products derived from this software without",
-" specific prior written permission.",
-"",
-"THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"",
-"AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE",
-"IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE",
-"ARE DISCLAIMED.",
-"",
-"IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,",
-"INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,",
-"BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,",
-"DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY",
-"OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING",
-"NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,",
-"EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.",
+"1. Redistributions of source code must retain the above copyright notice,",
+" this list of conditions and the following disclaimer.",
+"2. Redistributions in binary form must reproduce the above copyright",
+" notice, this list of conditions and the following disclaimer in the",
+" documentation and/or other materials provided with the distribution.",
+"3. Neither the name of the copyright holder nor the names of its",
+" contributors may be used to endorse or promote products derived from",
+" this software without specific prior written permission.",
+"",
+"THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS",
+"``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT",
+"LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR",
+"A PARTICULAR PURPOSE ARE DISCLAIMED.",
+"IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY",
+"DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES",
+"(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR",
+"SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER",
+"CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT",
+"LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY",
+"OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF",
+"SUCH DAMAGE.",
#if DK4_HAVE_LIBNETSNMP
"",
"",
@@ -902,7 +861,7 @@ static const char * const license_text[] = {
NULL
-#line 830 "prmonsnmp.ctr"
+#line 811 "prmonsnmp.ctr"
};
@@ -931,7 +890,7 @@ static const char * const snmp_version_names[] = {
NULL
-#line 849 "prmonsnmp.ctr"
+#line 830 "prmonsnmp.ctr"
};
@@ -995,7 +954,7 @@ static
DK4_VOLATILE
dk4_sig_atomic_t sig_had_term = 0;
-static int encoding = DK4_ENCODING_ASCII;
+static int encoding = DK4_ENCODING_PLAIN;
#endif
/** Exit status code.
@@ -1033,8 +992,9 @@ sig_pass_pointer(DK4_VOLATILE dk4_sig_atomic_t *ptr)
*/
static
void
-sig_handler_pipe(int signo)
+sig_handler_pipe(int DK4_ARG_UNUSED(signo) )
{
+ DK4_UNUSED_ARG(signo)
*sig_pass_pointer(&sig_had_pipe) = 1;
}
#endif
@@ -1045,8 +1005,9 @@ sig_handler_pipe(int signo)
*/
static
void
-sig_handler_int(int signo)
+sig_handler_int(int DK4_ARG_UNUSED(signo) )
{
+ DK4_UNUSED_ARG(signo)
*sig_pass_pointer(&sig_had_int) = 1;
}
@@ -1056,8 +1017,9 @@ sig_handler_int(int signo)
*/
static
void
-sig_handler_term(int signo)
+sig_handler_term(int DK4_ARG_UNUSED(signo) )
{
+ DK4_UNUSED_ARG(signo)
*sig_pass_pointer(&sig_had_term) = 1;
}
@@ -1183,11 +1145,11 @@ get_int(int *iptr, struct variable_list *var)
int back = 0;
-#line 1099 "prmonsnmp.ctr"
+#line 1083 "prmonsnmp.ctr"
switch (var->type) {
case ASN_OCTET_STR : {
-#line 1101 "prmonsnmp.ctr"
+#line 1085 "prmonsnmp.ctr"
if ((var->val_len > 0) && (var->val_len < sizeof(bu))) {
dk4mem_cpy(bu, (void *)((var->val).string), var->val_len, NULL);
bu[var->val_len] = '\0';
@@ -1202,7 +1164,7 @@ get_int(int *iptr, struct variable_list *var)
case ASN_COUNTER :
case ASN_INTEGER : {
-#line 1114 "prmonsnmp.ctr"
+#line 1098 "prmonsnmp.ctr"
l = *((var->val).integer);
*iptr = (int)l;
back = 1;
@@ -1210,7 +1172,7 @@ get_int(int *iptr, struct variable_list *var)
}
-#line 1120 "prmonsnmp.ctr"
+#line 1104 "prmonsnmp.ctr"
return back;
}
@@ -1229,11 +1191,11 @@ get_ul(unsigned long *ulptr, struct variable_list *var)
int back = 0;
-#line 1137 "prmonsnmp.ctr"
+#line 1121 "prmonsnmp.ctr"
switch (var->type) {
case ASN_OCTET_STR : {
-#line 1139 "prmonsnmp.ctr"
+#line 1123 "prmonsnmp.ctr"
if (0 < var->val_len) {
ul |=
((((unsigned long)(((var->val).string)[0])) << 24) & 0xFF000000UL);
@@ -1260,7 +1222,7 @@ get_ul(unsigned long *ulptr, struct variable_list *var)
case ASN_COUNTER :
case ASN_INTEGER : {
-#line 1164 "prmonsnmp.ctr"
+#line 1148 "prmonsnmp.ctr"
l = *((var->val).integer);
if (0L <= l) {
*ulptr = (unsigned long)l;
@@ -1270,7 +1232,7 @@ get_ul(unsigned long *ulptr, struct variable_list *var)
}
-#line 1172 "prmonsnmp.ctr"
+#line 1156 "prmonsnmp.ctr"
return back;
}
@@ -1408,7 +1370,7 @@ run_main_loop(void)
lst = 0;
must_show = 0;
-#line 1308 "prmonsnmp.ctr"
+#line 1292 "prmonsnmp.ctr"
must_flush = 0;
if (0 != can_continue(0)) {
rq = snmp_pdu_create(SNMP_MSG_GET);
@@ -1469,34 +1431,34 @@ run_main_loop(void)
if (0 != (1 & found)) {
if (devst != odevst) {
-#line 1367 "prmonsnmp.ctr"
+#line 1351 "prmonsnmp.ctr"
must_show = 1;
}
}
if (0 != (2 & found)) {
if (prist != oprist) {
-#line 1372 "prmonsnmp.ctr"
+#line 1356 "prmonsnmp.ctr"
must_show = 1;
}
}
if (0 != (4 & found)) {
if (cond != ocond) {
-#line 1377 "prmonsnmp.ctr"
+#line 1361 "prmonsnmp.ctr"
must_show = 1;
}
}
if (0 != (8 & found)) {
if (lst != olst) {
-#line 1382 "prmonsnmp.ctr"
+#line 1366 "prmonsnmp.ctr"
must_show = 1;
}
if (0 != dk4mem_cmp(statext, ostatext, lst, NULL)) {
-#line 1386 "prmonsnmp.ctr"
+#line 1370 "prmonsnmp.ctr"
must_show = 1;
}
}
@@ -1548,7 +1510,7 @@ run_main_loop(void)
if (0 != (8 & found)) {
if (0 < lst) {
uptr = (unsigned char *)statext;
- for (i = 0; i < lst; i++) {
+ for (i = 0; (size_t)i < lst; i++) {
if (0 < i) {
if (0 == (i % 24)) {
fputc('\n', stdout);
@@ -1809,7 +1771,7 @@ run_hvl(void)
{
-#line 1697 "prmonsnmp.ctr"
+#line 1681 "prmonsnmp.ctr"
if (0 != (1 & hvl)) {
show_text(help_text);
}
@@ -1824,7 +1786,7 @@ run_hvl(void)
exval = EXIT_SUCCESS;
-#line 1710 "prmonsnmp.ctr"
+#line 1694 "prmonsnmp.ctr"
}
@@ -1843,7 +1805,7 @@ int main(int argc, char *argv[])
/* +++++ Required libraries available */
dkChar blang[32];
dkChar breg[32];
- struct snmp_session template;
+ struct snmp_session sesstemp;
#if DK4_HAVE_SIGACTION
#ifdef SIGPIPE
struct sigaction opipe;
@@ -1871,10 +1833,10 @@ int main(int argc, char *argv[])
#endif
-#line 1755 "prmonsnmp.ctr"
+#line 1739 "prmonsnmp.ctr"
-#line 1756 "prmonsnmp.ctr"
+#line 1740 "prmonsnmp.ctr"
/* Set signal handlers.
--------------------
@@ -1952,7 +1914,7 @@ int main(int argc, char *argv[])
------------------
*/
if (0 == dk4loc_get_settings(blang, szblang, breg, szbreg, &encoding, NULL)) {
- encoding = DK4_ENCODING_ASCII;
+ encoding = DK4_ENCODING_PLAIN;
}
/* Process command line arguments.
-------------------------------
@@ -1972,32 +1934,32 @@ int main(int argc, char *argv[])
#if DK4_HAVE_SNMP_DISABLE_SYSLOG
-#line 1852 "prmonsnmp.ctr"
+#line 1836 "prmonsnmp.ctr"
snmp_disable_syslog();
#endif
#if DK4_HAVE_SNMP_DISABLE_FILELOG
-#line 1856 "prmonsnmp.ctr"
+#line 1840 "prmonsnmp.ctr"
snmp_disable_filelog();
#endif
#if DK4_HAVE_SNMP_DISABLE_STDERRLOG
-#line 1860 "prmonsnmp.ctr"
+#line 1844 "prmonsnmp.ctr"
snmp_disable_stderrlog();
#endif
init_snmp(prmonsnmp_kw[2]);
- DK4_MEMRES(&template, sizeof(template));
- snmp_sess_init(&template);
- template.version = snmp_vers;
- template.peername = host_name;
- template.community = (unsigned char *)snmp_comm;
+ DK4_MEMRES(&sesstemp, sizeof(sesstemp));
+ snmp_sess_init(&sesstemp);
+ sesstemp.version = snmp_vers;
+ sesstemp.peername = host_name;
+ sesstemp.community = (unsigned char *)snmp_comm;
if (NULL == snmp_comm) {
- template.community = (unsigned char *)(prmonsnmp_kw[3]);
+ sesstemp.community = (unsigned char *)(prmonsnmp_kw[3]);
}
- template.community_len = strlen((char *)(template.community));
- snmp_sess = snmp_open(&template);
+ sesstemp.community_len = strlen((char *)(sesstemp.community));
+ snmp_sess = snmp_open(&sesstemp);
if (NULL == snmp_sess) {
/* ERROR: Failed to open session */
fputs(prmonsnmp_kw[2], stderr);
@@ -2064,10 +2026,10 @@ int main(int argc, char *argv[])
-#line 1938 "prmonsnmp.ctr"
+#line 1922 "prmonsnmp.ctr"
-#line 1939 "prmonsnmp.ctr"
+#line 1923 "prmonsnmp.ctr"
/* ----- Required libraries available */
#else