~ubuntu-branches/ubuntu/gutsy/net-snmp/gutsy-security

« back to all changes in this revision

Viewing changes to agent/mibgroup/mibII/udpTable.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-09-13 12:06:21 UTC
  • Revision ID: james.westby@ubuntu.com-20040913120621-g952ntonlleihcvm
Tags: upstream-5.1.1
ImportĀ upstreamĀ versionĀ 5.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  UDP MIB group Table implementation - udpTable.c
 
3
 *
 
4
 */
 
5
 
 
6
/* Portions of this file are subject to the following copyright(s).  See
 
7
 * the Net-SNMP's COPYING file for more details and other copyrights
 
8
 * that may apply:
 
9
 */
 
10
/*
 
11
 * Portions of this file are copyrighted by:
 
12
 * Copyright ļæ½ 2003 Sun Microsystems, Inc. All rights reserved.
 
13
 * Use is subject to license terms specified in the COPYING file
 
14
 * distributed with the Net-SNMP package.
 
15
 */
 
16
 
 
17
#include <net-snmp/net-snmp-config.h>
 
18
#include "mibII_common.h"
 
19
 
 
20
#if HAVE_NETINET_UDP_H
 
21
#include <netinet/udp.h>
 
22
#endif
 
23
#if HAVE_NETINET_UDP_VAR_H
 
24
#include <netinet/udp_var.h>
 
25
#endif
 
26
 
 
27
#include <net-snmp/net-snmp-includes.h>
 
28
#include <net-snmp/agent/net-snmp-agent-includes.h>
 
29
#include <net-snmp/agent/auto_nlist.h>
 
30
 
 
31
#ifdef linux
 
32
#include "tcpTable.h"
 
33
#endif
 
34
#include "udp.h"
 
35
#include "udpTable.h"
 
36
#include "sysORTable.h"
 
37
 
 
38
#ifdef hpux11
 
39
#define UDPTABLE_ENTRY_TYPE     mib_udpLsnEnt 
 
40
#define UDPTABLE_LOCALADDRESS   LocalAddress 
 
41
#define UDPTABLE_LOCALPORT      LocalPort 
 
42
#define UDPTABLE_IS_TABLE
 
43
#else
 
44
 
 
45
#ifdef solaris2
 
46
typedef struct netsnmp_udpEntry_s netsnmp_udpEntry;
 
47
struct netsnmp_udpEntry_s {
 
48
    mib2_udpEntry_t   entry;
 
49
    netsnmp_udpEntry *inp_next;
 
50
};
 
51
#define UDPTABLE_ENTRY_TYPE     netsnmp_udpEntry
 
52
#define UDPTABLE_LOCALADDRESS   entry.udpLocalAddress 
 
53
#define UDPTABLE_LOCALPORT      entry.udpLocalPort 
 
54
#define UDPTABLE_IS_LINKED_LIST
 
55
#else
 
56
 
 
57
#ifdef WIN32
 
58
#include <iphlpapi.h>
 
59
#define UDPTABLE_ENTRY_TYPE     MIB_UDPROW              /* ??? */
 
60
#define UDPTABLE_LOCALADDRESS   dwLocalAddr
 
61
#define UDPTABLE_LOCALPORT      dwLocalPort 
 
62
#define UDPTABLE_IS_TABLE
 
63
#else                   /* everything else */
 
64
 
 
65
#ifdef linux
 
66
#define INP_NEXT_SYMBOL         inp_next
 
67
#endif
 
68
#define UDPTABLE_ENTRY_TYPE     struct inpcb 
 
69
#define UDPTABLE_LOCALADDRESS   inp_laddr.s_addr 
 
70
#define UDPTABLE_LOCALPORT      inp_lport
 
71
#define UDPTABLE_IS_LINKED_LIST
 
72
 
 
73
#endif                          /* WIN32 */
 
74
#endif                          /* solaris2 */
 
75
#endif                          /* hpux11 */
 
76
 
 
77
                                /* Head of linked list, or root of table */
 
78
UDPTABLE_ENTRY_TYPE     *udp_head  = NULL;
 
79
int                      udp_size  = 0; /* Only used for table-based systems */
 
80
 
 
81
 
 
82
        /*
 
83
         *
 
84
         * Initialization and handler routines are common to all architectures
 
85
         *
 
86
         */
 
87
#ifndef MIB_STATS_CACHE_TIMEOUT
 
88
#define MIB_STATS_CACHE_TIMEOUT 5
 
89
#endif
 
90
#ifndef UDP_STATS_CACHE_TIMEOUT
 
91
#define UDP_STATS_CACHE_TIMEOUT MIB_STATS_CACHE_TIMEOUT
 
92
#endif
 
93
 
 
94
oid             udpTable_oid[] = { SNMP_OID_MIB2, 7, 5 };
 
95
 
 
96
void
 
97
init_udpTable(void)
 
98
{
 
99
    netsnmp_table_registration_info *table_info;
 
100
    netsnmp_iterator_info           *iinfo;
 
101
    netsnmp_handler_registration    *reginfo;
 
102
 
 
103
    DEBUGMSGTL(("mibII/udpTable", "Initialising UDP Table\n"));
 
104
    /*
 
105
     * Create the table data structure, and define the indexing....
 
106
     */
 
107
    table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
 
108
    if (!table_info) {
 
109
        return;
 
110
    }
 
111
    netsnmp_table_helper_add_indexes(table_info, ASN_IPADDRESS,
 
112
                                                 ASN_INTEGER, 0);
 
113
    table_info->min_column = UDPLOCALADDRESS;
 
114
    table_info->max_column = UDPLOCALPORT;
 
115
 
 
116
 
 
117
    /*
 
118
     * .... and iteration information ....
 
119
     */
 
120
    iinfo      = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
 
121
    if (!iinfo) {
 
122
        return;
 
123
    }
 
124
    iinfo->get_first_data_point = udpTable_first_entry;
 
125
    iinfo->get_next_data_point  = udpTable_next_entry;
 
126
    iinfo->table_reginfo        = table_info;
 
127
#if defined(WIN32) || defined(solaris2)
 
128
    iinfo->flags               |= NETSNMP_ITERATOR_FLAG_SORTED;
 
129
#endif /* WIN32 || solaris2 */
 
130
 
 
131
 
 
132
    /*
 
133
     * .... and register the table with the agent.
 
134
     */
 
135
    reginfo = netsnmp_create_handler_registration("udpTable",
 
136
            udpTable_handler,
 
137
            udpTable_oid, OID_LENGTH(udpTable_oid),
 
138
            HANDLER_CAN_RONLY),
 
139
    netsnmp_register_table_iterator(reginfo, iinfo);
 
140
 
 
141
    /*
 
142
     * .... with a local cache
 
143
     */
 
144
    netsnmp_inject_handler( reginfo,
 
145
                    netsnmp_get_cache_handler(UDP_STATS_CACHE_TIMEOUT,
 
146
                                        udpTable_load, udpTable_free,
 
147
                                        udpTable_oid, OID_LENGTH(udpTable_oid)));
 
148
}
 
149
 
 
150
 
 
151
 
 
152
int
 
153
udpTable_handler(netsnmp_mib_handler          *handler,
 
154
                 netsnmp_handler_registration *reginfo,
 
155
                 netsnmp_agent_request_info   *reqinfo,
 
156
                 netsnmp_request_info         *requests)
 
157
{
 
158
    netsnmp_request_info  *request;
 
159
    netsnmp_variable_list *requestvb;
 
160
    netsnmp_table_request_info *table_info;
 
161
    UDPTABLE_ENTRY_TYPE   *entry;
 
162
    oid      subid;
 
163
    long     port;
 
164
 
 
165
    DEBUGMSGTL(("mibII/udpTable", "Handler - mode %s\n",
 
166
                    se_find_label_in_slist("agent_mode", reqinfo->mode)));
 
167
    switch (reqinfo->mode) {
 
168
    case MODE_GET:
 
169
        for (request=requests; request; request=request->next) {
 
170
            requestvb = request->requestvb;
 
171
            DEBUGMSGTL(( "mibII/udpTable", "oid: "));
 
172
            DEBUGMSGOID(("mibII/udpTable", requestvb->name,
 
173
                                           requestvb->name_length));
 
174
            DEBUGMSG((   "mibII/udpTable", "\n"));
 
175
 
 
176
            entry = (UDPTABLE_ENTRY_TYPE *)netsnmp_extract_iterator_context(request);
 
177
            if (!entry)
 
178
                continue;
 
179
            table_info = netsnmp_extract_table_info(request);
 
180
            subid      = table_info->colnum;
 
181
 
 
182
            switch (subid) {
 
183
            case UDPLOCALADDRESS:
 
184
#if defined(osf5) && defined(IN6_EXTRACT_V4ADDR)
 
185
                snmp_set_var_typed_value(requestvb, ASN_IPADDRESS,
 
186
                              (u_char*)IN6_EXTRACT_V4ADDR(pcb->inp_laddr),
 
187
                                sizeof(IN6_EXTRACT_V4ADDR(pcb->inp_laddr)));
 
188
#else
 
189
                snmp_set_var_typed_value(requestvb, ASN_IPADDRESS,
 
190
                                 (u_char *)&entry->UDPTABLE_LOCALADDRESS,
 
191
                                     sizeof(entry->UDPTABLE_LOCALADDRESS));
 
192
#endif
 
193
                break;
 
194
            case UDPLOCALPORT:
 
195
                port = ntohs((u_short)entry->UDPTABLE_LOCALPORT);
 
196
                snmp_set_var_typed_value(requestvb, ASN_INTEGER,
 
197
                                 (u_char *)&port, sizeof(port));
 
198
                break;
 
199
            }
 
200
        }
 
201
        break;
 
202
 
 
203
    case MODE_GETNEXT:
 
204
    case MODE_GETBULK:
 
205
    case MODE_SET_RESERVE1:
 
206
    case MODE_SET_RESERVE2:
 
207
    case MODE_SET_ACTION:
 
208
    case MODE_SET_COMMIT:
 
209
    case MODE_SET_FREE:
 
210
    case MODE_SET_UNDO:
 
211
        snmp_log(LOG_WARNING, "mibII/udpTable: Unsupported mode (%d)\n",
 
212
                               reqinfo->mode);
 
213
        break;
 
214
    default:
 
215
        snmp_log(LOG_WARNING, "mibII/udpTable: Unrecognised mode (%d)\n",
 
216
                               reqinfo->mode);
 
217
        break;
 
218
    }
 
219
 
 
220
    return SNMP_ERR_NOERROR;
 
221
}
 
222
 
 
223
        /*
 
224
         * Two forms of iteration hook routines:
 
225
         *    One for when the UDP table is stored as a table
 
226
         *    One for when the UDP table is stored as a linked list
 
227
         *
 
228
         * Also applies to the cache-handler free routine
 
229
         */
 
230
 
 
231
#ifdef  UDPTABLE_IS_TABLE
 
232
netsnmp_variable_list *
 
233
udpTable_first_entry(void **loop_context,
 
234
                     void **data_context,
 
235
                     netsnmp_variable_list *index,
 
236
                     netsnmp_iterator_info *data)
 
237
{
 
238
    /*
 
239
     * XXX - How can we tell if the cache is valid?
 
240
     *       No access to 'reqinfo'
 
241
     */
 
242
    if (udp_size == 0)
 
243
        return NULL;
 
244
 
 
245
    /*
 
246
     * Point to the first entry, and use the
 
247
     * 'next_entry' hook to retrieve this row
 
248
     */
 
249
    *loop_context = 0;
 
250
    return udpTable_next_entry( loop_context, data_context, index, data );
 
251
}
 
252
 
 
253
netsnmp_variable_list *
 
254
udpTable_next_entry( void **loop_context,
 
255
                     void **data_context,
 
256
                     netsnmp_variable_list *index,
 
257
                     netsnmp_iterator_info *data)
 
258
{
 
259
    int i = (int)*loop_context;
 
260
    long port;
 
261
 
 
262
    if (udp_size < i)
 
263
        return NULL;
 
264
 
 
265
    /*
 
266
     * Set up the indexing for the specified row...
 
267
     */
 
268
    snmp_set_var_value(index, (u_char *)&udp_head[i].UDPTABLE_LOCALADDRESS,
 
269
                                  sizeof(udp_head[i].UDPTABLE_LOCALADDRESS));
 
270
    port = ntohs((u_short)udp_head[i].UDPTABLE_LOCALPORT);
 
271
    snmp_set_var_value(index->next_variable,
 
272
                               (u_char*)&port, sizeof(port));
 
273
    /*
 
274
     * ... return the data structure for this row,
 
275
     * and update the loop context ready for the next one.
 
276
     */
 
277
    *data_context = (void*)&udp_head[i];
 
278
    *loop_context = (void*)++i;
 
279
    return index;
 
280
}
 
281
 
 
282
void
 
283
udpTable_free(netsnmp_cache *cache, void *magic)
 
284
{
 
285
#ifdef WIN32
 
286
    if (udp_head) {
 
287
                /* the allocated structure is a count followed by table entries */
 
288
                free((char *)(udp_head) - sizeof(DWORD));
 
289
        }
 
290
#else
 
291
    if (udp_head)
 
292
        free(udp_head);
 
293
#endif
 
294
    udp_head = NULL;
 
295
    udp_size = 0;
 
296
}
 
297
#else
 
298
#ifdef UDPTABLE_IS_LINKED_LIST
 
299
netsnmp_variable_list *
 
300
udpTable_first_entry(void **loop_context,
 
301
                     void **data_context,
 
302
                     netsnmp_variable_list *index,
 
303
                     netsnmp_iterator_info *data)
 
304
{
 
305
    /*
 
306
     * XXX - How can we tell if the cache is valid?
 
307
     *       No access to 'reqinfo'
 
308
     */
 
309
    if (udp_head == 0)
 
310
        return NULL;
 
311
 
 
312
    /*
 
313
     * Point to the first entry, and use the
 
314
     * 'next_entry' hook to retrieve this row
 
315
     */
 
316
    *loop_context = (void*)udp_head;
 
317
    return udpTable_next_entry( loop_context, data_context, index, data );
 
318
}
 
319
 
 
320
netsnmp_variable_list *
 
321
udpTable_next_entry( void **loop_context,
 
322
                     void **data_context,
 
323
                     netsnmp_variable_list *index,
 
324
                     netsnmp_iterator_info *data)
 
325
{
 
326
    UDPTABLE_ENTRY_TYPE  *entry = (UDPTABLE_ENTRY_TYPE *)*loop_context;
 
327
    long port;
 
328
 
 
329
    if (!entry)
 
330
        return NULL;
 
331
 
 
332
    /*
 
333
     * Set up the indexing for the specified row...
 
334
     */
 
335
#if defined(osf5) && defined(IN6_EXTRACT_V4ADDR)
 
336
                snmp_set_var_value(index,
 
337
                              (u_char*)&IN6_EXTRACT_V4ADDR(entry->inp_laddr),
 
338
                                 sizeof(IN6_EXTRACT_V4ADDR(entry->inp_laddr)));
 
339
#else
 
340
    snmp_set_var_value(index, (u_char*)&entry->UDPTABLE_LOCALADDRESS,
 
341
                                 sizeof(entry->UDPTABLE_LOCALADDRESS));
 
342
#endif
 
343
    port = ntohs(entry->UDPTABLE_LOCALPORT);
 
344
    snmp_set_var_value(index->next_variable,
 
345
                               (u_char*)&port, sizeof(port));
 
346
 
 
347
    /*
 
348
     * ... return the data structure for this row,
 
349
     * and update the loop context ready for the next one.
 
350
     */
 
351
    *data_context = (void*)entry;
 
352
    *loop_context = (void*)entry->INP_NEXT_SYMBOL;
 
353
    return index;
 
354
}
 
355
 
 
356
void
 
357
udpTable_free(netsnmp_cache *cache, void *magic)
 
358
{
 
359
    UDPTABLE_ENTRY_TYPE  *p;
 
360
    while (udp_head) {
 
361
        p = udp_head;
 
362
        udp_head = udp_head->INP_NEXT_SYMBOL;
 
363
        free(p);
 
364
    }
 
365
 
 
366
    udp_head = NULL;
 
367
}
 
368
#endif          /* UDPTABLE_IS_LINKED_LIST */
 
369
#endif          /* UDPTABLE_IS_TABLE */
 
370
 
 
371
 
 
372
        /*
 
373
         *
 
374
         * The cache-handler loading routine is the main
 
375
         *    place for architecture-specific code
 
376
         *
 
377
         * Load into either a table structure, or a linked list
 
378
         *    depending on the system architecture
 
379
         */
 
380
 
 
381
 
 
382
#ifdef hpux11
 
383
int
 
384
udpTable_load(netsnmp_cache *cache, void *vmagic)
 
385
{
 
386
    int             fd;
 
387
    struct nmparms  p;
 
388
    int             val = 0;
 
389
    unsigned int    ulen;
 
390
    int             ret;
 
391
 
 
392
    udpTable_free(NULL, NULL);
 
393
 
 
394
    if ((fd = open_mib("/dev/ip", O_RDONLY, 0, NM_ASYNC_OFF)) >= 0) {
 
395
        p.objid = ID_udpLsnNumEnt;
 
396
        p.buffer = (void *) &val;
 
397
        ulen = sizeof(int);
 
398
        p.len = &ulen;
 
399
        if ((ret = get_mib_info(fd, &p)) == 0)
 
400
            udp_size = val;
 
401
 
 
402
        if (udp_size > 0) {
 
403
            ulen = (unsigned) udp_size *sizeof(mib_udpLsnEnt);
 
404
            udp_head = (mib_udpLsnEnt *) malloc(ulen);
 
405
            p.objid = ID_udpLsnTable;
 
406
            p.buffer = (void *) udp_head;
 
407
            p.len = &ulen;
 
408
            if ((ret = get_mib_info(fd, &p)) < 0) {
 
409
                udp_size = 0;
 
410
            }
 
411
        }
 
412
 
 
413
        close_mib(fd);
 
414
    }
 
415
 
 
416
    if (udp_size > 0) {
 
417
        DEBUGMSGTL(("mibII/udpTable", "Loaded UDP Table\n"));
 
418
        return 0;
 
419
    }
 
420
    DEBUGMSGTL(("mibII/udpTable", "Failed to load UDP Table (hpux11)\n"));
 
421
    return -1;
 
422
}
 
423
#else                           /* hpux11 */
 
424
 
 
425
#ifdef linux
 
426
int
 
427
udpTable_load(netsnmp_cache *cache, void *vmagic)
 
428
{
 
429
    FILE           *in;
 
430
    char            line[256];
 
431
 
 
432
    udpTable_free(cache, NULL);
 
433
 
 
434
    if (!(in = fopen("/proc/net/udp", "r"))) {
 
435
        DEBUGMSGTL(("mibII/udpTable", "Failed to load UDP Table (linux1)\n"));
 
436
        snmp_log(LOG_ERR, "snmpd: cannot open /proc/net/udp ...\n");
 
437
        return -1;
 
438
    }
 
439
 
 
440
    /*
 
441
     * scan proc-file and build up a linked list 
 
442
     * This will actually be built up in reverse,
 
443
     *   but since the entries are unsorted, that doesn't matter.
 
444
     */
 
445
    while (line == fgets(line, sizeof(line), in)) {
 
446
        struct inpcb    pcb, *nnew;
 
447
        unsigned int    state, lport;
 
448
 
 
449
        if (3 != sscanf(line, "%*d: %x:%x %*x:%*x %x",
 
450
                        &pcb.inp_laddr.s_addr, &lport, &state))
 
451
            continue;
 
452
 
 
453
        if (state != 7)         /* fix me:  UDP_LISTEN ??? */
 
454
            continue;
 
455
 
 
456
        pcb.inp_lport = htons((unsigned short) (lport));
 
457
        pcb.inp_fport = htons(pcb.inp_fport);
 
458
 
 
459
        nnew = SNMP_MALLOC_TYPEDEF(struct inpcb);
 
460
        if (nnew == NULL)
 
461
            break;
 
462
        memcpy(nnew, &pcb, sizeof(struct inpcb));
 
463
        nnew->inp_next = udp_head;
 
464
        udp_head       = nnew;
 
465
    }
 
466
 
 
467
    fclose(in);
 
468
 
 
469
    DEBUGMSGTL(("mibII/udpTable", "Loaded UDP Table\n"));
 
470
    return 0;
 
471
}
 
472
#else                           /* linux */
 
473
 
 
474
#ifdef solaris2
 
475
static int
 
476
UDP_Cmp(void *addr, void *ep)
 
477
{
 
478
    if (memcmp((mib2_udpEntry_t *) ep, (mib2_udpEntry_t *) addr,
 
479
               sizeof(mib2_udpEntry_t)) == 0)
 
480
        return (0);
 
481
    else
 
482
        return (1);
 
483
}
 
484
 
 
485
 
 
486
int
 
487
udpTable_load(netsnmp_cache *cache, void *vmagic)
 
488
{
 
489
    mib2_udpEntry_t   entry;
 
490
    netsnmp_udpEntry *nnew;
 
491
    netsnmp_udpEntry *prev_entry = NULL;
 
492
 
 
493
 
 
494
    udpTable_free(NULL, NULL);
 
495
 
 
496
    if (getMibstat(MIB_UDP_LISTEN, &entry, sizeof(mib2_udpEntry_t),
 
497
                   GET_FIRST, &UDP_Cmp, &entry) != 0) {
 
498
        DEBUGMSGTL(("mibII/udpTable", "Failed to load UDP Table (solaris)\n"));
 
499
        return -1;
 
500
    }
 
501
 
 
502
    while (1) {
 
503
        /*
 
504
         * Not interested in 'idle' entries, apparently....
 
505
         */
 
506
        if (entry.udpEntryInfo.ue_state != MIB2_UDP_idle) {
 
507
            /*
 
508
             * Build up a linked list copy of the getMibstat results
 
509
             * Note that since getMibstat returns rows in sorted order,
 
510
             *    we need to retain this order while building the list
 
511
             *    so new entries are added onto the end of the list.
 
512
             */
 
513
            nnew = SNMP_MALLOC_TYPEDEF(netsnmp_udpEntry);
 
514
            if (nnew == NULL)
 
515
                break;
 
516
            memcpy(&(nnew->entry), &entry, sizeof(mib2_udpEntry_t));
 
517
            if (!prev_entry)
 
518
                udp_head = nnew;
 
519
            else
 
520
                prev_entry->inp_next = nnew;
 
521
            prev_entry = nnew;
 
522
        }
 
523
 
 
524
        if (getMibstat(MIB_UDP_LISTEN, &entry, sizeof(mib2_udpEntry_t),
 
525
                       GET_NEXT, &UDP_Cmp, &entry) != 0)
 
526
            break;
 
527
    }
 
528
 
 
529
    if (udp_head) {
 
530
        DEBUGMSGTL(("mibII/udpTable", "Loaded UDP Table\n"));
 
531
        return 0;
 
532
    }
 
533
    DEBUGMSGTL(("mibII/udpTable", "Failed to load UDP Table (solaris)\n"));
 
534
    return -1;
 
535
}
 
536
#else                           /* solaris2 */
 
537
 
 
538
#ifdef WIN32
 
539
int
 
540
udpTable_load(netsnmp_cache *cache, void *vmagic)
 
541
{
 
542
    PMIB_UDPTABLE pUdpTable = NULL;
 
543
    DWORD         dwActualSize = 0;
 
544
    DWORD         status = NO_ERROR;
 
545
 
 
546
    /*
 
547
     * query for the buffer size needed 
 
548
     */
 
549
    status = GetUdpTable(pUdpTable, &dwActualSize, TRUE);
 
550
    if (status == ERROR_INSUFFICIENT_BUFFER) {
 
551
        pUdpTable = (PMIB_UDPTABLE) malloc(dwActualSize);
 
552
        if (pUdpTable != NULL) {
 
553
            /*
 
554
             * Get the sorted UDP table 
 
555
             */
 
556
            status = GetUdpTable(pUdpTable, &dwActualSize, TRUE);
 
557
        }
 
558
    }
 
559
    if (status == NO_ERROR) {
 
560
        DEBUGMSGTL(("mibII/udpTable", "Loaded UDP Table\n"));
 
561
        udp_size = pUdpTable->dwNumEntries -1;  /* entries are counted starting with 0 */
 
562
        udp_head = pUdpTable->table;
 
563
        return 0;
 
564
    }
 
565
    DEBUGMSGTL(("mibII/udpTable", "Failed to load UDP Table (win32)\n"));
 
566
    if (pUdpTable)
 
567
        free(pUdpTable);
 
568
    return -1;
 
569
}
 
570
#else                           /* WIN32 */
 
571
 
 
572
#if (defined(CAN_USE_SYSCTL) && defined(UDPCTL_PCBLIST))
 
573
int
 
574
udpTable_load(netsnmp_cache *cache, void *vmagic)
 
575
{
 
576
    size_t   len;
 
577
    int      sname[] = { CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_PCBLIST };
 
578
    char     *udpcb_buf = NULL;
 
579
    struct xinpgen *xig = NULL;
 
580
    struct inpcb   *nnew;
 
581
 
 
582
    udpTable_free(NULL, NULL);
 
583
 
 
584
    /*
 
585
     *  Read in the buffer containing the UDP table data
 
586
     */
 
587
    len = 0;
 
588
    if (sysctl(sname, 4, 0, &len, 0, 0) < 0 ||
 
589
       (udpcb_buf = malloc(len)) == NULL)
 
590
        return -1;
 
591
    if (sysctl(sname, 4, udpcb_buf, &len, 0, 0) < 0) {
 
592
        free(udpcb_buf);
 
593
        return -1;
 
594
    }
 
595
 
 
596
    /*
 
597
     *  Unpick this into the constituent 'xinpgen' structures, and extract
 
598
     *     the 'inpcb' elements into a linked list (built in reverse)
 
599
     */
 
600
    xig = (struct xinpgen *) udpcb_buf;
 
601
    xig = (struct xinpgen *) ((char *) xig + xig->xig_len);
 
602
 
 
603
    while (xig && (xig->xig_len > sizeof(struct xinpgen))) {
 
604
        nnew = SNMP_MALLOC_TYPEDEF(struct inpcb);
 
605
        if (!nnew)
 
606
            break;
 
607
        memcpy(nnew, ((struct xinpcb *) xig)->xi_inp, sizeof(struct inpcb));
 
608
 
 
609
        nnew->next = udp_head;          /* XXX - ?? Check 'next' pointer */
 
610
        udp_head   = nnew;
 
611
        xig = (struct xinpgen *) ((char *) xig + xig->xig_len);
 
612
    }
 
613
 
 
614
    free(udpcb_buf);
 
615
    if (udp_head) {
 
616
        DEBUGMSGTL(("mibII/udpTable", "Loaded UDP Table\n"));
 
617
        return 0;
 
618
    }
 
619
    DEBUGMSGTL(("mibII/udpTable", "Failed to load UDP Table (sysctl)\n"));
 
620
    return -1;
 
621
}
 
622
#else           /* (defined(CAN_USE_SYSCTL) && defined(UDPCTL_PCBLIST)) */
 
623
#ifdef PCB_TABLE
 
624
int
 
625
udpTable_load(netsnmp_cache *cache, void *vmagic)
 
626
{
 
627
    struct inpcbtable table;
 
628
    struct inpcb   *nnew, *entry;
 
629
 
 
630
    udpTable_free(NULL, NULL);
 
631
 
 
632
    if (!auto_nlist(UDB_SYMBOL, (char *) &table, sizeof(table))) {
 
633
        DEBUGMSGTL(("mibII/udpTable", "Failed to read inpcbtable\n"));
 
634
        return -1;
 
635
    }
 
636
 
 
637
    /*
 
638
     *  Set up a linked list
 
639
     */
 
640
    entry  = table.inpt_queue.cqh_first;
 
641
    while (entry) {
 
642
   
 
643
        nnew = SNMP_MALLOC_TYPEDEF(struct inpcb);
 
644
        if (!nnew)
 
645
            break;
 
646
        klookup((unsigned long) entry, (char *) nnew, sizeof(struct inpcb));
 
647
 
 
648
        entry    = nnew->inp_queue.cqe_next;    /* Next kernel entry */
 
649
        nnew->inp_queue.cqe_next = udp_head;
 
650
        udp_head = nnew;
 
651
 
 
652
        if (entry == table.inpt_queue.cqh_first)
 
653
            break;
 
654
    }
 
655
 
 
656
    if (udp_head) {
 
657
        DEBUGMSGTL(("mibII/udpTable", "Loaded UDP Table\n"));
 
658
        return 0;
 
659
    }
 
660
    DEBUGMSGTL(("mibII/udpTable", "Failed to load UDP Table (pcb_table)\n"));
 
661
    return -1;
 
662
}
 
663
 
 
664
#else                           /* PCB_TABLE */
 
665
#ifdef UDB_SYMBOL
 
666
int
 
667
udpTable_load(netsnmp_cache *cache, void *vmagic)
 
668
{
 
669
    struct inpcb   udp_inpcb;
 
670
    struct inpcb   *nnew, *entry;
 
671
 
 
672
    udpTable_free(NULL, NULL);
 
673
 
 
674
    if (!auto_nlist(UDB_SYMBOL, (char *) &udp_inpcb, sizeof(udp_inpcb))) {
 
675
        DEBUGMSGTL(("mibII/udpTable", "Failed to read udb_symbol\n"));
 
676
        return -1;
 
677
    }
 
678
 
 
679
    /*
 
680
     *  Set up a linked list
 
681
     */
 
682
    entry  = udp_inpcb.INP_NEXT_SYMBOL;
 
683
    while (entry) {
 
684
   
 
685
        nnew = SNMP_MALLOC_TYPEDEF(struct inpcb);
 
686
        if (!nnew)
 
687
            break;
 
688
        klookup((unsigned long) entry, (char *) nnew, sizeof(struct inpcb));
 
689
 
 
690
        entry    = nnew->INP_NEXT_SYMBOL;               /* Next kernel entry */
 
691
        nnew->INP_NEXT_SYMBOL = udp_head;
 
692
        udp_head = nnew;
 
693
 
 
694
        if (entry == udp_inpcb.INP_NEXT_SYMBOL)
 
695
            break;
 
696
    }
 
697
 
 
698
    if (udp_head) {
 
699
        DEBUGMSGTL(("mibII/udpTable", "Loaded UDP Table\n"));
 
700
        return 0;
 
701
    }
 
702
    DEBUGMSGTL(("mibII/udpTable", "Failed to load UDP Table (udb_symbol)\n"));
 
703
    return -1;
 
704
}
 
705
 
 
706
#else                           /* UDB_SYMBOL */
 
707
int
 
708
udpTable_load(netsnmp_cache *cache, void *vmagic)
 
709
{
 
710
    DEBUGMSGTL(("mibII/udpTable", "Loading UDP Table not implemented\n"));
 
711
    return -1;
 
712
}
 
713
#endif                          /* UDB_SYMBOL */
 
714
#endif                          /* PCB_TABLE */
 
715
#endif          /* (defined(CAN_USE_SYSCTL) && defined(UDPCTL_PCBLIST)) */
 
716
#endif                          /* WIN32 */
 
717
#endif                          /* linux */
 
718
#endif                          /* solaris2 */
 
719
#endif                          /* hpux11 */