#!/bin/sh # This is `snmp2.31' (part 31 of snmp2). # Do not concatenate these parts, unpack them in order with `/bin/sh'. # File `snmp2/agent/snmp_vars.c' is being continued... # touch -am 1231235999 $$.touch >/dev/null 2>&1 if test ! -f 1231235999 && test -f $$.touch; then shar_touch=touch else shar_touch=: echo echo 'WARNING: not restoring timestamps. Consider getting and' echo "installing GNU \`touch', distributed in GNU File Utilities..." echo fi rm -f 1231235999 $$.touch # if test ! -r _sharseq.tmp; then echo 'Please unpack part 1 first!' exit 1 fi shar_sequence=`cat _sharseq.tmp` if test "$shar_sequence" != 31; then echo "Please unpack part $shar_sequence next!" exit 1 fi if test ! -f _sharnew.tmp; then echo 'x - still skipping snmp2/agent/snmp_vars.c' else echo 'x - continuing file snmp2/agent/snmp_vars.c' sed 's/^X//' << 'SHAR_EOF' >> 'snmp2/agent/snmp_vars.c' && X return (u_char *)&long_return; X break; X X case IDLE_USERINTER: X *write_method = write_ssclrt_idle; X return (u_char *) &user_interval; X break; X X case IDLE_CALIB: X long_return = tell_calibrate (); X return (u_char *)&long_return; X break; X X case IDLE_HISTSIZE: X long_return = tell_hist_size (); X return (u_char *)&long_return; X break; X X case IDLE_HISTVALID: X long_return = valid_idle (); X return (u_char *)&long_return; X break; X X default: X ERROR("var_sscl_idle"); X } X return NULL; } X u_char * var_sscl_system(vp, name, length, exact, var_len, write_method) X register struct variable *vp; /* IN - pointer to variable entry that points here */ X register oid *name; /* IN/OUT - input name requested, output name found */ X register int *length; /* IN/OUT - length of input and output oid's */ X int exact; /* IN - TRUE if an exact match was requested. */ X int *var_len; /* OUT - length of variable or 0 if function returned. */ X int (**write_method)(); /* OUT - pointer to function to set variable, otherwise 0 */ { X extern int write_ssclrt_system (); X X oid newname[MAX_NAME_LEN]; X int result; X X bcopy((char *)vp->name, (char *)newname, (int)vp->namelen * sizeof(oid)); X newname[10] = 0; X result = compare(name, *length, newname, (int)vp->namelen + 1); X if ((exact && (result != 0)) || (!exact && (result >= 0))) X return NULL; X bcopy((char *)newname, (char *)name, ((int)vp->namelen + 1) * sizeof(oid)); X *length = vp->namelen + 1; X *write_method = 0; X *var_len = sizeof(long); /* default length */ X switch (vp->magic){ X case SYSTEM_REBOOT: X *write_method = write_ssclrt_system; X return (u_char *) &system_struct.reboot; X break; X X case SYSTEM_VME: X *write_method = write_ssclrt_system; X return (u_char *) &system_struct.reboot_vme; X break; X X case SYSTEM_ABORT: X *write_method = write_ssclrt_system; X return (u_char *) &system_struct.abort_reboot; X break; X X case SYSTEM_SILENT: X *write_method = write_ssclrt_system; X return (u_char *) &system_struct.silent; X break; X X case SYSTEM_SPURIOUS: X *write_method = write_ssclrt_system; X return (u_char *) &system_struct.spuriousInts; X break; X X default: X ERROR("var_sscl_system"); X } X return NULL; } #endif X u_char * var_demo(vp, name, length, exact, var_len, write_method) X register struct variable *vp; /* IN - pointer to variable entry that points here */ X register oid *name; /* IN/OUT - input name requested, output name found */ X register int *length; /* IN/OUT - length of input and output oid's */ X int exact; /* IN - TRUE if an exact match was requested. */ X int *var_len; /* OUT - length of variable or 0 if function returned. */ X int (**write_method)(); /* OUT - pointer to function to set variable, otherwise 0 */ { X oid newname[MAX_NAME_LEN]; X int result; X static u_char bitstring[64] = {0, 0x83, 0}; X int bitstringlength = 3; X static u_char nsap[128] = {0x14, 0x47, 0x00, 0x05, 0x80, 0xff, 0xff, 0x00, X 0x00, 0x00, 0x01, 0x23, 0x01, 0x23, 0x01, X 0x23, 0x45, 0x67, 0x89, 0xab, 0x01}; X int nsaplength = 21; X static struct counter64 counter; X X counter.high = 0xFA202E75; X counter.low = 0x4FE92915; X X bcopy((char *)vp->name, (char *)newname, (int)vp->namelen * sizeof(oid)); X newname[7] = 0; X result = compare(name, *length, newname, (int)vp->namelen + 1); X if ((exact && (result != 0)) || (!exact && (result >= 0))) X return NULL; X bcopy((char *)newname, (char *)name, ((int)vp->namelen + 1) * sizeof(oid)); X *length = vp->namelen + 1; X *write_method = 0; X *var_len = sizeof(long); /* default length */ X switch (vp->magic){ X case MTRBITSTRING: X *var_len = bitstringlength; X return (u_char *)bitstring; X case MTRNSAPADDRESS: X *var_len = nsaplength; X return (u_char *)nsap; X case MTRBIGNUMBER: X *var_len = sizeof(counter); X return (u_char *) &counter; X default: X ERROR(""); X } X return NULL; } X #include int writeVersion(action, var_val, var_val_type, var_val_len, statP, name, name_len) X int action; X u_char *var_val; X u_char var_val_type; X int var_val_len; X u_char *statP; X oid *name; X int name_len; { X int bigsize = 1000; X u_char buf[sizeof(version_descr)], *cp; X int count, size; X X if (var_val_type != STRING){ X printf("not string\n"); X return SNMP_ERR_WRONGTYPE; X } X if (var_val_len > sizeof(version_descr)-1){ X printf("bad length\n"); X return SNMP_ERR_WRONGLENGTH; X } X size = sizeof(buf); X asn_parse_string(var_val, &bigsize, &var_val_type, buf, &size); X for(cp = buf, count = 0; count < size; count++, cp++){ X if (!isprint(*cp)){ X printf("not print %x\n", *cp); X return SNMP_ERR_WRONGVALUE; X } X } X buf[size] = 0; X if (action == COMMIT){ X strcpy(version_descr, buf); X X } X return SNMP_ERR_NOERROR; } X #ifdef VXWORKS X #define SNMPD_PARAM_INDEX 9 int write_ssclrt_snmpd(action, var_val, var_val_type, var_val_len, statP, name, name_len) X int action; X u_char *var_val; X u_char var_val_type; X int var_val_len; X u_char *statP; X oid *name; X int name_len; { X int bigsize = 1000; X int count, size; X long set_val; X X if (var_val_type != INTEGER) X { X ERROR ("integer"); X return SNMP_ERR_WRONGTYPE; X } X X size = sizeof (set_val); X asn_parse_int(var_val, &bigsize, &var_val_type, &set_val, size); X X if (action == COMMIT) X { X /* X * modify requested value X */ X switch((char)name[SNMPD_PARAM_INDEX]) X { X case 3: X taskPrioritySet (taskIdSelf (), set_val); X break; X X default: X ERROR (""); X break; X } X } X return SNMP_ERR_NOERROR; X } X #define IDLE_PARAM_INDEX 9 int write_ssclrt_idle(action, var_val, var_val_type, var_val_len, statP, name, name_len) X int action; X u_char *var_val; X u_char var_val_type; X int var_val_len; X u_char *statP; X oid *name; X int name_len; { X int bigsize = 1000; X int count, size; X long set_val; X X if (var_val_type != INTEGER) X { X ERROR ("integer"); X return SNMP_ERR_WRONGTYPE; X } X X size = sizeof (set_val); X asn_parse_int(var_val, &bigsize, &var_val_type, &set_val, size); X X if (action == COMMIT) X { X /* X * modify requested value X */ X switch((char)name[IDLE_PARAM_INDEX]) X { X case 5: /* user interval */ X user_interval = set_val; X break; X X default: X ERROR (""); X break; X } X } X return SNMP_ERR_NOERROR; X } X #define SYSTEM_PARAM_INDEX 9 int write_ssclrt_system(action, var_val, var_val_type, var_val_len, statP, name, name_len) X int action; X u_char *var_val; X u_char var_val_type; X int var_val_len; X u_char *statP; X oid *name; X int name_len; { X int bigsize = 1000; X int count, size; X long set_val; X X if (var_val_type != INTEGER) X { X ERROR ("integer"); X return SNMP_ERR_WRONGTYPE; X } X X size = sizeof (set_val); X asn_parse_int(var_val, &bigsize, &var_val_type, &set_val, size); X X if (action == COMMIT) X { X /* X * modify requested value X */ X switch((char)name[SYSTEM_PARAM_INDEX]) X { X case 1: /* reboot */ X system_struct.reboot = set_val; X reboot_task_create (); X break; X X case 2: /* reboot VME */ X system_struct.reboot_vme = set_val; X reboot_vme_task_create (); X break; X X case 3: /* abort reboot */ X system_struct.abort_reboot = set_val; X reboot_task_delete (); X system_struct.reboot = set_val; X system_struct.reboot_vme = set_val; X break; X X case 4: /* silent */ X system_struct.silent = set_val; X break; X X case 5: /* spurious */ X system_struct.spuriousInts = set_val; X break; X X default: X ERROR (""); X break; X } X } X return SNMP_ERR_NOERROR; X } X #define BOOT_PARAM_INDEX 11 int write_vxboot(action, var_val, var_val_type, var_val_len, statP, name, name_len) X int action; X u_char *var_val; X u_char var_val_type; X int var_val_len; X u_char *statP; X oid *name; X int name_len; { X int bigsize = 1000; X u_char buf[sizeof(version_descr)], *cp; X int count, size; X long set_val; X X /* X * this really should be done using the four step process X * described above with a switch for RESERVE1, RESERVE2, COMMIT and FREE X * requests. The trouble is that to handle these cases, memory will need X * to be allocated and managed to keep track of the values from the X * incoming set PDU. X */ X X /* checks type and value */ X switch ((char) name [BOOT_PARAM_INDEX]) X { X case 1: /* boot Device */ X case 2: /* hostName */ X case 3: /* targetName */ X case 4: /* ethernet Address */ X case 5: /* backplane Address */ X case 6: /* host Address */ X case 7: /* gateway Address */ X case 8: /* bootfile */ X case 9: /* startup script */ X case 10: /* user name */ X case 11: /* password */ X case 12: /* other */ X if (var_val_type != STRING) X { X printf("not string\n"); X return SNMP_ERR_WRONGTYPE; X } X if (var_val_len > vx_boot_lengths [name [BOOT_PARAM_INDEX]]-1) X { X printf("bad length\n"); X return SNMP_ERR_WRONGLENGTH; X } X size = sizeof(buf); X asn_parse_string(var_val, &bigsize, &var_val_type, buf, &size); X for(cp = buf, count = 0; count < size; count++, cp++) X { X if (!isprint(*cp)) X { X printf("not print %x\n", *cp); X return SNMP_ERR_WRONGVALUE; X } X } X X buf[size] = 0; X break; X X case 13: /* processor number */ X case 14: /* configuration flags */ X if (var_val_type != INTEGER) X { X ERROR ("integer"); X return SNMP_ERR_WRONGTYPE; X } X X size = sizeof (set_val); X asn_parse_int(var_val, &bigsize, &var_val_type, &set_val, size); X X printf ("set Value = %d\n", set_val); X break; X X default: X break; X } X X if (action == COMMIT) X { X /* X * modify requested value X */ X switch((char)name[BOOT_PARAM_INDEX]) X { X case 1: /* boot Device */ X strcpy(vx_params.bootDev, buf); X break; X X case 2: /* hostName */ X strcpy(vx_params.hostName, buf); X break; X X case 3: /* targetName */ X strcpy(vx_params.targetName, buf); X break; X X case 4: /* ethernet Address */ X strcpy(vx_params.ead, buf); X break; X X case 5: /* backplane Address */ X strcpy(vx_params.bad, buf); X break; X X case 6: /* host Address */ X strcpy(vx_params.had, buf); X break; X X case 7: /* gateway Address */ X strcpy(vx_params.gad, buf); X break; X X case 8: /* bootfile */ X strcpy(vx_params.bootFile, buf); X break; X X case 9: /* startup script */ X strcpy(vx_params.startupScript, buf); X break; X X case 10: /* user name */ X strcpy(vx_params.usr, buf); X break; X X case 11: /* password */ X strcpy(vx_params.passwd, buf); X break; X X case 12: /* other */ X strcpy(vx_params.other, buf); X break; X X case 13: /* processor number */ X vx_params.procNum = set_val; X printf ("set processor number: %d\n", vx_params.procNum); X break; X X case 14: /* configuration flags */ X vx_params.flags = set_val; X printf ("set configuration flags: %d\n", vx_params.flags); X break; X X default: X ERROR ("write_vxboot"); X break; X } X X /* X * put back into NVRAM X */ X bootStructToString (vx_boot_line, &vx_params); X sysNvRamSet (vx_boot_line, strlen (vx_boot_line) + 1, 0); X } X X return SNMP_ERR_NOERROR; X } X #endif X int writeSystem(action, var_val, var_val_type, var_val_len, statP, name, name_len) X int action; X u_char *var_val; X u_char var_val_type; X int var_val_len; X u_char *statP; X oid *name; X int name_len; { X int bigsize = 1000; X u_char buf[sizeof(version_descr)], *cp; X int count, size; X X if (var_val_type != STRING){ X printf("not string\n"); X return SNMP_ERR_WRONGTYPE; X } X if (var_val_len > sizeof(version_descr)-1){ X printf("bad length\n"); X return SNMP_ERR_WRONGLENGTH; X } X size = sizeof(buf); X asn_parse_string(var_val, &bigsize, &var_val_type, buf, &size); X for(cp = buf, count = 0; count < size; count++, cp++){ X if (!isprint(*cp)){ X printf("not print %x\n", *cp); X return SNMP_ERR_WRONGVALUE; X } X } X buf[size] = 0; X if (action == COMMIT){ X switch((char)name[7]){ X case 1: X strcpy(version_descr, buf); X break; X case 4: X strcpy(sysContact, buf); X break; X case 5: X strcpy(sysName, buf); X break; X case 6: X strcpy(sysLocation, buf); X break; X } X } X return SNMP_ERR_NOERROR; } X X u_char * var_ifEntry(vp, name, length, exact, var_len, write_method) X register struct variable *vp; /* IN - pointer to variable entry that points here */ X register oid *name; /* IN/OUT - input name requested, output name found */ X register int *length; /* IN/OUT - length of input and output oid's */ X int exact; /* IN - TRUE if an exact match was requested. */ X int *var_len; /* OUT - length of variable or 0 if function returned. */ X int (**write_method)(); /* OUT - pointer to function to set variable, otherwise 0 */ { X oid newname[MAX_NAME_LEN]; X register int interface; X int result, count; X static struct ifnet ifnet; #ifndef sunV3 X static struct in_ifaddr in_ifaddr; #endif sunV3 X static char Name[16]; X register char *cp; X X bcopy((char *)vp->name, (char *)newname, (int)vp->namelen * sizeof(oid)); X /* find "next" interface */ X count = Interface_Scan_Get_Count(); X for(interface = 1; interface <= count; interface++){ X newname[10] = (oid)interface; X result = compare(name, *length, newname, (int)vp->namelen + 1); X if ((exact && (result == 0)) || (!exact && (result < 0))) X break; X } X if (interface > count) X return NULL; X X bcopy((char *)newname, (char *)name, ((int)vp->namelen + 1) * sizeof(oid)); X *length = vp->namelen + 1; X *write_method = 0; X *var_len = sizeof(long); X #ifdef sunV3 X Interface_Scan_By_Index(interface, Name, &ifnet); #else X Interface_Scan_By_Index(interface, Name, &ifnet, &in_ifaddr); #endif X switch (vp->magic){ X case IFINDEX: X long_return = interface; X return (u_char *) &long_return; X case IFDESCR: #ifdef VXWORKS #undef USE_NAME_AS_DESCRIPTION #endif #ifdef USE_NAME_AS_DESCRIPTION X cp = Name; #else USE_NAME_AS_DESCRIPTION X cp = Lookup_Device_Annotation(Name, "snmp-descr"); X if (!cp) X cp = Lookup_Device_Annotation(Name, 0); X if (!cp) cp = Name; #endif USE_NAME_AS_DESCRIPTION X *var_len = strlen(cp); X return (u_char *)cp; X case IFTYPE: #ifdef VXWORKS X cp = Lookup_Device_Annotation(Name, "snmp-type"); X if (cp) long_return = atoi(cp); X else #endif X long_return = 1; /* OTHER */ X return (u_char *) &long_return; X case IFMTU: { X long_return = (long) ifnet.if_mtu; X return (u_char *) &long_return; X } X case IFSPEED: #ifdef VXWORKS X cp = Lookup_Device_Annotation(Name, "snmp-speed"); X if (cp) long_return = atoi(cp); X else #endif X (u_long)long_return = 1; /* OTHER */ X return (u_char *) &long_return; X case IFPHYSADDRESS: #ifdef VXWORKS X if (Lookup_Device_Annotation(Name, "ethernet-device")) { X Interface_Get_Ether_By_Index(interface, return_buf); X *var_len = 6; X return(u_char *) return_buf; X } else { X long_return = 0; X return (u_char *) long_return; X } #endif X Interface_Get_Ether_By_Index(interface, return_buf); X *var_len = 6; X return(u_char *) return_buf; X case IFADMINSTATUS: X long_return = ifnet.if_flags & IFF_RUNNING ? 1 : 2; X return (u_char *) &long_return; X case IFOPERSTATUS: X long_return = ifnet.if_flags & IFF_UP ? 1 : 2; X return (u_char *) &long_return; X case IFLASTCHANGE: X long_return = 0; /* XXX */ X return (u_char *) &long_return; X case IFINOCTETS: X (u_long)long_return = ifnet.if_ipackets * 308; /* XXX */ X return (u_char *) &long_return; X case IFINUCASTPKTS: X (u_long)long_return = ifnet.if_ipackets; X return (u_char *) &long_return; X case IFINNUCASTPKTS: X (u_long)long_return = 0; /* XXX */ X return (u_char *) &long_return; X case IFINDISCARDS: X (u_long)long_return = 0; /* XXX */ X return (u_char *) &long_return; X case IFINERRORS: X return (u_char *) &ifnet.if_ierrors; X case IFINUNKNOWNPROTOS: X (u_long)long_return = 0; /* XXX */ X return (u_char *) &long_return; X case IFOUTOCTETS: X (u_long)long_return = ifnet.if_opackets * 308; /* XXX */ X return (u_char *) &long_return; X case IFOUTUCASTPKTS: X (u_long)long_return = ifnet.if_opackets; X return (u_char *) &long_return; X case IFOUTNUCASTPKTS: X (u_long)long_return = 0; /* XXX */ X return (u_char *) &long_return; X case IFOUTDISCARDS: X return (u_char *) &ifnet.if_snd.ifq_drops; X case IFOUTERRORS: X return (u_char *) &ifnet.if_oerrors; X case IFOUTQLEN: X return (u_char *) &ifnet.if_snd.ifq_len; X default: X ERROR(""); X } X return NULL; } X /* X * Read the ARP table X */ X u_char * var_atEntry(vp, name, length, exact, var_len, write_method) X register struct variable *vp; /* IN - pointer to variable entry that points here */ X register oid *name; /* IN/OUT - input name requested, output name found */ X register int *length; /* IN/OUT - length of input and output oid's */ X int exact; /* IN - TRUE if an exact match was requested. */ X int *var_len; /* OUT - length of variable or 0 if function returned. */ X int (**write_method)(); /* OUT - pointer to function to set variable, otherwise 0 */ { X /* X * object identifier is of form: X * 1.3.6.1.2.1.3.1.1.1.interface.1.A.B.C.D, where A.B.C.D is IP address. X * Interface is at offset 10, X * IPADDR starts at offset 12. X */ X u_char *cp; X oid *op; X oid lowest[16]; X oid current[16]; X static char PhysAddr[6], LowPhysAddr[6]; X u_long Addr, LowAddr; X X /* fill in object part of name for current (less sizeof instance part) */ X X bcopy((char *)vp->name, (char *)current, (int)vp->namelen * sizeof(oid)); X X LowAddr = -1; /* Don't have one yet */ X ARP_Scan_Init(); X for (;;) { X if (ARP_Scan_Next(&Addr, PhysAddr) == 0) break; X current[10] = 1; /* IfIndex == 1 (ethernet???) XXX */ X current[11] = 1; X cp = (u_char *)&Addr; X op = current + 12; X *op++ = *cp++; X *op++ = *cp++; X *op++ = *cp++; X *op++ = *cp++; X X if (exact){ X if (compare(current, 16, name, *length) == 0){ X bcopy((char *)current, (char *)lowest, 16 * sizeof(oid)); X LowAddr = Addr; X bcopy(PhysAddr, LowPhysAddr, sizeof(PhysAddr)); X break; /* no need to search further */ X } X } else { X if ((compare(current, 16, name, *length) > 0) && X ((LowAddr == -1) || (compare(current, 16, lowest, 16) < 0))){ X /* X * if new one is greater than input and closer to input than X * previous lowest, save this one as the "next" one. X */ X bcopy((char *)current, (char *)lowest, 16 * sizeof(oid)); X LowAddr = Addr; X bcopy(PhysAddr, LowPhysAddr, sizeof(PhysAddr)); X } X } X } X if (LowAddr == -1) return(NULL); X X bcopy((char *)lowest, (char *)name, 16 * sizeof(oid)); X *length = 16; X *write_method = 0; X switch(vp->magic){ X case ATIFINDEX: X *var_len = sizeof long_return; X long_return = 1; /* XXX */ X return (u_char *)&long_return; X case ATPHYSADDRESS: X *var_len = sizeof(LowPhysAddr); X return (u_char *)LowPhysAddr; X case ATNETADDRESS: X *var_len = sizeof long_return; X long_return = LowAddr; X return (u_char *)&long_return; X default: X ERROR(""); X } X return NULL; } X u_char * var_ip(vp, name, length, exact, var_len, write_method) X register struct variable *vp; /* IN - pointer to variable entry that points here */ X oid *name; /* IN/OUT - input name requested, output name found */ X int *length; /* IN/OUT - length of input and output oid's */ X int exact; /* IN - TRUE if an exact match was requested. */ X int *var_len; /* OUT - length of variable or 0 if function returned. */ X int (**write_method)(); /* OUT - pointer to function to set variable, otherwise 0 */ { X static struct ipstat ipstat; X oid newname[MAX_NAME_LEN]; X int result; X X bcopy((char *)vp->name, (char *)newname, (int)vp->namelen * sizeof(oid)); X newname[8] = 0; X result = compare(name, *length, newname, (int)vp->namelen + 1); X if ((exact && (result != 0)) || (!exact && (result >= 0))) X return NULL; X bcopy((char *)newname, (char *)name, ((int)vp->namelen + 1) * sizeof(oid)); X *length = vp->namelen + 1; X X *write_method = 0; X *var_len = sizeof(long); /* default length */ X /* X * Get the IP statistics from the kernel... X */ X X KNLookup(N_IPSTAT, (char *)&ipstat, sizeof (ipstat)); X X switch (vp->magic){ X case IPFORWARDING: X #ifdef VXWORKS X /* ??? */ X long_return = 0; #else X #ifndef sparc X KNLookup( N_IPFORWARDING, (char *) &i, sizeof(i)); X fflush(stderr); X if (i) { X long_return = 1; /* GATEWAY */ X } else { X long_return = 2; /* HOST */ X } #else X long_return = 0; #endif #endif X X return (u_char *) &long_return; X case IPDEFAULTTTL: X /* X * Allow for a kernel w/o TCP. X */ X if (nl[N_TCP_TTL].n_value) { X KNLookup( N_TCP_TTL, (char *) &long_return, sizeof(long_return)); X } else long_return = 60; /* XXX */ X return (u_char *) &long_return; X case IPINRECEIVES: X return (u_char *) &ipstat.ips_total; X case IPINHDRERRORS: X long_return = ipstat.ips_badsum + ipstat.ips_tooshort + X ipstat.ips_toosmall + ipstat.ips_badhlen + X ipstat.ips_badlen; X return (u_char *) &long_return; X case IPINADDRERRORS: X return (u_char *) &ipstat.ips_cantforward; X X case IPFORWDATAGRAMS: X return (u_char *) &ipstat.ips_forward; X X case IPINUNKNOWNPROTOS: X long_return = 0; X return (u_char *) &long_return; X case IPINDISCARDS: X long_return = 0; X return (u_char *) &long_return; X case IPINDELIVERS: X X long_return = ipstat.ips_total - X (ipstat.ips_badsum + ipstat.ips_tooshort + X ipstat.ips_toosmall + ipstat.ips_badhlen + X ipstat.ips_badlen); X return (u_char *) &long_return; X X case IPOUTREQUESTS: X long_return = 0; X return (u_char *) &long_return; X case IPOUTDISCARDS: X long_return = 0; X return (u_char *) &long_return; X case IPOUTNOROUTES: X return (u_char *) &ipstat.ips_cantforward; X X case IPREASMTIMEOUT: X long_return = IPFRAGTTL; X return (u_char *) &long_return; X case IPREASMREQDS: X return (u_char *) &ipstat.ips_fragments; X X case IPREASMOKS: X return (u_char *) &ipstat.ips_fragments; X X case IPREASMFAILS: X long_return = ipstat.ips_fragdropped + ipstat.ips_fragtimeout; X return (u_char *) &long_return; X X case IPFRAGOKS: X long_return = 0; X return (u_char *) &long_return; X case IPFRAGFAILS: X long_return = 0; X return (u_char *) &long_return; X case IPFRAGCREATES: X long_return = 0; X return (u_char *) &long_return; X default: X ERROR(""); X } X return NULL; } X X X u_char * var_ipAddrEntry(vp, name, length, exact, var_len, write_method) X register struct variable *vp; /* IN - pointer to variable entry that points here */ X register oid *name; /* IN/OUT - input name requested, output name found */ X register int *length; /* IN/OUT - length of input and output oid's */ X int exact; /* IN - TRUE if an exact match was requested. */ X int *var_len; /* OUT - length of variable or 0 if function returned. */ X int (**write_method)(); /* OUT - pointer to function to set variable, otherwise 0 */ { X /* X * object identifier is of form: X * 1.3.6.1.2.1.4.20.1.?.A.B.C.D, where A.B.C.D is IP address. X * IPADDR starts at offset 10. X */ X oid lowest[14]; X oid current[14], *op; X u_char *cp; X int interface, lowinterface=0; X static struct ifnet ifnet, lowin_ifnet; #ifndef sunV3 X static struct in_ifaddr in_ifaddr, lowin_ifaddr; #endif sunV3 X X /* fill in object part of name for current (less sizeof instance part) */ X X bcopy((char *)vp->name, (char *)current, (int)vp->namelen * sizeof(oid)); X X Interface_Scan_Init(); X for (;;) { X #ifdef sunV3 X if (Interface_Scan_Next(&interface, (char *)0, &ifnet) == 0) break; X cp = (u_char *)&(((struct sockaddr_in *) &(ifnet.if_addr))->sin_addr.s_addr); #else X if (Interface_Scan_Next(&interface, (char *)0, &ifnet, &in_ifaddr) == 0) break; X cp = (u_char *)&(((struct sockaddr_in *) &(in_ifaddr.ia_addr))->sin_addr.s_addr); #endif X X op = current + 10; X *op++ = *cp++; X *op++ = *cp++; X *op++ = *cp++; X *op++ = *cp++; X if (exact){ X if (compare(current, 14, name, *length) == 0){ X bcopy((char *)current, (char *)lowest, 14 * sizeof(oid)); X lowinterface = interface; #ifdef sunV3 X lowin_ifnet = ifnet; #else X lowin_ifaddr = in_ifaddr; #endif X break; /* no need to search further */ X } X } else { X if ((compare(current, 14, name, *length) > 0) && X (!lowinterface || (compare(current, 14, lowest, 14) < 0))){ X /* X * if new one is greater than input and closer to input than X * previous lowest, save this one as the "next" one. X */ X lowinterface = interface; #ifdef sunV3 X lowin_ifnet = ifnet; #else X lowin_ifaddr = in_ifaddr; #endif X bcopy((char *)current, (char *)lowest, 14 * sizeof(oid)); X } X } X } X X if (!lowinterface) return(NULL); X bcopy((char *)lowest, (char *)name, 14 * sizeof(oid)); X *length = 14; X *write_method = 0; X *var_len = sizeof(long_return); X switch(vp->magic){ X case IPADADDR: #ifdef sunV3 X return(u_char *) &((struct sockaddr_in *) &lowin_ifnet.if_addr)->sin_addr.s_addr; #else X return(u_char *) &((struct sockaddr_in *) &lowin_ifaddr.ia_addr)->sin_addr.s_addr; #endif X case IPADIFINDEX: X long_return = lowinterface; X return(u_char *) &long_return; X case IPADNETMASK: #ifndef sunV3 X long_return = ntohl(lowin_ifaddr.ia_subnetmask); #endif X return(u_char *) &long_return; X case IPADBCASTADDR: X #ifdef sunV3 X long_return = ntohl(((struct sockaddr_in *) &lowin_ifnet.ifu_broadaddr)->sin_addr.s_addr) & 1; #else X long_return = ntohl(((struct sockaddr_in *) &lowin_ifaddr.ia_addr)->sin_addr.s_addr) & 1; #endif X return(u_char *) &long_return; X default: X ERROR(""); X } X return NULL; } X X u_char * var_icmp(vp, name, length, exact, var_len, write_method) X register struct variable *vp; /* IN - pointer to variable entry that points here */ X oid *name; /* IN/OUT - input name requested, output name found */ X int *length; /* IN/OUT - length of input and output oid's */ X int exact; /* IN - TRUE if an exact match was requested. */ X int *var_len; /* OUT - length of variable or 0 if function returned. */ X int (**write_method)(); /* OUT - pointer to function to set variable, otherwise 0 */ { X register int i; X static struct icmpstat icmpstat; X oid newname[MAX_NAME_LEN]; X int result; X X bcopy((char *)vp->name, (char *)newname, (int)vp->namelen * sizeof(oid)); X newname[8] = 0; X result = compare(name, *length, newname, (int)vp->namelen + 1); X if ((exact && (result != 0)) || (!exact && (result >= 0))) X return NULL; X bcopy((char *)newname, (char *)name, ((int)vp->namelen + 1) * sizeof(oid)); X *length = vp->namelen + 1; X X *write_method = 0; X *var_len = sizeof(long); /* all following variables are sizeof long */ X X /* X * Get the UDP statistics from the kernel... X */ X X KNLookup( N_ICMPSTAT, (char *)&icmpstat, sizeof (icmpstat)); X X switch (vp->magic){ X case ICMPINMSGS: X long_return = icmpstat.icps_badcode + icmpstat.icps_tooshort + X icmpstat.icps_checksum + icmpstat.icps_badlen; X for (i=0; i <= ICMP_MAXTYPE; i++) X long_return += icmpstat.icps_inhist[i]; X return (u_char *)&long_return; X case ICMPINERRORS: X long_return = icmpstat.icps_badcode + icmpstat.icps_tooshort + X icmpstat.icps_checksum + icmpstat.icps_badlen; X return (u_char *)&long_return; X case ICMPINDESTUNREACHS: X return (u_char *) &icmpstat.icps_inhist[ICMP_UNREACH]; X case ICMPINTIMEEXCDS: X return (u_char *) &icmpstat.icps_inhist[ICMP_TIMXCEED]; X case ICMPINPARMPROBS: X return (u_char *) &icmpstat.icps_inhist[ICMP_PARAMPROB]; X case ICMPINSRCQUENCHS: X return (u_char *) &icmpstat.icps_inhist[ICMP_SOURCEQUENCH]; X case ICMPINREDIRECTS: X return (u_char *) &icmpstat.icps_inhist[ICMP_REDIRECT]; X case ICMPINECHOS: X return (u_char *) &icmpstat.icps_inhist[ICMP_ECHO]; X case ICMPINECHOREPS: X return (u_char *) &icmpstat.icps_inhist[ICMP_ECHOREPLY]; X case ICMPINTIMESTAMPS: X return (u_char *) &icmpstat.icps_inhist[ICMP_TSTAMP]; X case ICMPINTIMESTAMPREPS: X return (u_char *) &icmpstat.icps_inhist[ICMP_TSTAMPREPLY]; X case ICMPINADDRMASKS: X return (u_char *) &icmpstat.icps_inhist[ICMP_MASKREQ]; X case ICMPINADDRMASKREPS: X return (u_char *) &icmpstat.icps_inhist[ICMP_MASKREPLY]; X case ICMPOUTMSGS: X long_return = icmpstat.icps_oldshort + icmpstat.icps_oldicmp; X for (i=0; i <= ICMP_MAXTYPE; i++) X long_return += icmpstat.icps_outhist[i]; X return (u_char *)&long_return; X case ICMPOUTERRORS: X long_return = icmpstat.icps_oldshort + icmpstat.icps_oldicmp; X return (u_char *)&long_return; X case ICMPOUTDESTUNREACHS: X return (u_char *) &icmpstat.icps_outhist[ICMP_UNREACH]; X case ICMPOUTTIMEEXCDS: X return (u_char *) &icmpstat.icps_outhist[ICMP_TIMXCEED]; X case ICMPOUTPARMPROBS: X return (u_char *) &icmpstat.icps_outhist[ICMP_PARAMPROB]; X case ICMPOUTSRCQUENCHS: X return (u_char *) &icmpstat.icps_outhist[ICMP_SOURCEQUENCH]; X case ICMPOUTREDIRECTS: X return (u_char *) &icmpstat.icps_outhist[ICMP_REDIRECT]; X case ICMPOUTECHOS: X return (u_char *) &icmpstat.icps_outhist[ICMP_ECHO]; X case ICMPOUTECHOREPS: X return (u_char *) &icmpstat.icps_outhist[ICMP_ECHOREPLY]; X case ICMPOUTTIMESTAMPS: X return (u_char *) &icmpstat.icps_outhist[ICMP_TSTAMP]; X case ICMPOUTTIMESTAMPREPS: X return (u_char *) &icmpstat.icps_outhist[ICMP_TSTAMPREPLY]; X case ICMPOUTADDRMASKS: X return (u_char *) &icmpstat.icps_outhist[ICMP_MASKREQ]; X case ICMPOUTADDRMASKREPS: X return (u_char *) &icmpstat.icps_outhist[ICMP_MASKREPLY]; X default: X ERROR(""); X } X return NULL; } X X u_char * var_udp(vp, name, length, exact, var_len, write_method) X register struct variable *vp; /* IN - pointer to variable entry that points here */ X oid *name; /* IN/OUT - input name requested, output name found */ X int *length; /* IN/OUT - length of input and output oid's */ X int exact; /* IN - TRUE if an exact match was requested. */ X int *var_len; /* OUT - length of variable or 0 if function returned. */ X int (**write_method)(); /* OUT - pointer to function to set variable, otherwise 0 */ { X static struct udpstat udpstat; X oid newname[MAX_NAME_LEN]; X int result; X X bcopy((char *)vp->name, (char *)newname, (int)vp->namelen * sizeof(oid)); X newname[8] = 0; X result = compare(name, *length, newname, (int)vp->namelen + 1); X if ((exact && (result != 0)) || (!exact && (result >= 0))) X return NULL; X bcopy((char *)newname, (char *)name, ((int)vp->namelen + 1) * sizeof(oid)); X *length = vp->namelen + 1; X X *write_method = 0; X *var_len = sizeof(long); /* default length */ X /* X * Get the IP statistics from the kernel... X */ X X KNLookup( N_UDPSTAT, (char *)&udpstat, sizeof (udpstat)); X X switch (vp->magic){ X case UDPINDATAGRAMS: X case UDPNOPORTS: X case UDPOUTDATAGRAMS: X long_return = 0; X return (u_char *) &long_return; X case UDPINERRORS: X long_return = udpstat.udps_hdrops + udpstat.udps_badsum + X udpstat.udps_badlen; X return (u_char *) &long_return; X default: X ERROR(""); X } X return NULL; } X u_char * var_tcp(vp, name, length, exact, var_len, write_method) X register struct variable *vp; /* IN - pointer to variable entry that points here */ X oid *name; /* IN/OUT - input name requested, output name found */ X int *length; /* IN/OUT - length of input and output oid's */ X int exact; /* IN - TRUE if an exact match was requested. */ X int *var_len; /* OUT - length of variable or 0 if function returned. */ X int (**write_method)(); /* OUT - pointer to function to set variable, otherwise 0 */ { X int i; X static struct tcpstat tcpstat; X oid newname[MAX_NAME_LEN], lowest[MAX_NAME_LEN], *op; X u_char *cp; X int State, LowState; X static struct inpcb inpcb, Lowinpcb; X int result; X X /* X * Allow for a kernel w/o TCP X */ X X if (nl[N_TCPSTAT].n_value == 0) return(NULL); X X if (vp->magic < TCPCONNSTATE) { X X bcopy((char *)vp->name, (char *)newname, X (int)vp->namelen * sizeof(oid)); X newname[8] = 0; X result = compare(name, *length, newname, (int)vp->namelen + 1); X if ((exact && (result != 0)) || (!exact && (result >= 0))) X return NULL; X bcopy((char *)newname, (char *)name, X ((int)vp->namelen + 1) * sizeof(oid)); X *length = vp->namelen + 1; X X *write_method = 0; X *var_len = sizeof(long); /* default length */ X /* X * Get the TCP statistics from the kernel... X */ X X KNLookup( N_TCPSTAT, (char *)&tcpstat, sizeof (tcpstat)); X X switch (vp->magic){ X case TCPRTOALGORITHM: X long_return = 4; /* Van Jacobsen's algorithm */ /* XXX */ X return (u_char *) &long_return; X case TCPRTOMIN: X long_return = TCPTV_MIN / PR_SLOWHZ * 1000; X return (u_char *) &long_return; X case TCPRTOMAX: X long_return = TCPTV_REXMTMAX / PR_SLOWHZ * 1000; X X return (u_char *) &long_return; X case TCPMAXCONN: X long_return = -1; X return (u_char *) &long_return; X case TCPACTIVEOPENS: X X return (u_char *) &tcpstat.tcps_connattempt; X X case TCPPASSIVEOPENS: X X return (u_char *) &tcpstat.tcps_accepts; X X case TCPATTEMPTFAILS: X return (u_char *) &tcpstat.tcps_conndrops; X X case TCPESTABRESETS: X return (u_char *) &tcpstat.tcps_drops; X X case TCPCURRESTAB: X long_return = TCP_Count_Connections(); X return (u_char *) &long_return; X case TCPINSEGS: X return (u_char *) &tcpstat.tcps_rcvtotal; X X case TCPOUTSEGS: X return (u_char *) &tcpstat.tcps_sndtotal; X case TCPRETRANSSEGS: X return (u_char *) &tcpstat.tcps_sndrexmitpack; X default: X ERROR(""); X } X } else { /* Info about a particular connection */ X bcopy((char *)vp->name, (char *)newname, (int)vp->namelen * sizeof(oid)); X /* find "next" connection */ Again: LowState = -1; /* Don't have one yet */ X TCP_Scan_Init(); X for (;;) { X if ((i = TCP_Scan_Next(&State, &inpcb)) < 0) goto Again; X if (i == 0) break; /* Done */ X cp = (u_char *)&inpcb.inp_laddr.s_addr; X op = newname + 10; X *op++ = *cp++; X *op++ = *cp++; X *op++ = *cp++; X *op++ = *cp++; X X newname[14] = ntohs(inpcb.inp_lport); X X cp = (u_char *)&inpcb.inp_faddr.s_addr; X op = newname + 15; X *op++ = *cp++; X *op++ = *cp++; X *op++ = *cp++; X *op++ = *cp++; X X newname[19] = ntohs(inpcb.inp_fport); X X if (exact){ X if (compare(newname, 20, name, *length) == 0){ X bcopy((char *)newname, (char *)lowest, 20 * sizeof(oid)); X LowState = State; X Lowinpcb = inpcb; X break; /* no need to search further */ X } X } else { X if ((compare(newname, 20, name, *length) > 0) && X ((LowState < 0) || (compare(newname, 20, lowest, 20) < 0))){ X /* X * if new one is greater than input and closer to input than X * previous lowest, save this one as the "next" one. X */ X bcopy((char *)newname, (char *)lowest, 20 * sizeof(oid)); X LowState = State; X Lowinpcb = inpcb; X } X } X } X if (LowState < 0) return(NULL); X bcopy((char *)lowest, (char *)name, ((int)vp->namelen + 10) * sizeof(oid)); X *length = vp->namelen + 10; X *write_method = 0; X *var_len = sizeof(long); X switch (vp->magic) { X case TCPCONNSTATE: { X static int StateMap[]={1, 2, 3, 4, 5, 8, 6, 10, 9, 7, 11}; X return (u_char *) &StateMap[LowState]; X } X case TCPCONNLOCALADDRESS: X return (u_char *) &Lowinpcb.inp_laddr.s_addr; X case TCPCONNLOCALPORT: X long_return = ntohs(Lowinpcb.inp_lport); X return (u_char *) &long_return; X case TCPCONNREMADDRESS: X return (u_char *) &Lowinpcb.inp_faddr.s_addr; X case TCPCONNREMPORT: X long_return = ntohs(Lowinpcb.inp_fport); X return (u_char *) &long_return; X } X } X return NULL; } X /* X * Print INTERNET connections X */ X static int TCP_Count_Connections() { X int Established; X struct inpcb cb; X register struct inpcb *prev, *next; X struct inpcb inpcb; X struct tcpcb tcpcb; X Again: /* X * Prepare to scan the control blocks X */ X Established = 0; X X KNLookup( N_TCB, (char *)&cb, sizeof(struct inpcb)); X inpcb = cb; X prev = (struct inpcb *) nl[N_TCB].n_value; X /* X * Scan the control blocks X */ X while (inpcb.inp_next != (struct inpcb *) nl[N_TCB].n_value) { X next = inpcb.inp_next; X X klookup( (int)next, (char *)&inpcb, sizeof (inpcb)); X if (inpcb.inp_prev != prev) { /* ??? */ X sleep(1); X goto Again; X } X if (inet_lnaof(inpcb.inp_laddr) == INADDR_ANY) { X prev = next; X continue; X } X klookup( (int)inpcb.inp_ppcb, (char *)&tcpcb, sizeof (tcpcb)); X X if ((tcpcb.t_state == TCPS_ESTABLISHED) || X (tcpcb.t_state == TCPS_CLOSE_WAIT)) X Established++; X prev = next; X } X return(Established); } X X static struct inpcb inpcb, *prev; X static TCP_Scan_Init() { X KNLookup( N_TCB, (char *)&inpcb, sizeof(inpcb)); X prev = (struct inpcb *) nl[N_TCB].n_value; } X static int TCP_Scan_Next(State, RetInPcb) int *State; struct inpcb *RetInPcb; { X register struct inpcb *next; X struct tcpcb tcpcb; X X if (inpcb.inp_next == (struct inpcb *) nl[N_TCB].n_value) { X return(0); /* "EOF" */ X } X X next = inpcb.inp_next; X X klookup( (int)next, (char *)&inpcb, sizeof (inpcb)); X if (inpcb.inp_prev != prev) /* ??? */ X return(-1); /* "FAILURE" */ X X klookup ( (int)inpcb.inp_ppcb, (char *)&tcpcb, sizeof (tcpcb)); X *State = tcpcb.t_state; X *RetInPcb = inpcb; X prev = next; X return(1); /* "OK" */ } X static int arptab_size, arptab_current; static struct arptab *at=0; static ARP_Scan_Init() { X extern char *malloc(); X X if (!at) { X KNLookup( N_ARPTAB_SIZE, (char *)&arptab_size, sizeof arptab_size); X at = (struct arptab *) malloc(arptab_size * sizeof(struct arptab)); X } X X KNLookup( N_ARPTAB, (char *)at, arptab_size * sizeof(struct arptab)); X arptab_current = 0; } X static int ARP_Scan_Next(IPAddr, PhysAddr) u_long *IPAddr; char *PhysAddr; { X register struct arptab *atab; X X while (arptab_current < arptab_size) { X atab = &at[arptab_current++]; X if (!(atab->at_flags & ATF_COM)) continue; X *IPAddr = atab->at_iaddr.s_addr; X #if defined (VXWORKS) X /* ??? */ X bcopy((char *) &atab->at_enaddr, PhysAddr, sizeof(atab->at_enaddr)); #endif #if defined (sunV3) || defined(sparc) X bcopy((char *) &atab->at_enaddr, PhysAddr, sizeof(atab->at_enaddr)); #endif #if defined(mips) || defined(ibm032) X bcopy((char *) atab->at_enaddr, PhysAddr, sizeof(atab->at_enaddr)); #endif X return(1); X } X return(0); /* "EOF" */ } X X #ifndef sunV3 static struct in_ifaddr savein_ifaddr; #endif static struct ifnet *ifnetaddr, saveifnet, *saveifnetaddr; static int saveIndex=0; static char saveName[16]; X Interface_Scan_Init() { X KNLookup (N_IFNET, (char *)&ifnetaddr, sizeof(ifnetaddr)); X saveIndex=0; } X X X #ifdef sunV3 /* ** 4.2 BSD doesn't have ifaddr ** */ int Interface_Scan_Next(Index, Name, Retifnet) int *Index; char *Name; struct ifnet *Retifnet; { X struct ifnet ifnet; X register char *cp; X extern char *index(); X X while (ifnetaddr) { X /* X * Get the "ifnet" structure and extract the device name X */ X klookup((int)ifnetaddr, (char *)&ifnet, sizeof ifnet); X klookup((int)ifnet.if_name, (char *)saveName, 16); X if (strcmp(saveName, "ip") == 0) { X ifnetaddr = ifnet.if_next; X continue; X } X X X X saveName[15] = '\0'; X cp = index(saveName, '\0'); X *cp++ = ifnet.if_unit + '0'; X *cp = '\0'; X if (1 || strcmp(saveName,"lo0") != 0) { /* XXX */ X X if (Index) X *Index = ++saveIndex; X if (Retifnet) X *Retifnet = ifnet; X if (Name) X strcpy(Name, saveName); X saveifnet = ifnet; X saveifnetaddr = ifnetaddr; X ifnetaddr = ifnet.if_next; X X return(1); /* DONE */ X } X ifnetaddr = ifnet.if_next; X } X return(0); /* EOF */ } X X #else X int Interface_Scan_Next(Index, Name, Retifnet, Retin_ifaddr) int *Index; char *Name; struct ifnet *Retifnet; struct in_ifaddr *Retin_ifaddr; { X struct ifnet ifnet; X struct in_ifaddr *ia, in_ifaddr; X register char *cp; X extern char *index(); X X while (ifnetaddr) { X /* X * Get the "ifnet" structure and extract the device name X */ X klookup((int)ifnetaddr, (char *)&ifnet, sizeof ifnet); X klookup((int)ifnet.if_name, (char *)saveName, 16); X X saveName[15] = '\0'; X cp = index(saveName, '\0'); X *cp++ = ifnet.if_unit + '0'; X *cp = '\0'; X if (1 || strcmp(saveName,"lo0") != 0) { /* XXX */ X /* X * Try to find an address for this interface X */ X X KNLookup(N_IN_IFADDR, (char *)&ia, sizeof(ia)); X while (ia) { X klookup((int)ia , (char *)&in_ifaddr, sizeof(in_ifaddr)); X if (in_ifaddr.ia_ifp == ifnetaddr) break; X ia = in_ifaddr.ia_next; X } X X ifnet.if_addrlist = (struct ifaddr *)ia; /* WRONG DATA TYPE; ONLY A FLAG */ /* ifnet.if_addrlist = (struct ifaddr *)&ia->ia_ifa; */ /* WRONG DATA TYPE; ONLY A FLAG */ X X if (Index) X *Index = ++saveIndex; X if (Retifnet) X *Retifnet = ifnet; X if (Retin_ifaddr) X *Retin_ifaddr = in_ifaddr; X if (Name) X strcpy(Name, saveName); X saveifnet = ifnet; X saveifnetaddr = ifnetaddr; X savein_ifaddr = in_ifaddr; X ifnetaddr = ifnet.if_next; X X return(1); /* DONE */ X } X ifnetaddr = ifnet.if_next; X } X return(0); /* EOF */ } X X #endif sunV3 X X X X #ifdef sunV3 X static int Interface_Scan_By_Index(Index, Name, Retifnet) int Index; char *Name; struct ifnet *Retifnet; { X int i; X X if (saveIndex != Index) { /* Optimization! */ X Interface_Scan_Init(); X while (Interface_Scan_Next(&i, Name, Retifnet)) { X if (i == Index) break; X } X if (i != Index) return(-1); /* Error, doesn't exist */ X } else { X if (Retifnet) X *Retifnet = saveifnet; X if (Name) X strcpy(Name, saveName); X } X return(0); /* DONE */ } X #else X static int Interface_Scan_By_Index(Index, Name, Retifnet, Retin_ifaddr) int Index; char *Name; struct ifnet *Retifnet; struct in_ifaddr *Retin_ifaddr; { X int i; X X if (saveIndex != Index) { /* Optimization! */ X Interface_Scan_Init(); X while (Interface_Scan_Next(&i, Name, Retifnet, Retin_ifaddr)) { X if (i == Index) break; X } X if (i != Index) return(-1); /* Error, doesn't exist */ X } else { X if (Retifnet) X *Retifnet = saveifnet; X if (Retin_ifaddr) X *Retin_ifaddr = savein_ifaddr; X if (Name) X strcpy(Name, saveName); X } X return(0); /* DONE */ } X #endif X X static int Interface_Count=0; X static int Interface_Scan_Get_Count() { X X if (!Interface_Count) { X Interface_Scan_Init(); #ifdef sunV3 X while (Interface_Scan_Next((int *)0, (char *)0, (struct ifnet *)0) != 0) { #else X while (Interface_Scan_Next((int *)0, (char *)0, (struct ifnet *)0, (struct in_ifaddr *)0) != 0) { #endif X Interface_Count++; X } X } X return(Interface_Count); } X X static int Interface_Get_Ether_By_Index(Index, EtherAddr) int Index; u_char *EtherAddr; { X int i; X struct arpcom arpcom; X X if (saveIndex != Index) { /* Optimization! */ X X Interface_Scan_Init(); X #ifdef sunV3 X while (Interface_Scan_Next((int *)&i, (char *)0, (struct ifnet *)0) != 0) { #else X while (Interface_Scan_Next((int *)&i, (char *)0, (struct ifnet *)0, (struct in_ifaddr *)0) != 0) { #endif X if (i == Index) break; X } X if (i != Index) return(-1); /* Error, doesn't exist */ X } X X /* X * the arpcom structure is an extended ifnet structure which X * contains the ethernet address. X */ X klookup((int)saveifnetaddr, (char *)&arpcom, sizeof (struct arpcom)); X if (strncmp("lo", saveName, 2) == 0) { X /* X * Loopback doesn't have a HW addr, so return 00:00:00:00:00:00 X */ X bzero(EtherAddr, sizeof(arpcom.ac_enaddr)); X X } else { #if defined(VXWORKS) X bcopy((char *) &arpcom.ac_enaddr, EtherAddr, sizeof (arpcom.ac_enaddr)); #endif #if defined(sunV3) || defined(sparc) X bcopy((char *) &arpcom.ac_enaddr, EtherAddr, sizeof (arpcom.ac_enaddr)); #endif #ifdef mips X bcopy((char *) arpcom.ac_enaddr, EtherAddr, sizeof (arpcom.ac_enaddr)); #endif X X X } X return(0); /* DONE */ } X X X #if defined(mips) || defined(ibm032) || defined(sunV3) X X /* ** Lets read the process table in blocks so as to ** minimize sys calls */ #define PROCBLOC 16 struct proc procbuf[PROCBLOC]; X X u_char * var_process(vp, name, length, exact, var_len, write_method) X register struct variable *vp; /* IN - pointer to variable entry that points here */ X register oid *name; /* IN/OUT - input name requested, output name found */ X register int *length; /* IN/OUT - length of input and output oid's */ X int exact; /* IN - TRUE if an exact match was requested. */ X int *var_len; /* OUT - length of variable or 0 if function returned. */ X int (**write_method)(); /* OUT - pointer to function to set variable, otherwise 0 */ { X oid newname[MAX_NAME_LEN]; X register int slotindex; X register int numread, i; X int result, count; X off_t procp; X struct proc *proc; X X X /* NOW BROKEN 6/92 */ X bcopy((char *)vp->name, (char *)newname, (int)vp->namelen * sizeof(oid)); X bzero(return_buf, 256); X X /* find "next" process */ X X X X if (KNLookup(N_PROC, (char *)&procp, sizeof(procp)) == NULL) { X return (NULL); X } X if (KNLookup(N_NPROC, (char *)&count, sizeof(count)) == NULL) { X return (NULL); X } X X proc = NULL; X slotindex = 0; X while ((!proc) && (slotindex < count)) { X X numread = MIN(count - slotindex, PROCBLOC); X if (klookup((int)procp, (char *)procbuf, X numread * sizeof(struct proc)) == NULL) { X return(NULL); X } X procp += sizeof(struct proc) * numread; X X for (i=0; i < numread; i++) { X slotindex++; X X if ((procbuf[i].p_stat == 0) || (procbuf[i].p_stat == SZOMB)) { X continue; X } X newname[13] = (oid) slotindex; X result = compare(name, *length, newname, (int)vp->namelen); X if ((exact && (result == 0)) || (!exact && (result < 0))) { X proc = &procbuf[i]; X break; X } X } X } X X X if (!proc) { X return NULL; X } X X bcopy((char *)newname, (char *)name, (int)vp->namelen * sizeof(oid)); SHAR_EOF : || echo 'restore of snmp2/agent/snmp_vars.c failed' fi echo 'End of snmp2 part 31' echo 'File snmp2/agent/snmp_vars.c is continued in part 32' echo 32 > _sharseq.tmp exit 0