コード例 #1
0
ファイル: tcpTable.c プロジェクト: vincentbernat/net-snmp
int
tcpTable_load(netsnmp_cache *cache, void *vmagic)
{
    struct inpcb   tcp_inpcb;
    struct tcpcb   tcpcb;
    netsnmp_inpcb  *nnew;
    struct inpcb   *entry;
#ifdef hpux
    int      StateMap[] = { 1, 2, 3, -1, 4, 5, 8, 6, 10, 9, 7, 11 };
#else
    int      StateMap[] = { 1, 2, 3,     4, 5, 8, 6, 10, 9, 7, 11 };
#endif

    tcpTable_free(NULL, NULL);

    if (!auto_nlist(TCP_SYMBOL, (char *) &tcp_inpcb, sizeof(tcp_inpcb))) {
        DEBUGMSGTL(("mibII/tcpTable", "Failed to read tcp_symbol\n"));
        return -1;
    }

    /*
     *  Set up a linked list
     */
    entry  = tcp_inpcb.INP_NEXT_SYMBOL;
    while (entry) {

        nnew = SNMP_MALLOC_TYPEDEF(netsnmp_inpcb);
        if (!nnew)
            break;
        if (!NETSNMP_KLOOKUP(entry, (char *)&(nnew->pcb), sizeof(struct inpcb))) {
            DEBUGMSGTL(("mibII/tcpTable:tcpTable_load", "klookup failed\n"));
            break;
        }
        if (!NETSNMP_KLOOKUP(nnew->pcb.inp_ppcb, (char *)&tcpcb, sizeof(struct tcpcb))) {
            DEBUGMSGTL(("mibII/tcpTable:tcpTable_load", "klookup failed\n"));
            break;
        }
        nnew->state    = StateMap[tcpcb.t_state];
        if (nnew->state == 5 /* established */ ||
                nnew->state == 8 /*  closeWait  */ )
            tcp_estab++;

        entry          = nnew->pcb.INP_NEXT_SYMBOL;	/* Next kernel entry */
        nnew->inp_next = tcp_head;
        tcp_head       = nnew;

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

    if (tcp_head) {
        DEBUGMSGTL(("mibII/tcpTable", "Loaded TCP Table (tcp_symbol)\n"));
        return 0;
    }
    DEBUGMSGTL(("mibII/tcpTable", "Failed to load TCP Table (tcp_symbol)\n"));
    return -1;
}
コード例 #2
0
ファイル: udpTable.c プロジェクト: gittestusername/uClinux
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;
}
コード例 #3
0
ファイル: udpTable.c プロジェクト: gittestusername/uClinux
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;
}
コード例 #4
0
ファイル: at.c プロジェクト: pexip/os-net-snmp
static int
ARP_Scan_Next(in_addr_t * IPAddr, char *PhysAddr, int *PhysAddrLen,
              u_long * ifType)
#endif
{
#ifndef NETSNMP_CAN_USE_SYSCTL
#ifdef linux
    if (arptab_current < arptab_size) {
        /*
         * copy values 
         */
        *IPAddr = at[arptab_current].at_iaddr.s_addr;
        *ifType =
            (at[arptab_current].
             at_flags & ATF_PERM) ? 4 /*static */ : 3 /*dynamic */ ;
        *ifIndex = at[arptab_current].if_index;
        memcpy(PhysAddr, &at[arptab_current].at_enaddr,
               sizeof(at[arptab_current].at_enaddr));
        *PhysAddrLen = at[arptab_current].at_enaddr_len;

        /*
         * increment to point next entry 
         */
        arptab_current++;
        /*
         * return success 
         */
        return (1);
    }
#elif defined(hpux11)
    if (arptab_current < arptab_size) {
        /*
         * copy values 
         */
        *IPAddr = at[arptab_current].NetAddr;
        memcpy(PhysAddr, at[arptab_current].PhysAddr.o_bytes,
               at[arptab_current].PhysAddr.o_length);
        *ifType = at[arptab_current].Type;
        *ifIndex = at[arptab_current].IfIndex;
        *PhysAddrLen = at[arptab_current].PhysAddr.o_length;
        /*
         * increment to point next entry 
         */
        arptab_current++;
        /*
         * return success 
         */
        return (1);
    }
#elif !defined(ARP_SCAN_FOUR_ARGUMENTS) || defined(hpux)
    register struct arptab *atab;

    while (arptab_current < arptab_size) {
#ifdef STRUCT_ARPHD_HAS_AT_NEXT
        /*
         * The arp table is an array of linked lists of arptab entries.
         * Unused slots have pointers back to the array entry itself 
         */

        if (at_ptr == (auto_nlist_value(ARPTAB_SYMBOL) +
                       arptab_current * sizeof(struct arphd))) {
            /*
             * Usused 
             */
            arptab_current++;
            at_ptr = at[arptab_current].at_next;
            continue;
        }

        if (!NETSNMP_KLOOKUP(at_ptr, (char *) &at_entry, sizeof(struct arptab))) {
            DEBUGMSGTL(("mibII/at:ARP_Scan_Next", "klookup failed\n"));
            break;
        }

        if (!NETSNMP_KLOOKUP(at_entry.at_ac, (char *) &at_com, sizeof(struct arpcom))) {
            DEBUGMSGTL(("mibII/at:ARP_Scan_Next", "klookup failed\n"));
            break;
        }

        at_ptr = at_entry.at_next;
        atab = &at_entry;
        *ifIndex = at_com.ac_if.if_index;       /* not strictly ARPHD */
#else                           /* STRUCT_ARPHD_HAS_AT_NEXT */
        atab = &at[arptab_current++];
#endif                          /* STRUCT_ARPHD_HAS_AT_NEXT */
        if (!(atab->at_flags & ATF_COM))
            continue;
        *ifType = (atab->at_flags & ATF_PERM) ? 4 : 3;
        *IPAddr = atab->at_iaddr.s_addr;
#if defined (sunV3) || defined(sparc) || defined(hpux)
        memcpy(PhysAddr, (char *) &atab->at_enaddr,
               sizeof(atab->at_enaddr));
        *PhysAddrLen = sizeof(atab->at_enaddr);
#endif
#if defined(mips) || defined(ibm032)
        memcpy(PhysAddr, (char *) atab->at_enaddr,
               sizeof(atab->at_enaddr));
        *PhysAddrLen = sizeof(atab->at_enaddr);
#endif
        return (1);
    }
#endif                          /* linux || hpux11 || !ARP_SCAN_FOUR_ARGUMENTS || hpux */

    return 0;                   /* we need someone with an irix box to fix this section */

#else                           /* !NETSNMP_CAN_USE_SYSCTL */
    struct rt_msghdr *rtm;
    struct sockaddr_inarp *sin;
    struct sockaddr_dl *sdl;

    while (rtnext < lim) {
        rtm = (struct rt_msghdr *) rtnext;
        sin = (struct sockaddr_inarp *) (rtm + 1);
        sdl = (struct sockaddr_dl *) (sin + 1);
        rtnext += rtm->rtm_msglen;
        if (sdl->sdl_alen) {
#ifdef irix6
            *IPAddr = sin->sarp_addr.s_addr;
#else
            *IPAddr = sin->sin_addr.s_addr;
#endif
            memcpy(PhysAddr, (char *) LLADDR(sdl), sdl->sdl_alen);
            *PhysAddrLen = sdl->sdl_alen;
            *ifIndex = sdl->sdl_index;
            *ifType = 1;        /* XXX */
            return (1);
        }
    }
    return (0);                 /* "EOF" */
#endif                          /* !NETSNMP_CAN_USE_SYSCTL */
}
コード例 #5
0
ファイル: swrun_nlist.cpp プロジェクト: duniansampa/SigLog
/* ---------------------------------------------------------------------
 */
int
netsnmp_arch_swrun_container_load( netsnmp_container *container, u_int flags)
{
    struct proc         *proc_table;
    int                  proc_type_base;
    int                  nproc, i, rc;
    netsnmp_swrun_entry *entry;

    auto_nlist( NPROC_SYMBOL, (char *)&nproc, sizeof(int));
    proc_table = (struct proc *) malloc(nproc*(sizeof(struct proc)));

    auto_nlist(  PROC_SYMBOL, (char *)&proc_table_base, sizeof(int));
    NETSNMP_KLOOKUP(proc_table_base, (char *)proc_table, 
                                        nproc*(sizeof(struct proc)));

    for ( i=0 ; i<nproc; i++ ) {
        if (0 == proc_table[i].p_stat)
            continue;	/* Skip unused entries */
        entry = netsnmp_swrun_entry_create(proc_table[i].p_pid);
        if (NULL == entry)
            continue;   /* error already logged by function */
        rc = CONTAINER_INSERT(container, entry);

        /*
         * XXX - What information does 'struct proc' contain?
         */
        
/*
 Apparently no process name/argument information
        entry->hrSWRunName_len = snprintf(entry->hrSWRunName,
                                   sizeof(entry->hrSWRunName)-1,
                                          "%s", proc_table[i].???);
        entry->hrSWRunPath_len = snprintf(entry->hrSWRunPath,
                                   sizeof(entry->hrSWRunPath)-1,
                                          "%s", proc_table[i].???);
        entry->hrSWRunParameters_len = snprintf(entry->hrSWRunParameters,
                                         sizeof(entry->hrSWRunParameters)-1,
                                          "%s", ???);
 */

        switch (proc_table[i].p_stat) {
/* XXX - which names to use ?? */
        case SACTIVE:
        case SRUN:
        case SONPROC: entry->hrSWRunStatus = HRSWRUNSTATUS_RUNNING;
                      break;
        case SSWAP:
        case SSLEEP:
        case SWAIT:   entry->hrSWRunStatus = HRSWRUNSTATUS_RUNNABLE;
                      break;
        case SSTOP:   entry->hrSWRunStatus = HRSWRUNSTATUS_NOTRUNNABLE;
                      break;
        case SIDL:
        case SZOMB:
        default:      entry->hrSWRunStatus = HRSWRUNSTATUS_INVALID;
                      break;
        }


        entry->hrSWRunPerfCPU  = (proc_table[i].p_utime.tv_sec  * 100);
        entry->hrSWRunPerfCPU += (proc_table[i].p_utime.tv_usec / 10000);
        entry->hrSWRunPerfCPU += (proc_table[i].p_stime.tv_sec  * 100);
        entry->hrSWRunPerfCPU += (proc_table[i].p_stime.tv_usec / 10000);
    /*
     or entry->hrSWRunPerfCPU  = proc_table[i].p_time;
     */
    }
    free(proc_table);

    DEBUGMSGTL(("swrun:load:arch"," loaded %d entries\n",
                CONTAINER_SIZE(container)));

    return 0;
}
コード例 #6
0
/**
 *
 * @retval  0 no errors
 * @retval !0 errors
 */
static int
_load(netsnmp_container *container, u_int load_flags)
{
    struct inpcbtable table;
    struct inpcb   *head, *next, *prev;
    struct inpcb   inpcb;
    struct tcpcb   tcpcb;
    int      StateMap[] = { 1, 2, 3, 4, 5, 8, 6, 10, 9, 7, 11 };
    netsnmp_tcpconn_entry  *entry;
    int      state;
    int      rc = 0;

    /*
     *  Read in the buffer containing the TCP table data
     */
    if (!auto_nlist(TCP_SYMBOL, (char *)&table, sizeof(table))) {
	DEBUGMSGTL(("tcp-mib/tcpConn_openbsd", "Failed to read tcp_symbol\n"));
	return -1;
    }

    prev = (struct inpcb *)&CIRCLEQ_FIRST(&table.inpt_queue);
    prev = NULL;
    head = next = CIRCLEQ_FIRST(&table.inpt_queue);

    while (next) {
	if (!NETSNMP_KLOOKUP(next, (char *)&inpcb, sizeof(inpcb))) {
	    DEBUGMSGTL(("tcp-mib/data_access/tcpConn", "klookup inpcb failed\n"));
	    break;
	}
	if (prev && CIRCLEQ_PREV(&inpcb, inp_queue) != prev) {
	    snmp_log(LOG_ERR,"tcbtable link error\n");
	    break;
	}
	prev = next;
	next = CIRCLEQ_NEXT(&inpcb, inp_queue);
	if (!NETSNMP_KLOOKUP(inpcb.inp_ppcb, (char *)&tcpcb, sizeof(tcpcb))) {
	    DEBUGMSGTL(("tcp-mib/data_access/tcpConn", "klookup tcpcb failed\n"));
	    break;
	}
	state = StateMap[tcpcb.t_state];

	if (load_flags) {
	    if (state == TCPCONNECTIONSTATE_LISTEN) {
		if (load_flags & NETSNMP_ACCESS_TCPCONN_LOAD_NOLISTEN) {
		    DEBUGMSGT(("verbose:access:tcpconn:container",
			       " skipping listen\n"));
		    goto skip;
		}
	    }
	    else if (load_flags & NETSNMP_ACCESS_TCPCONN_LOAD_ONLYLISTEN) {
		DEBUGMSGT(("verbose:access:tcpconn:container",
			    " skipping non-listen\n"));
		goto skip;
	    }
	}

#if !defined(NETSNMP_ENABLE_IPV6)
        if (inpcb.inp_flags & INP_IPV6)
	    goto skip;
#endif

        entry = netsnmp_access_tcpconn_entry_create();
        if(NULL == entry) {
            rc = -3;
            break;
        }

        /** oddly enough, these appear to already be in network order */
        entry->loc_port = ntohs(inpcb.inp_lport);
        entry->rmt_port = ntohs(inpcb.inp_fport);
        entry->tcpConnState = state;
        entry->pid = 0;
        
        /** the addr string may need work */
	if (inpcb.inp_flags & INP_IPV6) {
	    entry->loc_addr_len = entry->rmt_addr_len = 16;
	    memcpy(entry->loc_addr, &inpcb.inp_laddr6, 16);
	    memcpy(entry->rmt_addr, &inpcb.inp_faddr6, 16);
	}
	else {
	    entry->loc_addr_len = entry->rmt_addr_len = 4;
	    memcpy(entry->loc_addr, &inpcb.inp_laddr, 4);
	    memcpy(entry->rmt_addr, &inpcb.inp_faddr, 4);
	}
	DEBUGMSGTL(("tcp-mib/data_access", "tcp %d %d %d\n",
	    entry->loc_addr_len, entry->loc_port, entry->rmt_port));

        /*
         * add entry to container
         */
        entry->arbitrary_index = CONTAINER_SIZE(container) + 1;
        CONTAINER_INSERT(container, entry);
skip:
	if (head == next)
	    break;
    }

    if(rc<0)
        return rc;

    return 0;
}
コード例 #7
0
/**
 *
 * @retval  0 no errors
 * @retval !0 errors
 */
static int
_load(netsnmp_container *container, u_int load_flags)
{
    struct inpcbtable table;
    struct inpcb   *head, *next, *prev;
    struct inpcb   inpcb;
    netsnmp_udp_endpoint_entry  *entry;
    int      rc = 0;

    /*
     *  Read in the buffer containing the TCP table data
     */
    if (!auto_nlist(UDB_SYMBOL, (char *) &table, sizeof(table))) {
	DEBUGMSGTL(("udp-mib/udp_endpoint_openbsd", "Failed to read udp_symbol\n"));
	return -1;
    }

    prev = (struct inpcb *)&CIRCLEQ_FIRST(&table.inpt_queue);
    prev = NULL;
    head = next = CIRCLEQ_FIRST(&table.inpt_queue);

    while (next) {
	NETSNMP_KLOOKUP(next, (char *)&inpcb, sizeof(inpcb));
	if (prev && CIRCLEQ_PREV(&inpcb, inp_queue) != prev) {
	    snmp_log(LOG_ERR,"udbtable link error\n");
	    break;
	}
	prev = next;
	next = CIRCLEQ_NEXT(&inpcb, inp_queue);

#if !defined(NETSNMP_ENABLE_IPV6)
        if (inpcb.inp_flags & INP_IPV6)
            goto skip;
#endif
        entry = netsnmp_access_udp_endpoint_entry_create();
        if (NULL == entry) {
            rc = -3;
            break;
        }

        /** oddly enough, these appear to already be in network order */
        entry->loc_port = ntohs(inpcb.inp_lport);
        entry->rmt_port = ntohs(inpcb.inp_fport);
        entry->pid = 0;
        
        /** the addr string may need work */
	if (inpcb.inp_flags & INP_IPV6) {
	    entry->loc_addr_len = entry->rmt_addr_len = 16;
	    memcpy(entry->loc_addr, &inpcb.inp_laddr6, 16);
	    memcpy(entry->rmt_addr, &inpcb.inp_faddr6, 16);
	}
	else {
	    entry->loc_addr_len = entry->rmt_addr_len = 4;
	    memcpy(entry->loc_addr, &inpcb.inp_laddr, 4);
	    memcpy(entry->rmt_addr, &inpcb.inp_faddr, 4);
	}

        /*
         * add entry to container
         */
        entry->index = CONTAINER_SIZE(container) + 1;
        CONTAINER_INSERT(container, entry);
#if !defined(NETSNMP_ENABLE_IPV6)
    skip:
#endif
	if (next == head)
	    break;
    }

    if (rc < 0)
        return rc;

    return 0;
}