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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [snmp/] [agent/] [current/] [src/] [mibgroup/] [util_funcs.c] - Blame information for rev 786

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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