Annotation of 43BSDReno/contrib/isode-beta/snmp/system.c, revision 1.1.1.1

1.1       root        1: /* system.c - MIB realization of the System group */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/snmp/RCS/system.c,v 7.3 90/05/14 15:44:29 mrose Exp $";
                      5: #endif
                      6: 
                      7: /* 
                      8:  * $Header: /f/osi/snmp/RCS/system.c,v 7.3 90/05/14 15:44:29 mrose Exp $
                      9:  *
                     10:  * Contributed by NYSERNet Inc.  This work was partially supported by the
                     11:  * U.S. Defense Advanced Research Projects Agency and the Rome Air Development
                     12:  * Center of the U.S. Air Force Systems Command under contract number
                     13:  * F30602-88-C-0016.
                     14:  *
                     15:  *
                     16:  * $Log:       system.c,v $
                     17:  * Revision 7.3  90/05/14  15:44:29  mrose
                     18:  * touch-up
                     19:  * 
                     20:  * Revision 7.2  90/05/14  13:28:18  mrose
                     21:  * system
                     22:  * 
                     23:  * Revision 7.1  90/05/13  16:18:32  mrose
                     24:  * views
                     25:  * 
                     26:  * Revision 7.0  89/11/23  22:23:33  mrose
                     27:  * Release 6.0
                     28:  * 
                     29:  */
                     30: 
                     31: /*
                     32:  *                               NOTICE
                     33:  *
                     34:  *    Acquisition, use, and distribution of this module and related
                     35:  *    materials are subject to the restrictions of a license agreement.
                     36:  *    Consult the Preface in the User's Manual for the full terms of
                     37:  *    this agreement.
                     38:  *
                     39:  */
                     40: 
                     41: 
                     42: #include <stdio.h>
                     43: #include "mib.h"
                     44: #include "tailor.h"
                     45: 
                     46: /*  */
                     47: 
                     48: static int  o_sysUpTime (oi, v, offset)
                     49: OI     oi;
                     50: register struct type_SNMP_VarBind *v;
                     51: int    offset;
                     52: {
                     53:     struct timeval boottime,
                     54:                   now;
                     55:     register OID    oid = oi -> oi_name;
                     56:     register OT            ot = oi -> oi_type;
                     57:     static   int lastq = -1;
                     58:     static   integer diff;
                     59: 
                     60:     switch (offset) {
                     61:        case type_SNMP_PDUs_get__request:
                     62:            if (oid -> oid_nelem != ot -> ot_name -> oid_nelem + 1
                     63:                    || oid -> oid_elements[oid -> oid_nelem - 1] != 0)
                     64:                return int_SNMP_error__status_noSuchName;
                     65:            break;
                     66: 
                     67:        case type_SNMP_PDUs_get__next__request:
                     68:            if (oid -> oid_nelem == ot -> ot_name -> oid_nelem) {
                     69:                OID     new;
                     70: 
                     71:                if ((new = oid_extend (oid, 1)) == NULLOID)
                     72:                    return int_SNMP_error__status_genErr;
                     73:                new -> oid_elements[new -> oid_nelem - 1] = 0;
                     74: 
                     75:                if (v -> name)
                     76:                    free_SNMP_ObjectName (v -> name);
                     77:                v -> name = new;
                     78:            }
                     79:            else
                     80:                return NOTOK;
                     81:            break;
                     82: 
                     83:        default:
                     84:            return int_SNMP_error__status_genErr;
                     85:     }
                     86: 
                     87:     if (quantum != lastq) {
                     88:        lastq = quantum;
                     89: 
                     90:        if (getkmem (nl + N_BOOTTIME, (caddr_t) &boottime, sizeof boottime)
                     91:                == NOTOK)
                     92:            return int_SNMP_error__status_genErr;
                     93:        if (gettimeofday (&now, (struct timezone *) 0) == NOTOK) {
                     94:            advise (LLOG_EXCEPTIONS, "failed", "gettimeofday");
                     95:            return int_SNMP_error__status_genErr;           
                     96:        }
                     97:        diff = (now.tv_sec - boottime.tv_sec) * 100
                     98:             + ((now.tv_usec - boottime.tv_usec) / 10000);
                     99:     }
                    100: 
                    101:     return o_number (oi, v, diff);
                    102: }
                    103: 
                    104: /*  */
                    105: 
                    106: static struct sys_pair {
                    107:     char    *s_name;
                    108:     char    *s_text;
                    109:     IFP             s_getfnx;
                    110: }    pairs[] = {
                    111:     "sysDescr",    sysDescr,   o_generic,
                    112:     "sysObjectID", sysObjectID, o_generic,
                    113:     "sysUpTime",   NULL,       o_sysUpTime,
                    114:     "sysContact",  NULL,       o_generic,
                    115: #define        SYS_NAME        4
                    116:     "sysName",     NULL,       o_generic,
                    117:     "sysLocation", NULL,       o_generic,
                    118:     "sysServices", "72",       o_generic,
                    119: 
                    120:     NULL
                    121: };
                    122: 
                    123: 
                    124: init_system () {
                    125:     char    buffer[BUFSIZ];
                    126:     register OT            ot;
                    127:     register struct sys_pair *sp;
                    128: 
                    129:     (void) gethostname (buffer, sizeof buffer);
                    130:     pairs[SYS_NAME].s_text = buffer;
                    131: 
                    132:     for (sp = pairs; sp -> s_name; sp++)
                    133:        if (ot = text2obj (sp -> s_name)) {
                    134:            ot -> ot_getfnx = sp -> s_getfnx;
                    135: 
                    136:            if (sp -> s_text)
                    137:                if (ot -> ot_syntax)
                    138:                    (void) (*ot -> ot_syntax -> os_parse) ((struct qbuf **)
                    139:                                                               &ot -> ot_info,
                    140:                                                           sp -> s_text);
                    141:                else
                    142:                    advise (LLOG_EXCEPTIONS, NULLCP, "%s: no syntax",
                    143:                            sp -> s_name);
                    144:        }
                    145:        else
                    146:            advise (LLOG_EXCEPTIONS, NULLCP, "%s: unknown object",
                    147:                    sp -> s_name);
                    148: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.