Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
util_funcs.c
Package: snmp.src.rar [view]
Upload User: cxs890
Upload Date: 2021-05-22
Package Size: 347k
Code Size: 7k
Category:
SNMP
Development Platform:
C/C++
- /*
- * util_funcs.c
- */
- #include <config.h>
- #if HAVE_IO_H
- #include <io.h>
- #endif
- #include <stdio.h>
- #if HAVE_STDLIB_H
- #include <stdlib.h>
- #endif
- #if HAVE_MALLOC_H
- #include <malloc.h>
- #endif
- #include <sys/types.h>
- #ifdef __alpha
- #ifndef _BSD
- #define _BSD
- #define _myBSD
- #endif
- #endif
- #if HAVE_SYS_WAIT_H
- # include <sys/wait.h>
- #endif
- #ifdef __alpha
- #ifdef _myBSD
- #undef _BSD
- #undef _myBSD
- #endif
- #endif
- #ifndef WEXITSTATUS
- # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
- #endif
- #ifndef WIFEXITED
- # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
- #endif
- #if TIME_WITH_SYS_TIME
- # ifdef WIN32
- # include <sys/timeb.h>
- # else
- # include <time.h>
- # endif
- # include <time.h>
- #else
- # if HAVE_SYS_TIME_H
- # include <sys/time.h>
- # else
- # include <time.h>
- # endif
- #endif
- #if HAVE_UNISTD_H
- #include <unistd.h>
- #endif
- #if HAVE_FCNTL_H
- #include <fcntl.h>
- #endif
- #include <errno.h>
- #include <signal.h>
- #if HAVE_STRING_H
- #include <string.h>
- #else
- #include <strings.h>
- #endif
- #include <ctype.h>
- #if HAVE_WINSOCK_H
- #include <ip/socket.h>
- #endif
- #if HAVE_BASETSD_H
- #include <basetsd.h>
- #define ssize_t SSIZE_T
- #endif
- #if HAVE_RAISE
- #define alarm raise
- #endif
- #include "mibincl.h"
- #include "struct.h"
- #include "util_funcs.h"
- #include <snmplib/system.h>
- #if HAVE_LIMITS_H
- #include "limits.h"
- #endif
- #ifdef USING_UCD_SNMP_ERRORMIB_MODULE
- #include "ucd-snmp/errormib.h"
- #else
- #define setPerrorstatus(x) snmp_log_perror(x)
- #endif
- #include "read_config.h"
- extern int numprocs, numextens;
- extern char *skip_white (char *);
- char *skip_not_white (char *);
- #define MAXARGS 30
- /************************************************************************
- * generic_header
- *
- * Parameters:
- * *vp (I) Pointer to variable entry that points here.
- * *name (I/O) Input name requested, output name found.
- * *length (I/O) Length of input and output oid's.
- * exact (I) TRUE if an exact match was requested.
- * *var_len (O) Length of variable or 0 if function returned.
- * (**write_method) Hook to name a write method (UNUSED).
- *
- * Returns:
- * MATCH_SUCCEEDED If vp->name matches name (accounting for exact bit).
- * MATCH_FAILED Otherwise,
- *
- * vp->namelen:oid length of leaf
- * vp->namelen+1:oid length of index
- * Check whether variable (vp) matches name.
- */
- int header_table_generic(struct variable *vp,
- oid *name,
- int *length,
- int exact,
- int *var_len,
- WriteMethod **write_method)
- {
- int result;
- /* int flag = 0;*/
- int len = min(vp->namelen, *length);
- result = snmp_oid_compare(name, len, vp->name , len );
- if(exact && result || result > 0 )
- return MATCH_FAILED;
- if( result < 0 || (!exact && *length <= vp->namelen))/*未下发索引,将索引初始化为零*/
- {
- name[vp->namelen] = 0;
- *length = vp->namelen + 1;
- }
- *write_method = NULL;
- *var_len = sizeof(uint32);
- memcpy( name, vp->name, vp->namelen * sizeof(oid));
- return(MATCH_SUCCEEDED);
- }
- /*
- header_generic(...
- Arguments:
- vp IN - pointer to variable entry that points here
- name IN/OUT - IN/name requested, OUT/name found
- length IN/OUT - length of IN/OUT oid's
- exact IN - TRUE if an exact match was requested
- var_len OUT - length of variable or 0 if function returned
- write_method
- */
- /*******************************************************************-o-******
- * generic_header
- *
- * Parameters:
- * *vp (I) Pointer to variable entry that points here.
- * *name (I/O) Input name requested, output name found.
- * *length (I/O) Length of input and output oid's.
- * exact (I) TRUE if an exact match was requested.
- * *var_len (O) Length of variable or 0 if function returned.
- * (**write_method) Hook to name a write method (UNUSED).
- *
- * Returns:
- * MATCH_SUCCEEDED If vp->name matches name (accounting for exact bit).
- * MATCH_FAILED Otherwise,
- *
- *
- * Check whether variable (vp) matches name.
- */
- int
- header_generic(struct variable *vp,
- oid *name,
- int *length,
- int exact,
- int *var_len,
- WriteMethod **write_method)
- {
- oid newname[MAX_OID_LEN];
- int result;
- DEBUGMSGTL(("util_funcs", "header_generic: "));
- DEBUGMSGOID(("util_funcs", name, *length));
- DEBUGMSG(("util_funcs"," exact=%dn", exact));
- memcpy((char *)newname, (char *)vp->name, (int)vp->namelen * sizeof(oid));
- newname[vp->namelen] = 0;
- result = snmp_oid_compare(name, *length, newname, vp->namelen + 1);
- DEBUGMSGTL(("util_funcs", " result: %dn", result));
- if ((exact && (result != 0)) || (!exact && (result >= 0)))
- return(MATCH_FAILED);
- memcpy( (char *)name,(char *)newname, ((int)vp->namelen + 1) * sizeof(oid));
- *length = vp->namelen + 1;
- *write_method = 0;
- *var_len = sizeof(long); /* default to 'long' results */
- return(MATCH_SUCCEEDED);
- }
- #if 0
- /* checkmib(): provided for backwards compatibility, do not use: */
- int checkmib(struct variable *vp, oid *name, int *length,
- int exact, int *var_len,
- WriteMethod **write_method, int max) {
- /* checkmib used to be header_simple_table, with reveresed boolean
- return output. header_simple_table() was created to match
- header_generic(). */
- return (!header_simple_table(vp, name, length, exact, var_len,
- write_method, max));
- }
- #endif
- char *find_field(char *ptr,
- int field)
- {
- int i;
- char *init=ptr;
- if (field == LASTFIELD) {
- /* skip to end */
- while (*ptr++);
- ptr = ptr - 2;
- /* rewind a field length */
- while (*ptr != 0 && isspace(*ptr) && init <= ptr) ptr--;
- while (*ptr != 0 && !isspace(*ptr) && init <= ptr) ptr--;
- if (isspace(*ptr)) ptr++; /* past space */
- if (ptr < init) ptr = init;
- if (!isspace(*ptr) && *ptr != 0) return(ptr);
- } else {
- if ((ptr = skip_white(ptr)) == NULL) return(NULL);
- for (i=1; *ptr != 0 && i != field; i++)
- {
- if ((ptr = skip_not_white(ptr)) == NULL) return (NULL);
- if ((ptr = skip_white(ptr)) == NULL) return (NULL);
- }
- if (*ptr != 0 && i == field) return(ptr);
- return (NULL);
- }
- return(NULL);
- }
- int parse_miboid(const char *buf,
- oid *oidout)
- {
- int i;
- if (!buf)
- return 0;
- if (*buf == '.') buf++;
- for(i=0;isdigit(*buf);i++) {
- oidout[i] = atoi(buf);
- while(isdigit(*buf++));
- if (*buf == '.') buf++;
- }
- /* oidout[i] = -1; hmmm */
- return i;
- }
- void
- string_append_int (char *s,
- int val)
- {
- char textVal[16];
- if (val < 10) {
- *s++ = (unsigned char)('0' + val);
- *s = '';
- return;
- }
- sprintf (textVal, "%d", val);
- strcpy(s, textVal);
- return;
- }