Greetings,I'm trying to compose a DateAndTime string, but when it's decoded by net-snmp's command-line tools it has trailing junk that I don't understand.
Here's my function. The input value is coming from a text-file that's in a human-readable format.
int
parse_dateandtime(char *input, char *output)
{
unsigned short int year, month, day, hour, minute, second;
unsigned short int i;
char *cptr;
/* Validate the input. */
if (input == NULL)
{
DEBUGMSGTL(("mitelSnmpUtil",
"parse_dateandtime: input is NULL\n"));
return FALSE;
}
if (output == NULL)
{
DEBUGMSGTL(("mitelSnmpUtil",
"parse_dateandtime: output is NULL\n"));
return FALSE;
}
/* Should look something like "2005-06-08,22:16:54" */
if (strlen(input) < MIN_DATETIME_LENGTH)
{
DEBUGMSGTL(("mitelSnmpUtil",
"parse_dateandtime: input string too small\n"));
return FALSE;
}
DEBUGMSGTL(("mitelSnmpUtil",
"Trying to parse DateAndTime string: %s\n", input));
if (sscanf(input, "%hu-%hu-%hu,%hu:%hu:%hu",
&year, &month, &day, &hour, &minute, &second) != 6)
{
fprintf(stderr, "Warning: Failed to parse DateAndTime value "
"from string: %s\n", input);
return FALSE;
}
DEBUGMSGTL(("mitelSnmpUtil",
"Parsed DateAndTime value. Got %d %d %d %d %d %d\n",
year, month, day, hour, minute, second));
/* Note, the year must be in network byte order. */
cptr = output;
i = year & 0xFF00;
i >>= 8;
*cptr = i;
cptr++;
*cptr = year & 0x00FF;
cptr++;
*cptr = (u_char)month;
cptr++;
*cptr = (u_char)day;
cptr++;
*cptr = (u_char)hour;
cptr++;
*cptr = (u_char)minute;
cptr++;
*cptr = (u_char)second;
cptr++;
/* While we only care up to the second, we should add in the other
octets
* with zeros anyway, just to be friendly to any clients expecting the
* agreed-upon length. We need four more bytes.
*/
*cptr = (u_char)0;
cptr++;
*cptr = (u_char)'-';
cptr++;
*cptr = (u_char)5;
cptr++;
*cptr = (u_char)0;
cptr++;
*cptr = '\0';
return TRUE;
}
But when I use this, the snmpwalk ends up looking funny.
MITEL-CMNALM-MIB::mitelAlmActiveTblSeverityDetectTime.10.1.3.6.1.4.1.1027.1.7.1
= STRING: 1971-1-16,12:1:30.0,-0:0495058484924000
Lots of trailing junk. Any idea what I'm doing wrong here? Thanks, Mike -- Michael P. Soulier <[EMAIL PROTECTED]>, 613-592-2122 x2522 Linux applications development "...the word HACK is used as a verb to indicate a massive amount of nerd-like effort." -Harley Hahn, A Student's Guide to Unix
smime.p7s
Description: S/MIME Cryptographic Signature
