forked from networkupstools/nut
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
snmp-ups: Fix detection and display of hex strings
Signed-off-by: Arnaud Quette <[email protected]>
- Loading branch information
Showing
1 changed file
with
14 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* | ||
* Copyright (C) | ||
* 2002 - 2014 Arnaud Quette <[email protected]> | ||
* 2015 - 2018 Eaton (author: Arnaud Quette <[email protected]>) | ||
* 2015 - 2019 Eaton (author: Arnaud Quette <[email protected]>) | ||
* 2017 Eaton (author: Jim Klimov <[email protected]>) | ||
* 2002 - 2006 Dmitry Frolov <[email protected]> | ||
* J.W. Hoogervorst <[email protected]> | ||
|
@@ -126,7 +126,7 @@ const char *mibname; | |
const char *mibvers; | ||
|
||
#define DRIVER_NAME "Generic SNMP UPS driver" | ||
#define DRIVER_VERSION "1.05" | ||
#define DRIVER_VERSION "1.06" | ||
|
||
/* driver description structure */ | ||
upsdrv_info_t upsdrv_info = { | ||
|
@@ -774,15 +774,20 @@ static bool_t decode_str(struct snmp_pdu *pdu, char *buf, size_t buf_len, info_l | |
case ASN_OPAQUE: | ||
len = pdu->variables->val_len > buf_len - 1 ? | ||
buf_len - 1 : pdu->variables->val_len; | ||
if (len > 0) { | ||
/* Test for hexadecimal values */ | ||
if (!isprint(pdu->variables->val.string[0])) | ||
snprint_hexstring(buf, buf_len, pdu->variables->val.string, pdu->variables->val_len); | ||
else { | ||
memcpy(buf, pdu->variables->val.string, len); | ||
buf[len] = '\0'; | ||
/* Test for hexadecimal values */ | ||
int hex = 0, x; | ||
char *cp; | ||
for(cp = pdu->variables->val.string, x = 0; x < (int)pdu->variables->val_len; x++, cp++) { | ||
if (!(isprint(*cp) || isspace(*cp))) { | ||
hex = 1; | ||
} | ||
} | ||
if (hex) | ||
snprint_hexstring(buf, buf_len, pdu->variables->val.string, pdu->variables->val_len); | ||
else { | ||
memcpy(buf, pdu->variables->val.string, len); | ||
buf[len] = '\0'; | ||
} | ||
break; | ||
case ASN_INTEGER: | ||
case ASN_COUNTER: | ||
|