SNMP Subagent Programmer's Guide
System Time Manager
2-78 119728—SNMP Subagent Programmer’s Guide
Programming Tutorials
Example 2-16. System Time Manager Access Functions (page 1 of 2)
#include "tdmporth" nolist  /* these three include files are here so  */
#include "snmperrH" nolist  /* accessf.c could be compiled separately */
#include "smitypeH" nolist  /* from systime.c.           */
#include <timeh>  nolist /* for systemTimeString GET & SETs */     <--
9
#include <talh>  nolist  
#include <cextdecs (COMPUTETIMESTAMP, CONVERTTIMESTAMP, \
        PROCESS_GETINFO_,SETSYSTEMCLOCK)> nolist
static int
GET_systemTimeString(void *ctxt, void **indices, void *attr_ref)        <--
10
{
 OCTETSTRING  *attr;
 time_t    now;
 struct tm   *curtime;
 now = time(NULL);
 curtime = localtime(&now);
 systemTimeString.len = (Len_t) strftime (systemTimeString.val,
             20, "%Y/%m/%d %H:%M:%S",
             curtime);
 attr = (OCTETSTRING *) attr_ref;
 *attr = systemTimeString;
 return(SNMP_ERR_NO_ERROR);
}
static int
SET_systemTimeString(void *ctxt, void **indices, void *attr_ref)        <--
11 
{
 OCTETSTRING  *attr;
 short     ccstatus;
 ccstatus = SETSYSTEMCLOCK(juliantime,0);
 if (ccstatus == CCE)
  { return(SNMP_ERR_NO_ERROR);} /* it worked */
 if (ccstatus == CCL)
  { return(SNMP_ERR_GEN_ERR); } /* insufficient capability */
 if (ccstatus == CCG)
  { return(SNMP_ERR_BAD_VALUE); } /* timestamp value trouble */
}










