OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [net/] [snmp/] [agent/] [v2_0/] [src/] [mibgroup/] [util_funcs.c] - Blame information for rev 322

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      ./agent/current/src/mibgroup/util_funcs.c
4
//
5
//
6
//==========================================================================
7
//####ECOSGPLCOPYRIGHTBEGIN####
8
// -------------------------------------------
9
// This file is part of eCos, the Embedded Configurable Operating System.
10
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
11
//
12
// eCos is free software; you can redistribute it and/or modify it under
13
// the terms of the GNU General Public License as published by the Free
14
// Software Foundation; either version 2 or (at your option) any later version.
15
//
16
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
17
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19
// for more details.
20
//
21
// You should have received a copy of the GNU General Public License along
22
// with eCos; if not, write to the Free Software Foundation, Inc.,
23
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24
//
25
// As a special exception, if other files instantiate templates or use macros
26
// or inline functions from this file, or you compile this file and link it
27
// with other works to produce a work based on this file, this file does not
28
// by itself cause the resulting work to be covered by the GNU General Public
29
// License. However the source code for this file must still be made available
30
// in accordance with section (3) of the GNU General Public License.
31
//
32
// This exception does not invalidate any other reasons why a work based on
33
// this file might be covered by the GNU General Public License.
34
//
35
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
36
// at http://sources.redhat.com/ecos/ecos-license/
37
// -------------------------------------------
38
//####ECOSGPLCOPYRIGHTEND####
39
//####UCDSNMPCOPYRIGHTBEGIN####
40
//
41
// -------------------------------------------
42
//
43
// Portions of this software may have been derived from the UCD-SNMP
44
// project,  <http://ucd-snmp.ucdavis.edu/>  from the University of
45
// California at Davis, which was originally based on the Carnegie Mellon
46
// University SNMP implementation.  Portions of this software are therefore
47
// covered by the appropriate copyright disclaimers included herein.
48
//
49
// The release used was version 4.1.2 of May 2000.  "ucd-snmp-4.1.2"
50
// -------------------------------------------
51
//
52
//####UCDSNMPCOPYRIGHTEND####
53
//==========================================================================
54
//#####DESCRIPTIONBEGIN####
55
//
56
// Author(s):    hmt
57
// Contributors: hmt
58
// Date:         2000-05-30
59
// Purpose:      Port of UCD-SNMP distribution to eCos.
60
// Description:  
61
//              
62
//
63
//####DESCRIPTIONEND####
64
//
65
//==========================================================================
66
/********************************************************************
67
       Copyright 1989, 1991, 1992 by Carnegie Mellon University
68
 
69
                          Derivative Work -
70
Copyright 1996, 1998, 1999, 2000 The Regents of the University of California
71
 
72
                         All Rights Reserved
73
 
74
Permission to use, copy, modify and distribute this software and its
75
documentation for any purpose and without fee is hereby granted,
76
provided that the above copyright notice appears in all copies and
77
that both that copyright notice and this permission notice appear in
78
supporting documentation, and that the name of CMU and The Regents of
79
the University of California not be used in advertising or publicity
80
pertaining to distribution of the software without specific written
81
permission.
82
 
83
CMU AND THE REGENTS OF THE UNIVERSITY OF CALIFORNIA DISCLAIM ALL
84
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
85
WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL CMU OR
86
THE REGENTS OF THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY SPECIAL,
87
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
88
FROM THE LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
89
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
90
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
91
*********************************************************************/
92
/*
93
 * util_funcs.c
94
 */
95
 
96
#include <config.h>
97
 
98
#if HAVE_IO_H
99
#include <io.h>
100
#endif
101
#include <stdio.h>
102
#if HAVE_STDLIB_H
103
#include <stdlib.h>
104
#endif
105
#if HAVE_MALLOC_H
106
#include <malloc.h>
107
#endif
108
#include <sys/types.h>
109
#ifdef __alpha
110
#ifndef _BSD
111
#define _BSD
112
#define _myBSD
113
#endif
114
#endif
115
#if HAVE_SYS_WAIT_H
116
# include <sys/wait.h>
117
#endif
118
#ifdef __alpha
119
#ifdef _myBSD
120
#undef _BSD
121
#undef _myBSD
122
#endif
123
#endif
124
#ifndef WEXITSTATUS
125
# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
126
#endif
127
#ifndef WIFEXITED
128
# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
129
#endif
130
#if TIME_WITH_SYS_TIME
131
# ifdef WIN32
132
#  include <sys/timeb.h>
133
# else
134
#  include <sys/time.h>
135
# endif
136
# include <time.h>
137
#else
138
# if HAVE_SYS_TIME_H
139
#  include <sys/time.h>
140
# else
141
#  include <time.h>
142
# endif
143
#endif
144
#if HAVE_UNISTD_H
145
#include <unistd.h>
146
#endif
147
#if HAVE_FCNTL_H
148
#include <fcntl.h>
149
#endif
150
#include <errno.h>
151
#include <signal.h>
152
#if HAVE_STRING_H
153
#include <string.h>
154
#else
155
#include <strings.h>
156
#endif
157
#include <ctype.h>
158
#if HAVE_WINSOCK_H
159
#include <winsock.h>
160
#endif
161
#if HAVE_BASETSD_H
162
#include <basetsd.h>
163
#define ssize_t SSIZE_T
164
#endif
165
#if HAVE_RAISE
166
#define alarm raise
167
#endif
168
#include "mibincl.h"
169
#include "mibgroup/struct.h"
170
#include "mibgroup/util_funcs.h"
171
#include "system.h"
172
#if HAVE_LIMITS_H
173
#include "limits.h"
174
#endif
175
#ifdef USING_UCD_SNMP_ERRORMIB_MODULE
176
#include "ucd-snmp/errormib.h"
177
#else
178
#define setPerrorstatus(x) snmp_log_perror(x)
179
#endif
180
#include "read_config.h"
181
 
182
#ifdef EXCACHETIME
183
static long cachetime;
184
#endif
185
 
186
extern int numprocs, numextens;
187
 
188
void
189
Exit(int var)
190
{
191
  snmp_log(LOG_ERR, "Server Exiting with code %d\n",var);
192
  exit(var);
193
}
194
 
195
int shell_command(struct extensible *ex)
196
{
197
#if HAVE_SYSTEM
198
  char shellline[STRMAX];
199
  FILE *shellout;
200
 
201
  sprintf(shellline,"%s > /tmp/shoutput",ex->command);
202
  ex->result = system(shellline);
203
  ex->result = WEXITSTATUS(ex->result);
204
  shellout = fopen("/tmp/shoutput","r");
205
  if((shellout = fopen("/tmp/shoutput","r")) != NULL) {
206
    if (fgets(ex->output,STRMAX,shellout) == NULL) {
207
      ex->output[0] = 0;
208
    }
209
    fclose(shellout);
210
  }
211
  unlink("/tmp/shoutput");
212
#else
213
  ex->output[0] = 0;
214
  ex->result = 0;
215
#endif
216
  return(ex->result);
217
}
218
 
219
#define MAXOUTPUT 300
220
 
221
int exec_command(struct extensible *ex)
222
{
223
#if HAVE_EXECV
224
  int fd;
225
  FILE *file;
226
 
227
  if ((fd = get_exec_output(ex))) {
228
    file = fdopen(fd,"r");
229
    if (fgets(ex->output,STRMAX,file) == NULL) {
230
      ex->output[0] = 0;
231
    }
232
    fclose(file);
233
    wait_on_exec(ex);
234
  } else
235
#endif
236
  {
237
    ex->output[0] = 0;
238
    ex->result = 0;
239
  }
240
  return(ex->result);
241
}
242
 
243
void wait_on_exec(struct extensible *ex)
244
{
245
#ifndef __ECOS
246
#ifndef EXCACHETIME
247
    if (ex->pid && waitpid(ex->pid,&ex->result,0) < 0) {
248
      setPerrorstatus("waitpid");
249
    }
250
    ex->pid = 0;
251
#endif
252
#endif
253
}
254
 
255
#define MAXARGS 30
256
 
257
int get_exec_output(struct extensible *ex)
258
{
259
#if HAVE_EXECV
260
  int fd[2],i, cnt;
261
  char ctmp[STRMAX], *cptr1, *cptr2, argvs[STRMAX], **argv, **aptr;
262
#ifdef EXCACHETIME
263
  char cache[MAXCACHESIZE];
264
  ssize_t cachebytes;
265
  long curtime;
266
  static char lastcmd[STRMAX];
267
  int cfd;
268
  static int lastresult;
269
  int readcount;
270
#endif
271
 
272
#ifdef EXCACHETIME
273
  curtime = time(NULL);
274
  if (curtime > (cachetime + EXCACHETIME) ||
275
      strcmp(ex->command, lastcmd) != 0) {
276
    strcpy(lastcmd,ex->command);
277
    cachetime = curtime;
278
#endif
279
    if (pipe(fd))
280
      {
281
        setPerrorstatus("pipe");
282
#ifdef EXCACHETIME
283
        cachetime = 0;
284
#endif
285
        return 0;
286
      }
287
    if ((ex->pid = fork()) == 0)
288
      {
289
        close(1);
290
        if (dup(fd[1]) != 1)
291
          {
292
            setPerrorstatus("dup");
293
            return 0;
294
          }
295
        close(fd[1]);
296
        close(fd[0]);
297
        for(cnt=1,cptr1 = ex->command, cptr2 = argvs; *cptr1 != 0;
298
            cptr2++, cptr1++) {
299
          *cptr2 = *cptr1;
300
          if (*cptr1 == ' ') {
301
            *(cptr2++) = 0;
302
            cptr1 = skip_white(cptr1);
303
            *cptr2 = *cptr1;
304
            if (*cptr1 != 0) cnt++;
305
          }
306
        }
307
        *cptr2 = 0;
308
        *(cptr2+1) = 0;
309
        argv = (char **) malloc((cnt+2) * sizeof(char *));
310
        if (argv == NULL)
311
          return 0; /* memory alloc error */
312
        aptr = argv;
313
        *(aptr++) = argvs;
314
        for (cptr2 = argvs, i=1; i != cnt; cptr2++)
315
          if (*cptr2 == 0) {
316
            *(aptr++) = cptr2 + 1;
317
            i++;
318
          }
319
        while (*cptr2 != 0) cptr2++;
320
        *(aptr++) = NULL;
321
        copy_word(ex->command,ctmp);
322
        execv(ctmp,argv);
323
        snmp_log_perror(ctmp);
324
        exit(1);
325
      }
326
    else
327
      {
328
        close(fd[1]);
329
        if (ex->pid < 0) {
330
          close(fd[0]);
331
          setPerrorstatus("fork");
332
#ifdef EXCACHETIME
333
          cachetime = 0;
334
#endif
335
          return 0;
336
        }
337
#ifdef EXCACHETIME
338
        unlink(CACHEFILE);
339
        /* XXX  Use SNMP_FILEMODE_CLOSED instead of 644? */
340
        if ((cfd = open(CACHEFILE,O_WRONLY|O_TRUNC|O_CREAT,0644)) < 0) {
341
          setPerrorstatus("open");
342
          cachetime = 0;
343
          return 0;
344
        }
345
        fcntl(fd[0],F_SETFL,O_NONBLOCK);  /* don't block on reads */
346
#ifdef HAVE_USLEEP
347
        for (readcount = 0; readcount <= MAXREADCOUNT*100 &&
348
               (cachebytes = read(fd[0],(void *)cache,MAXCACHESIZE));
349
             readcount++) {
350
#else
351
        for (readcount = 0; readcount <= MAXREADCOUNT &&
352
               (cachebytes = read(fd[0],(void *)cache,MAXCACHESIZE));
353
             readcount++) {
354
#endif
355
          if (cachebytes > 0)
356
            write(cfd,(void *) cache, cachebytes);
357
          else if (cachebytes == -1 && errno != EAGAIN) {
358
            setPerrorstatus("read");
359
            break;
360
          }
361
          else
362
#ifdef HAVE_USLEEP
363
            usleep (10000);     /* sleeps for 0.01 sec */
364
#else
365
            sleep (1);
366
#endif
367
        }
368
        close(cfd);
369
        close(fd[0]);
370
        /* wait for the child to finish */
371
        if (ex->pid > 0 && waitpid(ex->pid,&ex->result,0) < 0) {
372
          setPerrorstatus("waitpid()");
373
          cachetime = 0;
374
          return 0;
375
        }
376
        ex->pid = 0;
377
        ex->result = WEXITSTATUS(ex->result);
378
        lastresult = ex->result;
379
#else /* !EXCACHETIME */
380
        return(fd[0]);
381
#endif
382
      }
383
#ifdef EXCACHETIME
384
  }
385
  else {
386
      ex->result = lastresult;
387
  }
388
  if ((cfd = open(CACHEFILE,O_RDONLY)) < 0) {
389
    setPerrorstatus("open");
390
    return 0;
391
  }
392
  return(cfd);
393
#endif
394
 
395
#else /* !HAVE_EXECV */
396
  return 0;
397
#endif
398
}
399
 
400
int get_exec_pipes(char *cmd,
401
                   int *fdIn,
402
                   int *fdOut,
403
                   int *pid)
404
 
405
{
406
#if HAVE_EXECV
407
  int fd[2][2],i, cnt;
408
  char ctmp[STRMAX], *cptr1, *cptr2, argvs[STRMAX], **argv, **aptr;
409
  /* Setup our pipes */
410
  if (pipe(fd[0]) || pipe(fd[1]))
411
    {
412
      setPerrorstatus("pipe");
413
      return 0;
414
    }
415
  if ((*pid = fork()) == 0)   /* First handle for the child */
416
    {
417
      close(0);
418
      if (dup(fd[0][0]) != 0)
419
        {
420
          setPerrorstatus("dup");
421
          return 0;
422
        }
423
      close(1);
424
      if (dup(fd[1][1]) != 1)
425
        {
426
          setPerrorstatus("dup");
427
          return 0;
428
        }
429
      close(fd[0][0]);
430
      close(fd[0][1]);
431
      close(fd[1][0]);
432
      close(fd[1][1]);
433
      for(cnt=1,cptr1 = cmd, cptr2 = argvs; *cptr1 != 0;
434
          cptr2++, cptr1++) {
435
        *cptr2 = *cptr1;
436
        if (*cptr1 == ' ') {
437
          *(cptr2++) = 0;
438
          cptr1 = skip_white(cptr1);
439
          *cptr2 = *cptr1;
440
          if (*cptr1 != 0) cnt++;
441
        }
442
      }
443
      *cptr2 = 0;
444
      *(cptr2+1) = 0;
445
      argv = (char **) malloc((cnt+2) * sizeof(char *));
446
      if (argv == NULL)
447
        return 0; /* memory alloc error */
448
      aptr = argv;
449
      *(aptr++) = argvs;
450
      for (cptr2 = argvs, i=1; i != cnt; cptr2++)
451
        if (*cptr2 == 0) {
452
          *(aptr++) = cptr2 + 1;
453
          i++;
454
        }
455
      while (*cptr2 != 0) cptr2++;
456
      *(aptr++) = NULL;
457
      copy_word(cmd,ctmp);
458
      execv(ctmp,argv);
459
      snmp_log_perror("execv");
460
      exit(1);
461
    }
462
  else
463
    {
464
      close(fd[0][0]);
465
      close(fd[1][1]);
466
      if (*pid < 0) {
467
        close(fd[0][1]);
468
        close(fd[1][0]);
469
        setPerrorstatus("fork");
470
        return 0;
471
      }
472
      *fdIn = fd[1][0];
473
      *fdOut = fd[0][1];
474
      return(1); /* We are returning 0 for error... */
475
    }
476
#endif /* !HAVE_EXECV */
477
  return 0;
478
}
479
 
480
int clear_cache(int action,
481
                u_char *var_val,
482
                u_char var_val_type,
483
                size_t var_val_len,
484
                u_char *statP,
485
                oid *name,
486
                size_t name_len)
487
{
488
 
489
  long tmp=0;
490
 
491
  if (var_val_type != ASN_INTEGER) {
492
    snmp_log(LOG_NOTICE, "Wrong type != int\n");
493
    return SNMP_ERR_WRONGTYPE;
494
  }
495
  tmp = *((long *) var_val);
496
  if (tmp == 1 && action == COMMIT) {
497
#ifdef EXCACHETIME
498
    cachetime = 0;                      /* reset the cache next read */
499
#endif 
500
  }
501
  return SNMP_ERR_NOERROR;
502
}
503
 
504
char **argvrestartp, *argvrestartname, *argvrestart;
505
 
506
RETSIGTYPE restart_doit(int a)
507
{
508
  int i;
509
 
510
  /* close everything open */
511
  for (i=0; i<= 2; i++)
512
    close(i);
513
 
514
  /* do the exec */
515
#if HAVE_EXECV
516
  execv(argvrestartname,argvrestartp);
517
  setPerrorstatus("execv");
518
#endif
519
}
520
 
521
int
522
restart_hook(int action,
523
             u_char *var_val,
524
             u_char var_val_type,
525
             size_t var_val_len,
526
             u_char *statP,
527
             oid *name,
528
             size_t name_len)
529
{
530
 
531
  long tmp=0;
532
 
533
  if (var_val_type != ASN_INTEGER) {
534
    snmp_log(LOG_NOTICE, "Wrong type != int\n");
535
    return SNMP_ERR_WRONGTYPE;
536
  }
537
  tmp = *((long *) var_val);
538
  if (tmp == 1 && action == COMMIT) {
539
#ifdef SIGALRM
540
    signal(SIGALRM,restart_doit);
541
#endif
542
#ifndef __ECOS
543
    alarm(RESTARTSLEEP);
544
#endif
545
  }
546
  return SNMP_ERR_NOERROR;
547
}
548
 
549
void
550
print_mib_oid(oid name[],
551
              size_t len)
552
{
553
  char *buffer;
554
  buffer=malloc(11*len); /* maximum digit lengths for int32 + a '.' */
555
  if (!buffer) {
556
    snmp_log(LOG_ERR, "Malloc failed - out of memory?");
557
    return;
558
  }
559
  sprint_mib_oid(buffer, name, len);
560
  snmp_log(LOG_NOTICE, "Mib: %s\n", buffer);
561
  free(buffer);
562
}
563
 
564
void
565
sprint_mib_oid(char *buf,
566
               oid name[],
567
               size_t len)
568
{
569
  int i;
570
  for(i=0; i < (int)len; i++) {
571
    sprintf(buf,".%d",(int) name[i]);
572
    while (*buf != 0)
573
      buf++;
574
  }
575
}
576
 
577
/*******************************************************************-o-******
578
 * header_simple_table
579
 *
580
 * Parameters:
581
 *        *vp            Variable data.
582
 *        *name          Fully instantiated OID name.
583
 *        *length        Length of name.
584
 *         exact         TRUE if an exact match is desired.
585
 *        *var_len       Hook for size of returned data type.
586
 *      (**write_method) Hook for write method (UNUSED).
587
 *         max
588
 *
589
 * Returns:
590
 *      0        If name matches vp->name (accounting for 'exact') and is
591
 *                      not greater in length than 'max'.
592
 *      1       Otherwise.
593
 *
594
 *
595
 * Compare 'name' to vp->name for the best match or an exact match (if
596
 *      requested).  Also check that 'name' is not longer than 'max' if
597
 *      max is greater-than/equal 0.
598
 * Store a successful match in 'name', and increment the OID instance if
599
 *      the match was not exact.
600
 *
601
 * 'name' and 'length' are undefined upon failure.
602
 *
603
 */
604
int header_simple_table(struct variable *vp, oid *name, size_t *length,
605
                        int exact, size_t *var_len,
606
                        WriteMethod **write_method, int max)
607
{
608
  int   i,
609
        rtest;  /* Set to:      -1      If name < vp->name,
610
                 *              1       If name > vp->name,
611
                 *              0        Otherwise.
612
                 */
613
  oid newname[MAX_OID_LEN];
614
 
615
  for(i=0,rtest=0; i < (int) vp->namelen && i < (int)(*length) && !rtest; i++) {
616
    if (name[i] != vp->name[i]) {
617
      if (name[i] < vp->name[i])
618
        rtest = -1;
619
      else
620
        rtest = 1;
621
    }
622
  }
623
  if (rtest > 0 ||
624
      (rtest == 0 && !exact && (int)(vp->namelen+1) < (int) *length) ||
625
    (exact == 1 && (rtest || (int)*length != (int)(vp->namelen+1)))) {
626
    if (var_len)
627
        *var_len = 0;
628
    return MATCH_FAILED;
629
  }
630
 
631
  memset(newname, 0, sizeof(newname));
632
 
633
  if (((int) *length) <= (int) vp->namelen || rtest == -1) {
634
    memmove(newname, vp->name, (int)vp->namelen * sizeof (oid));
635
    newname[vp->namelen] = 1;
636
    *length = vp->namelen+1;
637
  }
638
  else {
639
    *length = vp->namelen+1;
640
    memmove(newname, name, (*length) * sizeof(oid));
641
    if (!exact)
642
      newname[*length-1] = name[*length-1] + 1;
643
    else
644
      newname[*length-1] = name[*length-1];
645
  }
646
  if (max >= 0 && ((int)newname[*length-1] > max)) {
647
    if(var_len)
648
      *var_len = 0;
649
    return MATCH_FAILED;
650
  }
651
 
652
  memmove(name, newname, (*length) * sizeof(oid));
653
  if (write_method)
654
    *write_method = 0;
655
  if (var_len)
656
    *var_len = sizeof(long);   /* default */
657
  return(MATCH_SUCCEEDED);
658
}
659
 
660
/*
661
  header_generic(...
662
  Arguments:
663
  vp      IN      - pointer to variable entry that points here
664
  name    IN/OUT  - IN/name requested, OUT/name found
665
  length  IN/OUT  - length of IN/OUT oid's
666
  exact   IN      - TRUE if an exact match was requested
667
  var_len OUT     - length of variable or 0 if function returned
668
  write_method
669
 
670
*/
671
 
672
/*******************************************************************-o-******
673
 * generic_header
674
 *
675
 * Parameters:
676
 *        *vp      (I)     Pointer to variable entry that points here.
677
 *        *name    (I/O)   Input name requested, output name found.
678
 *        *length  (I/O)   Length of input and output oid's.
679
 *         exact   (I)     TRUE if an exact match was requested.
680
 *        *var_len (O)     Length of variable or 0 if function returned.
681
 *      (**write_method)   Hook to name a write method (UNUSED).
682
 *
683
 * Returns:
684
 *      MATCH_SUCCEEDED If vp->name matches name (accounting for exact bit).
685
 *      MATCH_FAILED    Otherwise,
686
 *
687
 *
688
 * Check whether variable (vp) matches name.
689
 */
690
int
691
header_generic(struct variable *vp,
692
               oid *name,
693
               size_t *length,
694
               int exact,
695
               size_t *var_len,
696
               WriteMethod **write_method)
697
{
698
    oid newname[MAX_OID_LEN];
699
    int result;
700
 
701
    DEBUGMSGTL(("util_funcs", "header_generic: "));
702
    DEBUGMSGOID(("util_funcs", name, *length));
703
    DEBUGMSG(("util_funcs"," exact=%d\n", exact));
704
 
705
    memcpy((char *)newname, (char *)vp->name, (int)vp->namelen * sizeof(oid));
706
    newname[vp->namelen] = 0;
707
    result = snmp_oid_compare(name, *length, newname, vp->namelen + 1);
708
    DEBUGMSGTL(("util_funcs", "  result: %d\n", result));
709
    if ((exact && (result != 0)) || (!exact && (result >= 0)))
710
        return(MATCH_FAILED);
711
    memcpy( (char *)name,(char *)newname, ((int)vp->namelen + 1) * sizeof(oid));
712
    *length = vp->namelen + 1;
713
 
714
    *write_method = 0;
715
    *var_len = sizeof(long);    /* default to 'long' results */
716
    return(MATCH_SUCCEEDED);
717
}
718
 
719
/* checkmib(): provided for backwards compatibility, do not use: */
720
int checkmib(struct variable *vp, oid *name, size_t *length,
721
             int exact, size_t *var_len,
722
             WriteMethod **write_method, int max) {
723
  /* checkmib used to be header_simple_table, with reveresed boolean
724
     return output.  header_simple_table() was created to match
725
     header_generic(). */
726
  return (!header_simple_table(vp, name, length, exact, var_len,
727
                              write_method, max));
728
}
729
 
730
char *find_field(char *ptr,
731
                 int field)
732
{
733
  int i;
734
  char *init=ptr;
735
 
736
  if (field == LASTFIELD) {
737
    /* skip to end */
738
    while (*ptr++);
739
    ptr = ptr - 2;
740
    /* rewind a field length */
741
    while (*ptr != 0 && isspace(*ptr) && init <= ptr) ptr--;
742
    while (*ptr != 0 && !isspace(*ptr) && init <= ptr) ptr--;
743
    if (isspace(*ptr)) ptr++;  /* past space */
744
    if (ptr < init) ptr = init;
745
    if (!isspace(*ptr) && *ptr != 0) return(ptr);
746
  } else {
747
    if ((ptr = skip_white(ptr)) == NULL) return(NULL);
748
    for (i=1; *ptr != 0 && i != field; i++)
749
      {
750
        if ((ptr = skip_not_white(ptr)) == NULL) return (NULL);
751
        if ((ptr = skip_white(ptr)) == NULL) return (NULL);
752
      }
753
    if (*ptr != 0 && i == field) return(ptr);
754
    return (NULL);
755
  }
756
  return(NULL);
757
}
758
 
759
int parse_miboid(const char *buf,
760
                 oid *oidout)
761
{
762
  int i;
763
 
764
  if (!buf)
765
    return 0;
766
  if (*buf == '.') buf++;
767
  for(i=0;isdigit(*buf);i++) {
768
    oidout[i] = atoi(buf);
769
    while(isdigit(*buf++));
770
    if (*buf == '.') buf++;
771
  }
772
  /* oidout[i] = -1; hmmm */
773
  return i;
774
}
775
 
776
void
777
string_append_int (char *s,
778
                   int val)
779
{
780
    char textVal[16];
781
 
782
    if (val < 10) {
783
        *s++ = '0' + val;
784
        *s = '\0';
785
        return;
786
    }
787
    sprintf (textVal, "%d", val);
788
    strcpy(s, textVal);
789
    return;
790
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.