Exemplo n.º 1
0
int
udpTable_load(netsnmp_cache *cache, void *vmagic)
{
    size_t   len;
    int      sname[] = { CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_PCBLIST };
    char     *udpcb_buf = NULL;
    struct xinpgen *xig = NULL;
    UDPTABLE_ENTRY_TYPE  *nnew;

    udpTable_free(NULL, NULL);

    /*
     *  Read in the buffer containing the UDP table data
     */
    len = 0;
    if (sysctl(sname, 4, 0, &len, 0, 0) < 0 ||
            (udpcb_buf = malloc(len)) == NULL)
        return -1;
    if (sysctl(sname, 4, udpcb_buf, &len, 0, 0) < 0) {
        free(udpcb_buf);
        return -1;
    }

    /*
     *  Unpick this into the constituent 'xinpgen' structures, and extract
     *     the 'inpcb' elements into a linked list (built in reverse)
     */
    xig = (struct xinpgen *) udpcb_buf;
    xig = (struct xinpgen *) ((char *) xig + xig->xig_len);

    while (xig && (xig->xig_len > sizeof(struct xinpgen))) {
        nnew = SNMP_MALLOC_TYPEDEF(UDPTABLE_ENTRY_TYPE);
        if (!nnew)
            break;
#if defined(freebsd4) || defined(darwin)
        memcpy(nnew, &((struct xinpcb *) xig)->xi_inp, sizeof(struct inpcb));
        nnew->inp_next = udp_head;
#else
        memcpy(nnew, ((struct xinpcb *) xig)->xi_inp, sizeof(struct inpcb));
        nnew->next = udp_head;		/* XXX - ?? Check 'next' pointer */
#endif

        udp_head   = nnew;
        xig = (struct xinpgen *) ((char *) xig + xig->xig_len);
    }

    free(udpcb_buf);
    if (udp_head) {
        DEBUGMSGTL(("mibII/udpTable", "Loaded UDP Table\n"));
        return 0;
    }
    DEBUGMSGTL(("mibII/udpTable", "Failed to load UDP Table (sysctl)\n"));
    return -1;
}
Exemplo n.º 2
0
int
udpTable_load(netsnmp_cache *cache, void *vmagic)
{
    mib2_udpEntry_t   entry;
    netsnmp_udpEntry *nnew;
    netsnmp_udpEntry *prev_entry = NULL;


    udpTable_free(NULL, NULL);

    if (getMibstat(MIB_UDP_LISTEN, &entry, sizeof(mib2_udpEntry_t),
                   GET_FIRST, &UDP_Cmp, &entry) != 0) {
        DEBUGMSGTL(("mibII/udpTable", "Failed to load UDP Table (solaris)\n"));
        return -1;
    }

    while (1) {
        /*
         * Not interested in 'idle' entries, apparently....
         */
        DEBUGMSGTL(("mibII/udpTable", "UDP Entry %x:%d (%d)\n",
                     entry.udpLocalAddress, entry.udpLocalPort, entry.udpEntryInfo.ue_state));
        if (entry.udpEntryInfo.ue_state == MIB2_UDP_idle) {
            /*
             * Build up a linked list copy of the getMibstat results
             * Note that since getMibstat returns rows in sorted order,
	     *    we need to retain this order while building the list
	     *    so new entries are added onto the end of the list.
             * xxx-rks: WARNING: this is NOT TRUE on the sf cf solaris boxes.
             */
            nnew = SNMP_MALLOC_TYPEDEF(netsnmp_udpEntry);
            if (nnew == NULL)
                break;
            memcpy(&(nnew->entry), &entry, sizeof(mib2_udpEntry_t));
            if (!prev_entry)
	        udp_head = nnew;
	    else
	        prev_entry->inp_next = nnew;
	    prev_entry = nnew;
	}

        if (getMibstat(MIB_UDP_LISTEN, &entry, sizeof(mib2_udpEntry_t),
                       GET_NEXT, &UDP_Cmp, &entry) != 0)
	    break;
    }

    if (udp_head) {
        DEBUGMSGTL(("mibII/udpTable", "Loaded UDP Table\n"));
        return 0;
    }
    DEBUGMSGTL(("mibII/udpTable", "Failed to load UDP Table (solaris)\n"));
    return -1;
}
Exemplo n.º 3
0
int
udpTable_load(netsnmp_cache *cache, void *vmagic)
{
    FILE           *in;
    char            line[256];

    udpTable_free(cache, NULL);

    if (!(in = fopen("/proc/net/udp", "r"))) {
        DEBUGMSGTL(("mibII/udpTable", "Failed to load UDP Table (linux)\n"));
        snmp_log(LOG_ERR, "snmpd: cannot open /proc/net/udp ...\n");
        return -1;
    }

    /*
     * scan proc-file and build up a linked list
     * This will actually be built up in reverse,
     *   but since the entries are unsorted, that doesn't matter.
     */
    while (line == fgets(line, sizeof(line), in)) {
        struct inpcb    pcb, *nnew;
        unsigned int    state, lport;

        if (3 != sscanf(line, "%*d: %x:%x %*x:%*x %x",
                        &pcb.inp_laddr.s_addr, &lport, &state))
            continue;

        if (state != 7)         /* fix me:  UDP_LISTEN ??? */
            continue;

        /* store in network byte order */
        pcb.inp_laddr.s_addr = htonl(pcb.inp_laddr.s_addr);
        pcb.inp_lport = htons((unsigned short) (lport));

        nnew = SNMP_MALLOC_TYPEDEF(struct inpcb);
        if (nnew == NULL)
            break;
        memcpy(nnew, &pcb, sizeof(struct inpcb));
        nnew->inp_next = udp_head;
        udp_head       = nnew;
    }

    fclose(in);

    DEBUGMSGTL(("mibII/udpTable", "Loaded UDP Table\n"));
    return 0;
}
Exemplo n.º 4
0
int
udpTable_load(netsnmp_cache *cache, void *vmagic)
{
    struct inpcb   udp_inpcb;
    struct inpcb   *nnew, *entry;

    udpTable_free(NULL, NULL);

    if (!auto_nlist(UDB_SYMBOL, (char *) &udp_inpcb, sizeof(udp_inpcb))) {
        DEBUGMSGTL(("mibII/udpTable", "Failed to read udb_symbol\n"));
        return -1;
    }

    /*
     *  Set up a linked list
     */
    entry  = udp_inpcb.INP_NEXT_SYMBOL;
    while (entry) {
   
        nnew = SNMP_MALLOC_TYPEDEF(struct inpcb);
        if (!nnew)
            break;

        if (!NETSNMP_KLOOKUP(entry, (char *) nnew, sizeof(struct inpcb))) {
            DEBUGMSGTL(("mibII/udpTable:udpTable_load", "klookup failed\n"));
            break;
        }

        entry    = nnew->INP_NEXT_SYMBOL;		/* Next kernel entry */
	nnew->INP_NEXT_SYMBOL = udp_head;
	udp_head = nnew;

        if (entry == udp_inpcb.INP_NEXT_SYMBOL)
            break;
    }

    if (udp_head) {
        DEBUGMSGTL(("mibII/udpTable", "Loaded UDP Table\n"));
        return 0;
    }
    DEBUGMSGTL(("mibII/udpTable", "Failed to load UDP Table (udb_symbol)\n"));
    return -1;
}
Exemplo n.º 5
0
int
udpTable_load(netsnmp_cache *cache, void *vmagic)
{
    struct inpcbtable table;
    struct inpcb   *nnew, *entry;

    udpTable_free(NULL, NULL);

    if (!auto_nlist(UDB_SYMBOL, (char *) &table, sizeof(table))) {
        DEBUGMSGTL(("mibII/udpTable", "Failed to read inpcbtable\n"));
        return -1;
    }

    /*
     *  Set up a linked list
     */
    entry  = table.inpt_queue.cqh_first;
    while (entry) {
   
        nnew = SNMP_MALLOC_TYPEDEF(struct inpcb);
        if (!nnew)
            break;

        if (!NETSNMP_KLOOKUP(entry, (char *) nnew, sizeof(struct inpcb))) {
            DEBUGMSGTL(("mibII/udpTable:udpTable_load", "klookup failed\n"));
            break;
        }

        entry    = nnew->inp_queue.cqe_next;	/* Next kernel entry */
	nnew->inp_queue.cqe_next = udp_head;
	udp_head = nnew;

        if (entry == table.inpt_queue.cqh_first)
            break;
    }

    if (udp_head) {
        DEBUGMSGTL(("mibII/udpTable", "Loaded UDP Table\n"));
        return 0;
    }
    DEBUGMSGTL(("mibII/udpTable", "Failed to load UDP Table (pcb_table)\n"));
    return -1;
}
Exemplo n.º 6
0
int
udpTable_load(netsnmp_cache *cache, void *vmagic)
{
    int             fd;
    struct nmparms  p;
    int             val = 0;
    unsigned int    ulen;
    int             ret;

    udpTable_free(NULL, NULL);

    if ((fd = open_mib("/dev/ip", O_RDONLY, 0, NM_ASYNC_OFF)) >= 0) {
        p.objid = ID_udpLsnNumEnt;
        p.buffer = (void *) &val;
        ulen = sizeof(int);
        p.len = &ulen;
        if ((ret = get_mib_info(fd, &p)) == 0)
            udp_size = val;

        if (udp_size > 0) {
            ulen = (unsigned) udp_size *sizeof(mib_udpLsnEnt);
            udp_head = (mib_udpLsnEnt *) malloc(ulen);
            p.objid = ID_udpLsnTable;
            p.buffer = (void *) udp_head;
            p.len = &ulen;
            if ((ret = get_mib_info(fd, &p)) < 0) {
                udp_size = 0;
            }
        }

        close_mib(fd);
    }

    if (udp_size > 0) {
        DEBUGMSGTL(("mibII/udpTable", "Loaded UDP Table\n"));
        return 0;
    }
    DEBUGMSGTL(("mibII/udpTable", "Failed to load UDP Table (hpux11)\n"));
    return -1;
}