The function get_uptime is in snmplib/system.c
Its usage is in apps/snmptrap.c and agent/mibgroup/host/hr_system.c ....
and thanks for considering the mail
Regards
Suma
PS : the code:
/*
* Returns uptime in centiseconds(!).
*/
long
get_uptime(void)
{
#if !defined(solaris2) && !defined(linux) && !defined(cygwin)
struct timeval now;
long boottime_csecs, nowtime_csecs;
boottime_csecs = get_boottime();
if (boottime_csecs == 0)
return 0;
gettimeofday(&now, (struct timezone *) 0);
nowtime_csecs = (now.tv_sec * 100) + (now.tv_usec / 10000);
return (nowtime_csecs - boottime_csecs);
#endif
#ifdef solaris2
kstat_ctl_t *ksc = kstat_open();
kstat_t *ks;
kid_t kid;
kstat_named_t *named;
u_long lbolt = 0;
if (ksc) {
ks = kstat_lookup(ksc, "unix", -1, "system_misc");
if (ks) {
kid = kstat_read(ksc, ks, NULL);
if (kid != -1) {
named = kstat_data_lookup(ks, "lbolt");
if (named) {
#ifdef KSTAT_DATA_UINT32
lbolt = named->value.ui32;
#else
lbolt = named->value.ul;
#endif
}
}
}
kstat_close(ksc);
}
return lbolt;
#endif /* solaris2 */
#ifdef linux
FILE *in = fopen("/proc/uptime", "r");
long uptim = 0, a, b;
if (in) {
if (2 == fscanf(in, "%ld.%ld", &a, &b))
uptim = a * 100 + b;
fclose(in);
}
return uptim;
#endif /* linux */
#ifdef cygwin
return (0); /* not implemented */
#endif
}
On 1/18/06, Dave Shield <[EMAIL PROTECTED]> wrote:
> On Mon, 2006-01-16 at 15:01 +0530, Suma C wrote:
> > Can we use the /proc/uptime or even better the library function :
> > get_uptime .....
>
> A library function like that would certainly be an idea.
> But the big question is how portable it would be.
> Remember that the Net-SNMP suite runs on a wide variety
> of systems, not just Linux. So we prefer to use general
> solutions in preference to system-specific ones wherever
> possible.
>
> And checking my (fairly bog-standard) Fedora 4 system,
> I can't immediately spot any mention of this routine.
> There isn't a man page for "get_uptime", and it doesn't
> appear in any of the header files.
> This is not a good sign.
>
> Can you point me in the direction of some documentation?
>
> Dave
>
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders