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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [snmp/] [agent/] [current/] [src/] [agent_trap.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/agent_trap.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
/* agent_trap.c: define trap generation routines for mib modules, etc,
92
   to use */
93
 
94
#include <config.h>
95
 
96
#if HAVE_UNISTD_H
97
#include <unistd.h>
98
#endif
99
#if HAVE_STDLIB_H
100
#include <stdlib.h>
101
#endif
102
#if HAVE_STRING_H
103
#include <string.h>
104
#else
105
#include <strings.h>
106
#endif
107
#if TIME_WITH_SYS_TIME
108
# ifdef WIN32
109
#  include <sys/timeb.h>
110
# else
111
#  include <sys/time.h>
112
# endif
113
# include <time.h>
114
#else
115
# if HAVE_SYS_TIME_H
116
#  include <sys/time.h>
117
# else
118
#  include <time.h>
119
# endif
120
#endif
121
#if HAVE_SYS_SOCKET_H
122
#include <sys/socket.h>
123
#elif HAVE_WINSOCK_H
124
#include <winsock.h>
125
#endif
126
#if HAVE_NETINET_IN_H
127
#include <netinet/in.h>
128
#endif
129
 
130
#include "asn1.h"
131
#include "snmp_api.h"
132
#include "snmp_impl.h"
133
#include "snmp_client.h"
134
#include "snmp.h"
135
#include "system.h"
136
#include "read_config.h"
137
#include "snmp_debug.h"
138
 
139
struct trap_sink {
140
    struct snmp_session *sesp;
141
    struct trap_sink    *next;
142
    int                 pdutype;
143
    int                 version;
144
};
145
 
146
struct trap_sink *sinks   = NULL;
147
 
148
extern struct timeval   starttime;
149
 
150
#define OID_LENGTH(x)  (sizeof(x)/sizeof(x[0]))
151
 
152
oid objid_enterprisetrap[] = { EXTENSIBLEMIB, 251 };
153
oid version_id[]           = { EXTENSIBLEMIB, AGENTID, OSTYPE };
154
int enterprisetrap_len = OID_LENGTH( objid_enterprisetrap );
155
int version_id_len     = OID_LENGTH( version_id );
156
 
157
#define SNMPV2_TRAPS_PREFIX     SNMP_OID_SNMPMODULES,1,1,5
158
oid  cold_start_oid[] =         { SNMPV2_TRAPS_PREFIX, 1 };     /* SNMPv2-MIB */
159
oid  warm_start_oid[] =         { SNMPV2_TRAPS_PREFIX, 2 };     /* SNMPv2-MIB */
160
oid  link_down_oid[] =          { SNMPV2_TRAPS_PREFIX, 3 };     /* IF-MIB */
161
oid  link_up_oid[] =            { SNMPV2_TRAPS_PREFIX, 4 };     /* IF-MIB */
162
oid  auth_fail_oid[] =          { SNMPV2_TRAPS_PREFIX, 5 };     /* SNMPv2-MIB */
163
oid  egp_xxx_oid[] =            { SNMPV2_TRAPS_PREFIX, 99 };    /* ??? */
164
 
165
#define SNMPV2_TRAP_OBJS_PREFIX SNMP_OID_SNMPMODULES,1,1,4
166
oid  snmptrap_oid[]           = { SNMPV2_TRAP_OBJS_PREFIX, 1, 0 };
167
oid  snmptrapenterprise_oid[] = { SNMPV2_TRAP_OBJS_PREFIX, 3, 0 };
168
oid  sysuptime_oid[]          = { SNMP_OID_MIB2,1,3,0 };
169
int  snmptrap_oid_len         = OID_LENGTH(snmptrap_oid);
170
int  snmptrapenterprise_oid_len = OID_LENGTH(snmptrapenterprise_oid);
171
int  sysuptime_oid_len        = OID_LENGTH(sysuptime_oid);
172
 
173
 
174
#define SNMP_AUTHENTICATED_TRAPS_ENABLED        1
175
#define SNMP_AUTHENTICATED_TRAPS_DISABLED       2
176
 
177
int      snmp_enableauthentraps = SNMP_AUTHENTICATED_TRAPS_DISABLED;
178
char    *snmp_trapcommunity     = NULL;
179
 
180
/* Prototypes */
181
 /*
182
static int create_v1_trap_session (const char *, u_short, const char *);
183
static int create_v2_trap_session (const char *, u_short, const char *);
184
static int create_v2_inform_session (const char *, u_short, const char *);
185
static void free_trap_session (struct trap_sink *sp);
186
static void send_v1_trap (struct snmp_session *, int, int);
187
static void send_v2_trap (struct snmp_session *, int, int, int);
188
 */
189
 
190
 
191
        /*******************
192
         *
193
         * Trap session handling
194
         *
195
         *******************/
196
int add_trap_session( struct snmp_session *ss, int pdutype, int version )
197
{
198
    struct trap_sink *new_sink =
199
      (struct trap_sink *) malloc (sizeof (*new_sink));
200
    if ( new_sink == NULL )
201
        return 0;
202
 
203
    new_sink->sesp    = ss;
204
    new_sink->pdutype = pdutype;
205
    new_sink->version = version;
206
    new_sink->next    = sinks;
207
    sinks = new_sink;
208
    return 1;
209
}
210
 
211
int create_trap_session (char *sink, u_short sinkport,
212
                                char *com,
213
                                int version, int pdutype)
214
{
215
    struct snmp_session  session, *sesp;
216
 
217
    memset (&session, 0, sizeof (struct snmp_session));
218
    session.peername = sink;
219
    session.version = version;
220
    if (com) {
221
        session.community = (u_char *)com;
222
        session.community_len = strlen (com);
223
    }
224
    session.remote_port = sinkport;
225
    sesp = snmp_open (&session);
226
 
227
    if (sesp) {
228
        return( add_trap_session( sesp, pdutype, version ));
229
    }
230
 
231
    /* diagnose snmp_open errors with the input struct snmp_session pointer */
232
    snmp_sess_perror("snmpd: create_trap_session", &session);
233
    return 0;
234
}
235
 
236
static int create_v1_trap_session (char *sink, u_short sinkport,
237
                                   char *com)
238
{
239
    return create_trap_session( sink, sinkport, com,
240
                                SNMP_VERSION_1, SNMP_MSG_TRAP );
241
}
242
 
243
static int create_v2_trap_session (char *sink,  u_short sinkport,
244
                                   char *com)
245
{
246
    return create_trap_session( sink, sinkport, com,
247
                                SNMP_VERSION_2c, SNMP_MSG_TRAP2 );
248
}
249
 
250
static int create_v2_inform_session (char *sink,  u_short sinkport,
251
                                     char *com)
252
{
253
    return create_trap_session( sink, sinkport, com,
254
                                SNMP_VERSION_2c, SNMP_MSG_INFORM );
255
}
256
 
257
 
258
static void free_trap_session (struct trap_sink *sp)
259
{
260
    snmp_close(sp->sesp);
261
    free (sp);
262
}
263
 
264
 
265
void snmpd_free_trapsinks (void)
266
{
267
    struct trap_sink *sp = sinks;
268
    while (sp) {
269
        sinks = sinks->next;
270
        free_trap_session(sp);
271
        sp = sinks;
272
    }
273
}
274
 
275
        /*******************
276
         *
277
         * Trap handling
278
         *
279
         *******************/
280
 
281
void send_enterprise_trap_vars (int trap,
282
                     int specific,
283
                     oid *enterprise, int enterprise_length,
284
                     struct variable_list *vars)
285
{
286
    struct variable_list uptime_var, snmptrap_var, enterprise_var;
287
    struct variable_list *v2_vars, *last_var=NULL;
288
    struct snmp_pdu     *template_pdu, *pdu;
289
    struct timeval       now;
290
    long uptime;
291
    struct sockaddr_in *pduIp;
292
    struct trap_sink *sink;
293
    oid temp_oid[MAX_OID_LEN];
294
 
295
                /*
296
                 * Initialise SNMPv2 required variables
297
                 */
298
    gettimeofday(&now, NULL);
299
    uptime = calculate_time_diff(&now, &starttime);
300
    memset (&uptime_var, 0, sizeof (struct variable_list));
301
    snmp_set_var_objid( &uptime_var, sysuptime_oid, OID_LENGTH(sysuptime_oid));
302
    snmp_set_var_value( &uptime_var, (u_char *)&uptime, sizeof(uptime) );
303
    uptime_var.type           = ASN_TIMETICKS;
304
    uptime_var.next_variable  = &snmptrap_var;
305
 
306
    memset (&snmptrap_var, 0, sizeof (struct variable_list));
307
    snmp_set_var_objid( &snmptrap_var, snmptrap_oid, OID_LENGTH(snmptrap_oid));
308
        /* value set later .... */
309
    snmptrap_var.type           = ASN_OBJECT_ID;
310
    if ( vars )
311
        snmptrap_var.next_variable  = vars;
312
    else
313
        snmptrap_var.next_variable  = &enterprise_var;
314
 
315
                        /* find end of provided varbind list,
316
                           ready to append the enterprise info if necessary */
317
    last_var = vars;
318
    while ( last_var && last_var->next_variable )
319
        last_var = last_var->next_variable;
320
 
321
    memset (&enterprise_var, 0, sizeof (struct variable_list));
322
    snmp_set_var_objid( &enterprise_var,
323
                 snmptrapenterprise_oid, OID_LENGTH(snmptrapenterprise_oid));
324
    snmp_set_var_value( &enterprise_var, (u_char *)enterprise, enterprise_length*sizeof(oid));
325
    enterprise_var.type           = ASN_OBJECT_ID;
326
    enterprise_var.next_variable  = NULL;
327
 
328
    v2_vars = &uptime_var;
329
 
330
                /*
331
                 *  Create a template PDU, ready for sending
332
                 */
333
    template_pdu = snmp_pdu_create( SNMP_MSG_TRAP );
334
    if ( template_pdu == NULL ) {
335
                /* Free memory if value stored dynamically */
336
        snmp_set_var_value( &enterprise_var, NULL, 0);
337
        return;
338
    }
339
    template_pdu->trap_type     = trap;
340
    template_pdu->specific_type = specific;
341
    if ( snmp_clone_mem((void **)&template_pdu->enterprise,
342
                                enterprise, enterprise_length*sizeof(oid))) {
343
        snmp_free_pdu( template_pdu );
344
        snmp_set_var_value( &enterprise_var, NULL, 0);
345
        return;
346
    }
347
    template_pdu->enterprise_length = enterprise_length;
348
    template_pdu->flags |= UCD_MSG_FLAG_FORCE_PDU_COPY;
349
    pduIp = (struct sockaddr_in *)&template_pdu->agent_addr;
350
    pduIp->sin_family            = AF_INET;
351
    pduIp->sin_len               = sizeof(*pduIp);
352
    pduIp->sin_addr.s_addr       = get_myaddr();
353
    template_pdu->time                   = uptime;
354
 
355
                /*
356
                 *  Now use the parameters to determine
357
                 *    which v2 variables are needed,
358
                 *    and what values they should take.
359
                 */
360
    switch ( trap ) {
361
        case -1:        /*
362
                         *      SNMPv2 only
363
                         *  Check to see whether the variables provided
364
                         *    are sufficient for SNMPv2 notifications
365
                         */
366
                if (vars && snmp_oid_compare(vars->name, vars->name_length,
367
                                sysuptime_oid, OID_LENGTH(sysuptime_oid)) == 0 )
368
                        v2_vars = vars;
369
                else
370
                if (vars && snmp_oid_compare(vars->name, vars->name_length,
371
                                snmptrap_oid, OID_LENGTH(snmptrap_oid)) == 0 )
372
                        uptime_var.next_variable = vars;
373
                else {
374
                        /* Hmmm... we don't seem to have a value - oops! */
375
                        snmptrap_var.next_variable = vars;
376
                }
377
                last_var = NULL;        /* Don't need enterprise info */
378
                break;
379
 
380
                        /* "Standard" SNMPv1 traps */
381
 
382
        case SNMP_TRAP_COLDSTART:
383
                snmp_set_var_value( &snmptrap_var,
384
                                    (u_char *)cold_start_oid,
385
                                    sizeof(cold_start_oid));
386
                break;
387
        case SNMP_TRAP_WARMSTART:
388
                snmp_set_var_value( &snmptrap_var,
389
                                    (u_char *)warm_start_oid,
390
                                    sizeof(warm_start_oid));
391
                break;
392
        case SNMP_TRAP_LINKDOWN:
393
                snmp_set_var_value( &snmptrap_var,
394
                                    (u_char *)link_down_oid,
395
                                    sizeof(link_down_oid));
396
                break;
397
        case SNMP_TRAP_LINKUP:
398
                snmp_set_var_value( &snmptrap_var,
399
                                    (u_char *)link_up_oid,
400
                                    sizeof(link_up_oid));
401
                break;
402
        case SNMP_TRAP_AUTHFAIL:
403
                if (snmp_enableauthentraps == SNMP_AUTHENTICATED_TRAPS_DISABLED) {
404
                    snmp_free_pdu( template_pdu );
405
                    snmp_set_var_value( &enterprise_var, NULL, 0);
406
                    return;
407
                }
408
                snmp_set_var_value( &snmptrap_var,
409
                                    (u_char *)auth_fail_oid,
410
                                    sizeof(auth_fail_oid));
411
                break;
412
        case SNMP_TRAP_EGPNEIGHBORLOSS:
413
                snmp_set_var_value( &snmptrap_var,
414
                                    (u_char *)egp_xxx_oid,
415
                                    sizeof(egp_xxx_oid));
416
                break;
417
 
418
        case SNMP_TRAP_ENTERPRISESPECIFIC:
419
                memcpy( &temp_oid,
420
                                    (char *)enterprise,
421
                                    (enterprise_length)*sizeof(oid));
422
                temp_oid[ enterprise_length   ] = 0;
423
                temp_oid[ enterprise_length+1 ] = specific;
424
                snmp_set_var_value( &snmptrap_var,
425
                                    (u_char *)&temp_oid,
426
                                    (enterprise_length+2)*sizeof(oid));
427
                snmptrap_var.next_variable  = vars;
428
                last_var = NULL;        /* Don't need version info */
429
                break;
430
    }
431
 
432
 
433
                /*
434
                 *  Now loop through the list of trap sinks,
435
                 *   sending an appropriately formatted PDU to each
436
                 */
437
    for ( sink = sinks ; sink ; sink=sink->next ) {
438
        if ( sink->version == SNMP_VERSION_1 && trap == -1 )
439
                continue;       /* Skip v1 sinks for v2 only traps */
440
        template_pdu->version = sink->version;
441
        template_pdu->command = sink->pdutype;
442
        if ( sink->version != SNMP_VERSION_1 ) {
443
            template_pdu->variables = v2_vars;
444
            if ( last_var )
445
                last_var->next_variable = &enterprise_var;
446
        }
447
        else
448
            template_pdu->variables = vars;
449
 
450
        pdu = snmp_clone_pdu( template_pdu );
451
        pdu->sessid = sink->sesp->sessid;       /* AgentX only ? */
452
        if ( snmp_send( sink->sesp, pdu) == 0 ) {
453
            snmp_sess_perror ("snmpd: send_trap", sink->sesp);
454
            snmp_free_pdu( pdu );
455
        }
456
        else {
457
            snmp_increment_statistic(STAT_SNMPOUTTRAPS);
458
            snmp_increment_statistic(STAT_SNMPOUTPKTS);
459
        }
460
 
461
        if ( sink->version != SNMP_VERSION_1 && last_var )
462
            last_var->next_variable = NULL;
463
    }
464
 
465
                /* Free memory if values stored dynamically */
466
    snmp_set_var_value( &enterprise_var, NULL, 0);
467
    snmp_set_var_value( &snmptrap_var, NULL, 0);
468
        /* Ensure we don't free anything we shouldn't */
469
    if ( last_var )
470
        last_var->next_variable = NULL;
471
    template_pdu->variables = NULL;
472
    snmp_free_pdu( template_pdu );
473
}
474
 
475
void send_trap_vars (int trap,
476
                     int specific,
477
                     struct variable_list *vars)
478
{
479
    if ( trap == SNMP_TRAP_ENTERPRISESPECIFIC )
480
        send_enterprise_trap_vars( trap, specific, objid_enterprisetrap,
481
                        OID_LENGTH(objid_enterprisetrap), vars );
482
    else
483
        send_enterprise_trap_vars( trap, specific, version_id,
484
                        OID_LENGTH(version_id), vars );
485
}
486
 
487
void send_easy_trap (int trap,
488
                     int specific)
489
{
490
    send_trap_vars( trap, specific, NULL );
491
}
492
 
493
void send_v2trap ( struct variable_list *vars)
494
{
495
    send_trap_vars( -1, -1, vars );
496
}
497
 
498
void
499
send_trap_pdu(struct snmp_pdu *pdu)
500
{
501
    send_trap_vars( -1, -1, pdu->variables );
502
}
503
 
504
 
505
 
506
        /*******************
507
         *
508
         * Config file handling
509
         *
510
         *******************/
511
 
512
void snmpd_parse_config_authtrap(const char *token,
513
                                 char *cptr)
514
{
515
    int i;
516
 
517
    i = atoi(cptr);
518
    if ( i == 0 ) {
519
        if ( !strcmp( cptr, "enable" ))
520
            i = SNMP_AUTHENTICATED_TRAPS_ENABLED;
521
        else if ( !strcmp( cptr, "disable" ))
522
            i = SNMP_AUTHENTICATED_TRAPS_DISABLED;
523
    }
524
    if (i < 1 || i > 2)
525
        config_perror("authtrapenable must be 1 or 2");
526
    else
527
        snmp_enableauthentraps = i;
528
}
529
 
530
void snmpd_parse_config_trapsink(const char *token,
531
                                 char *cptr)
532
{
533
    char tmpbuf[1024];
534
    char *sp, *cp, *pp = NULL;
535
    u_short sinkport;
536
 
537
    if (!snmp_trapcommunity) snmp_trapcommunity = strdup("public");
538
    sp = strtok(cptr, " \t\n");
539
    cp = strtok(NULL, " \t\n");
540
    if (cp) pp = strtok(NULL, " \t\n");
541
    if (cp && pp) {
542
        sinkport = atoi(pp);
543
        if ((sinkport < 1) || (sinkport > 0xffff)) {
544
            config_perror("trapsink port out of range");
545
            sinkport = SNMP_TRAP_PORT;
546
        }
547
    } else {
548
        sinkport = SNMP_TRAP_PORT;
549
    }
550
    if (create_v1_trap_session(sp, sinkport,
551
                               cp ? cp : snmp_trapcommunity) == 0) {
552
        sprintf(tmpbuf,"cannot create trapsink: %s", cptr);
553
        config_perror(tmpbuf);
554
    }
555
}
556
 
557
 
558
void
559
snmpd_parse_config_trap2sink(const char *word, char *cptr)
560
{
561
    char tmpbuf[1024];
562
    char *sp, *cp, *pp = NULL;
563
    u_short sinkport;
564
 
565
    if (!snmp_trapcommunity) snmp_trapcommunity = strdup("public");
566
    sp = strtok(cptr, " \t\n");
567
    cp = strtok(NULL, " \t\n");
568
    if (cp) pp = strtok(NULL, " \t\n");
569
    if (cp && pp) {
570
        sinkport = atoi(pp);
571
        if ((sinkport < 1) || (sinkport > 0xffff)) {
572
            config_perror("trapsink port out of range");
573
            sinkport = SNMP_TRAP_PORT;
574
        }
575
    } else {
576
        sinkport = SNMP_TRAP_PORT;
577
    }
578
    if (create_v2_trap_session(sp, sinkport,
579
                               cp ? cp : snmp_trapcommunity) == 0) {
580
        sprintf(tmpbuf,"cannot create trap2sink: %s", cptr);
581
        config_perror(tmpbuf);
582
    }
583
}
584
 
585
void
586
snmpd_parse_config_informsink(const char *word, char *cptr)
587
{
588
    char tmpbuf[1024];
589
    char *sp, *cp, *pp = NULL;
590
    u_short sinkport;
591
 
592
    if (!snmp_trapcommunity) snmp_trapcommunity = strdup("public");
593
    sp = strtok(cptr, " \t\n");
594
    cp = strtok(NULL, " \t\n");
595
    if (cp) pp = strtok(NULL, " \t\n");
596
    if (cp && pp) {
597
        sinkport = atoi(pp);
598
        if ((sinkport < 1) || (sinkport > 0xffff)) {
599
            config_perror("trapsink port out of range");
600
            sinkport = SNMP_TRAP_PORT;
601
        }
602
    } else {
603
        sinkport = SNMP_TRAP_PORT;
604
    }
605
    if (create_v2_inform_session(sp, sinkport,
606
                                 cp ? cp : snmp_trapcommunity) == 0) {
607
        sprintf(tmpbuf,"cannot create informsink: %s", cptr);
608
        config_perror(tmpbuf);
609
    }
610
}
611
 
612
void
613
snmpd_parse_config_trapcommunity(const char *word, char *cptr)
614
{
615
    if (snmp_trapcommunity) free(snmp_trapcommunity);
616
    snmp_trapcommunity = malloc (strlen(cptr)+1);
617
    copy_word(cptr, snmp_trapcommunity);
618
}
619
 
620
void snmpd_free_trapcommunity (void)
621
{
622
    if (snmp_trapcommunity) {
623
        free(snmp_trapcommunity);
624
        snmp_trapcommunity = NULL;
625
    }
626
}

powered by: WebSVN 2.1.0

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