RE: popen() is executed many times in MODE_SET_ACTION:

goon863 <[email protected]>
Newsgroups gmane.network.net-snmp.user,gmane.spam.detected
Message-ID <1098498538.1357821192539025952.JavaMail.coremail@bj163app104.163.com>
sorry that " agentXRetries  0 ". and the adjunct enseirb.c is my code after changed.it run several times popen();Any suggestion will be apreciated.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
enseirb.c (application/octet-stream, 24 KB)
/*
 * Note: this file originally auto-generated by mib2c using
 *        : mib2c.scalar.conf,v 1.1 2002/06/19 18:50:13 hardaker Exp $
 */

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "enseirb.h"

#include <stdlib.h>
#include <unistd.h>
/*    #include <asm/io.h> */

#define lp_base 0x378
#define         OFF 0
#define         ON  1

static int  led0 = OFF;
static int  led1 = OFF;
static int  led2 = OFF;
static int  led3 = OFF;
static int  led4 = OFF;
static int  led5 = OFF;
static int  led6 = OFF;
static int  led7 = OFF;
static char led8[]="haha";

static char lpdata;


#define MYDEBUG_    //l
#ifdef MYDEBUG_
        #define MYDEBUG(x) x
#else
        #define MYDEBUG(x)
#endif /* MYDEBUG_ */



struct stu

{
	float ave;
	float miss;
}ping0[1],ping1[1],*pp,*qq;

void ping(char addr[],char times[]);
void get_value(char buf[],char name[],char dat[]);

/** Initialzies the enseirb module */
void
init_enseirb(void)
{
    static oid      led0_oid[] = { 1, 3, 6, 1, 4, 1, 9362, 1, 1, 0 };
    static oid      led1_oid[] = { 1, 3, 6, 1, 4, 1, 9362, 1, 2, 0 };
    static oid      led2_oid[] = { 1, 3, 6, 1, 4, 1, 9362, 1, 3, 0 };
    static oid      led3_oid[] = { 1, 3, 6, 1, 4, 1, 9362, 1, 4, 0 };
    static oid      led4_oid[] = { 1, 3, 6, 1, 4, 1, 9362, 1, 5, 0 };
    static oid      led5_oid[] = { 1, 3, 6, 1, 4, 1, 9362, 1, 6, 0 };
    static oid      led6_oid[] = { 1, 3, 6, 1, 4, 1, 9362, 1, 7, 0 };
    static oid      led7_oid[] = { 1, 3, 6, 1, 4, 1, 9362, 1, 8, 0 };

    DEBUGMSGTL(("enseirb", "Initializing\n"));

    netsnmp_register_instance(
		              netsnmp_create_handler_registration
                              ("led0",
                               do_led0, led0_oid, OID_LENGTH(led0_oid), HANDLER_CAN_RWRITE));
    netsnmp_register_instance(netsnmp_create_handler_registration
                              ("led1",
                               do_led1, led1_oid, OID_LENGTH(led1_oid), HANDLER_CAN_RWRITE));
    netsnmp_register_instance(netsnmp_create_handler_registration
                              ("led2",
                               do_led2, led2_oid, OID_LENGTH(led2_oid), HANDLER_CAN_RWRITE));
    netsnmp_register_instance(netsnmp_create_handler_registration
                              ("led3",
                               do_led3, led3_oid, OID_LENGTH(led3_oid), HANDLER_CAN_RWRITE));
    netsnmp_register_instance(netsnmp_create_handler_registration
                              ("led4",
                               do_led4, led4_oid, OID_LENGTH(led4_oid), HANDLER_CAN_RWRITE));
    netsnmp_register_instance(netsnmp_create_handler_registration
                              ("led5",
                               do_led5, led5_oid, OID_LENGTH(led5_oid), HANDLER_CAN_RWRITE));
    netsnmp_register_instance(netsnmp_create_handler_registration
                              ("led6",
                               do_led6, led6_oid, OID_LENGTH(led6_oid), HANDLER_CAN_RWRITE));
    netsnmp_register_instance(netsnmp_create_handler_registration
                              ("led7",
                               do_led7, led7_oid, OID_LENGTH(led7_oid), HANDLER_CAN_RWRITE));


//  Acces port parallele
//    ioperm(lp_base, 1, 1);

// On eteint les 8 leds
    lpdata = 0;
//    outb(lpdata, lp_base);
}

int
do_led0(netsnmp_mib_handler *handler,
        netsnmp_handler_registration *reginfo,
        netsnmp_agent_request_info *reqinfo,
        netsnmp_request_info *requests)
{
	char tmp;
    /*
     * We are never called for a GETNEXT if it's registered as a
     * "instance", as it's "magically" handled for us.  
     */

    /*
     * a instance handler also only hands us one request at a time, so
     * we don't need to loop over a list of requests; we'll only get one. 
     */

    switch (reqinfo->mode) {

    case MODE_GET:
	read_ping(led8);
        snmp_set_var_typed_value(requests->requestvb,
				 ASN_OCTET_STR,
                                 (u_char *) led8,
				 strlen(led8));
        DEBUGMSGTL(("enseirb", "led0 current value :  %d\n", led0));
        break;

        /*
         * SET REQUEST
         *
         * multiple states in the transaction.  See:
         * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
         */
    case MODE_SET_RESERVE1:
        break;

    case MODE_SET_RESERVE2:
        break;

    case MODE_SET_FREE:
        /*
         * XXX: free resources allocated in RESERVE1 and/or
         * RESERVE2.  Something failed somewhere, and the states
         * below won't be called. 
         */
        break;

    case MODE_SET_ACTION:
        /*
         * XXX: perform the value change here 
         */
//	lpdata = inb(lp_base);
	tmp = *(requests->requestvb->val.integer);

	if((tmp == 0) && (led0 == 1))
		send_easy_trap(SNMP_TRAP_ENTERPRISESPECIFIC, 100);
//	        send_easy_trap(10, 10);
	led0 = tmp;	        
        DEBUGMSGTL(("enseirb", "led0 set now to  %d\n", led0));
        tmp = led0 << 0;
        if(tmp)
                lpdata = lpdata | tmp;
        else {
                tmp = 1 << 0;
                lpdata = lpdata & (~tmp);
        }
//        outb(lpdata, lp_base);
        break;

    case MODE_SET_COMMIT:
        /*
         * XXX: delete temporary storage 
         */
        break;

    case MODE_SET_UNDO:
        /*
         * XXX: UNDO and return to previous value for the object 
         */
        break;

    default:
        /*
         * we should never get here, so this is a really bad error 
         */
        return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}


int
do_led1(netsnmp_mib_handler *handler,
        netsnmp_handler_registration *reginfo,
        netsnmp_agent_request_info *reqinfo,
        netsnmp_request_info *requests)
{
	char tmp;
    /*
     * We are never called for a GETNEXT if it's registered as a
     * "instance", as it's "magically" handled for us.  
     */

    /*
     * a instance handler also only hands us one request at a time, so
     * we don't need to loop over a list of requests; we'll only get one. 
     */

    switch (reqinfo->mode) {

    case MODE_GET:
        snmp_set_var_typed_value(requests->requestvb,
				 ASN_INTEGER,
                                 (u_char *) &led1,
				 sizeof(led1));
        DEBUGMSGTL(("enseirb", "led0 current value :  %d\n", led1));
        break;

        /*
         * SET REQUEST
         *
         * multiple states in the transaction.  See:
         * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
         */
    case MODE_SET_RESERVE1:
        break;

    case MODE_SET_RESERVE2:
        break;

    case MODE_SET_FREE:
        /*
         * XXX: free resources allocated in RESERVE1 and/or
         * RESERVE2.  Something failed somewhere, and the states
         * below won't be called. 
         */
        break;

    case MODE_SET_ACTION:
        /*
         * XXX: perform the value change here 
         */
//	lpdata = inb(lp_base);
#if 0
	led1 = *(requests->requestvb->val.integer);
        DEBUGMSGTL(("enseirb", "led1 set now to  %d\n", led1));
        tmp = led1 << 1;
        if(tmp)
                lpdata = lpdata | tmp;
        else {
                tmp = 1 << 1;
                lpdata = lpdata & (~tmp);
        }
//        outb(lpdata, lp_base);
#endif
        break;

    case MODE_SET_COMMIT:
        /*
         * XXX: delete temporary storage 
         */
        break;

    case MODE_SET_UNDO:
        /*
         * XXX: UNDO and return to previous value for the object 
         */
        break;

    default:
        /*
         * we should never get here, so this is a really bad error 
         */
        return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}


int
do_led2(netsnmp_mib_handler *handler,
        netsnmp_handler_registration *reginfo,
        netsnmp_agent_request_info *reqinfo,
        netsnmp_request_info *requests)
{
	char tmp;
    /*
     * We are never called for a GETNEXT if it's registered as a
     * "instance", as it's "magically" handled for us.  
     */

    /*
     * a instance handler also only hands us one request at a time, so
     * we don't need to loop over a list of requests; we'll only get one. 
     */

    switch (reqinfo->mode) {

    case MODE_GET:
//	ping("www.google.com","10");
//	system("ping -c 3 192.168.0.1");
	 MYDEBUG( printf("popen haha (%s  %d\n) ... ", __FILE__,__LINE__));
        snmp_set_var_typed_value(requests->requestvb,
				 ASN_INTEGER,
                                 (u_char *) &led2,
				 sizeof(led2));
        DEBUGMSGTL(("enseirb", "led2 current value :  %d\n", led2));
        break;

        /*
         * SET REQUEST
         *
         * multiple states in the transaction.  See:
         * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
         */
    case MODE_SET_RESERVE1:
        break;

    case MODE_SET_RESERVE2:
        break;

    case MODE_SET_FREE:
        /*
         * XXX: free resources allocated in RESERVE1 and/or
         * RESERVE2.  Something failed somewhere, and the states
         * below won't be called. 
         */
        break;

    case MODE_SET_ACTION:
        /*
         * XXX: perform the value change here 
         */
//	lpdata = inb(lp_base);
	led2 = *(requests->requestvb->val.integer);
	MYDEBUG( printf("run here (%s  %d\n) ... ", __FILE__,__LINE__));
//	system("ping -c 6 www.google.com");
	if(led2==20) ping("www.google.com","10"); 
	
//	if(led2==20) system("ping -c 8 www.google.com");
	MYDEBUG( printf("run here (%s  %d\n) ... ", __FILE__,__LINE__));
/*	led2=10;
	snmp_set_var_typed_value(requests->requestvb,
                                 ASN_INTEGER,
                                 (u_char *) &led2,
                                 sizeof(led2));
*/
#if 0
        DEBUGMSGTL(("enseirb", "led2 set now to  %d\n", led2));
        tmp = led2 << 2;
        if(tmp)
                lpdata = lpdata | tmp;
        else {
                tmp = 1 << 2;
                lpdata = lpdata & (~tmp);
        }
//        outb(lpdata, lp_base);
#endif 
        break;

    case MODE_SET_COMMIT:
        /*
         * XXX: delete temporary storage 
         */
        break;

    case MODE_SET_UNDO:
        /*
         * XXX: UNDO and return to previous value for the object 
         */
        break;

    default:
        /*
         * we should never get here, so this is a really bad error 
         */
        return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}


int
do_led3(netsnmp_mib_handler *handler,
        netsnmp_handler_registration *reginfo,
        netsnmp_agent_request_info *reqinfo,
        netsnmp_request_info *requests)
{
	char tmp;
    /*
     * We are never called for a GETNEXT if it's registered as a
     * "instance", as it's "magically" handled for us.  
     */

    /*
     * a instance handler also only hands us one request at a time, so
     * we don't need to loop over a list of requests; we'll only get one. 
     */

    switch (reqinfo->mode) {

    case MODE_GET:
        snmp_set_var_typed_value(requests->requestvb,
				 ASN_INTEGER,
                                 (u_char *) &led3,
				 sizeof(led3));
        DEBUGMSGTL(("enseirb", "led3 current value :  %d\n", led3));
        break;

        /*
         * SET REQUEST
         *
         * multiple states in the transaction.  See:
         * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
         */
    case MODE_SET_RESERVE1:
        break;

    case MODE_SET_RESERVE2:
        break;

    case MODE_SET_FREE:
        /*
         * XXX: free resources allocated in RESERVE1 and/or
         * RESERVE2.  Something failed somewhere, and the states
         * below won't be called. 
         */
        break;

    case MODE_SET_ACTION:
        /*
         * XXX: perform the value change here 
         */
//	lpdata = inb(lp_base);
	led3 = *(requests->requestvb->val.integer);
        DEBUGMSGTL(("enseirb", "led3 set now to  %d\n", led3));
        tmp = led3 << 3;
        if(tmp)
                lpdata = lpdata | tmp;
        else {
                tmp = 1 << 3;
                lpdata = lpdata & (~tmp);
        }
//        outb(lpdata, lp_base);
        break;

    case MODE_SET_COMMIT:
        /*
         * XXX: delete temporary storage 
         */
        break;

    case MODE_SET_UNDO:
        /*
         * XXX: UNDO and return to previous value for the object 
         */
        break;

    default:
        /*
         * we should never get here, so this is a really bad error 
         */
        return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}


int
do_led4(netsnmp_mib_handler *handler,
        netsnmp_handler_registration *reginfo,
        netsnmp_agent_request_info *reqinfo,
        netsnmp_request_info *requests)
{
	char tmp;
    /*
     * We are never called for a GETNEXT if it's registered as a
     * "instance", as it's "magically" handled for us.  
     */

    /*
     * a instance handler also only hands us one request at a time, so
     * we don't need to loop over a list of requests; we'll only get one. 
     */

    switch (reqinfo->mode) {

    case MODE_GET:
        snmp_set_var_typed_value(requests->requestvb,
				 ASN_INTEGER,
                                 (u_char *) &led4,
				 sizeof(led4));
        DEBUGMSGTL(("enseirb", "led4 current value :  %d\n", led4));
        break;

        /*
         * SET REQUEST
         *
         * multiple states in the transaction.  See:
         * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
         */
    case MODE_SET_RESERVE1:
        break;

    case MODE_SET_RESERVE2:
        break;

    case MODE_SET_FREE:
        /*
         * XXX: free resources allocated in RESERVE1 and/or
         * RESERVE2.  Something failed somewhere, and the states
         * below won't be called. 
         */
        break;

    case MODE_SET_ACTION:
        /*
         * XXX: perform the value change here 
         */
//	lpdata = inb(lp_base);
	led4 = *(requests->requestvb->val.integer);
        DEBUGMSGTL(("enseirb", "led4 set now to  %d\n", led4));
        tmp = led4 << 4;
        if(tmp)
                lpdata = lpdata | tmp;
        else {
                tmp = 1 << 4;
                lpdata = lpdata & (~tmp);
        }
//        outb(lpdata, lp_base);
        break;

    case MODE_SET_COMMIT:
        /*
         * XXX: delete temporary storage 
         */
        break;

    case MODE_SET_UNDO:
        /*
         * XXX: UNDO and return to previous value for the object 
         */
        break;

    default:
        /*
         * we should never get here, so this is a really bad error 
         */
        return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}


int
do_led5(netsnmp_mib_handler *handler,
        netsnmp_handler_registration *reginfo,
        netsnmp_agent_request_info *reqinfo,
        netsnmp_request_info *requests)
{
	char tmp;
    /*
     * We are never called for a GETNEXT if it's registered as a
     * "instance", as it's "magically" handled for us.  
     */

    /*
     * a instance handler also only hands us one request at a time, so
     * we don't need to loop over a list of requests; we'll only get one. 
     */

    switch (reqinfo->mode) {

    case MODE_GET:
        snmp_set_var_typed_value(requests->requestvb,
				 ASN_INTEGER,
                                 (u_char *) &led5,
				 sizeof(led5));
        DEBUGMSGTL(("enseirb", "led5 current value :  %d\n", led5));
        break;

        /*
         * SET REQUEST
         *
         * multiple states in the transaction.  See:
         * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
         */
    case MODE_SET_RESERVE1:
        break;

    case MODE_SET_RESERVE2:
        break;

    case MODE_SET_FREE:
        /*
         * XXX: free resources allocated in RESERVE1 and/or
         * RESERVE2.  Something failed somewhere, and the states
         * below won't be called. 
         */
        break;

    case MODE_SET_ACTION:
        /*
         * XXX: perform the value change here 
         */
//	lpdata = inb(lp_base);
	led5 = *(requests->requestvb->val.integer);
        DEBUGMSGTL(("enseirb", "led5 set now to  %d\n", led5));
        tmp = led5 << 5;
        if(tmp)
                lpdata = lpdata | tmp;
        else {
                tmp = 1 << 5;
                lpdata = lpdata & (~tmp);
        }
//        outb(lpdata, lp_base);
        break;

    case MODE_SET_COMMIT:
        /*
         * XXX: delete temporary storage 
         */
        break;

    case MODE_SET_UNDO:
        /*
         * XXX: UNDO and return to previous value for the object 
         */
        break;

    default:
        /*
         * we should never get here, so this is a really bad error 
         */
        return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}


int
do_led6(netsnmp_mib_handler *handler,
        netsnmp_handler_registration *reginfo,
        netsnmp_agent_request_info *reqinfo,
        netsnmp_request_info *requests)
{
	char tmp;
    /*
     * We are never called for a GETNEXT if it's registered as a
     * "instance", as it's "magically" handled for us.  
     */

    /*
     * a instance handler also only hands us one request at a time, so
     * we don't need to loop over a list of requests; we'll only get one. 
     */

    switch (reqinfo->mode) {

    case MODE_GET:
        snmp_set_var_typed_value(requests->requestvb,
				 ASN_INTEGER,
                                 (u_char *) &led6,
				 sizeof(led6));
        DEBUGMSGTL(("enseirb", "led6 current value :  %d\n", led6));
        break;

        /*
         * SET REQUEST
         *
         * multiple states in the transaction.  See:
         * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
         */
    case MODE_SET_RESERVE1:
        break;

    case MODE_SET_RESERVE2:
        break;

    case MODE_SET_FREE:
        /*
         * XXX: free resources allocated in RESERVE1 and/or
         * RESERVE2.  Something failed somewhere, and the states
         * below won't be called. 
         */
        break;

    case MODE_SET_ACTION:
        /*
         * XXX: perform the value change here 
         */
//	lpdata = inb(lp_base);
	led6 = *(requests->requestvb->val.integer);
        DEBUGMSGTL(("enseirb", "led6 set now to  %d\n", led6));
        tmp = led6 << 6;
        if(tmp)
                lpdata = lpdata | tmp;
        else {
                tmp = 1 << 6;
                lpdata = lpdata & (~tmp);
        }
//        outb(lpdata, lp_base);
        break;

    case MODE_SET_COMMIT:
        /*
         * XXX: delete temporary storage 
         */
        break;

    case MODE_SET_UNDO:
        /*
         * XXX: UNDO and return to previous value for the object 
         */
        break;

    default:
        /*
         * we should never get here, so this is a really bad error 
         */
        return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}


int
do_led7(netsnmp_mib_handler *handler,
        netsnmp_handler_registration *reginfo,
        netsnmp_agent_request_info *reqinfo,
        netsnmp_request_info *requests)
{
	char tmp;
    /*
     * We are never called for a GETNEXT if it's registered as a
     * "instance", as it's "magically" handled for us.  
     */

    /*
     * a instance handler also only hands us one request at a time, so
     * we don't need to loop over a list of requests; we'll only get one. 
     */

    switch (reqinfo->mode) {

    case MODE_GET:
        snmp_set_var_typed_value(requests->requestvb,
				 ASN_INTEGER,
                                 (u_char *) &led7,
				 sizeof(led7));
        DEBUGMSGTL(("enseirb", "led7 current value :  %d\n", led7));
        break;

        /*
         * SET REQUEST
         *
         * multiple states in the transaction.  See:
         * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
         */
    case MODE_SET_RESERVE1:
        break;

    case MODE_SET_RESERVE2:
        break;

    case MODE_SET_FREE:
        /*
         * XXX: free resources allocated in RESERVE1 and/or
         * RESERVE2.  Something failed somewhere, and the states
         * below won't be called. 
         */
        break;

    case MODE_SET_ACTION:
        /*
         * XXX: perform the value change here 
         */
//	lpdata = inb(lp_base);
	led7 = *(requests->requestvb->val.integer);
        DEBUGMSGTL(("enseirb", "led7 set now to  %d\n", led7));
        tmp = led7 << 7;
        if(tmp)
                lpdata = lpdata | tmp;
        else {
                tmp = 1 << 7;
                lpdata = lpdata & (~tmp);
        }
//        outb(lpdata, lp_base);
        break;

    case MODE_SET_COMMIT:
        /*
         * XXX: delete temporary storage 
         */
        break;

    case MODE_SET_UNDO:
        /*
         * XXX: UNDO and return to previous value for the object 
         */
        break;

    default:
        /*
         * we should never get here, so this is a really bad error 
         */
        return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}






void get_value(char buf[],char name[],char dat[])
{
	int len=0;
	int	buflen=0;
	char string[64];
	memset(string,0,sizeof(string));
	char valflag=0;
	char value[32];
	memset(value,0,sizeof(value));
//	char name[]="time=";
	
	len=strlen(buf);
	len++;

//	int i=0;
	int stringlen=0;
//	printf("com %s \n",buf);
//	printf("len %d\n",len);
	
	for(buflen=0;buflen<len;buflen++)
	{
		
		if((buf[buflen]==' ')|(buf[buflen]=='+')|(buf[buflen]=='\0')){
//			printf("st %s dd \n",string);
			if(valflag){
				strcpy(value,string);
				valflag=0;
			}
			memset(string,0,sizeof(string));
			stringlen=-1;
		}
		if(strcmp(string,name)==0){
			valflag=1;
			memset(string,0,sizeof(string));
			stringlen=0;
		}
		
		string[stringlen]=buf[buflen];
//		printf("%s\n",string);
		stringlen++;
	}
//	printf("string over %s \n",value);
	strcpy(dat,value);
}

void ping(char addr[],char times[])
{
	FILE *wrt;

	FILE * fp;
//	char addr[]="www.google.com";
	int i=0;
	char timce=0;
	char dat[16];
	float add;
	float all=0;
	float average=0;
	float miss=0;
	char name[]="time=";
//	char comm[64]="ping -c ";
//	sprintf(comm," %d www.google.com",timec);
	float miss_cout;
	char buffer[128];
	char ping_buf[32];
	char value[32];
	timce=atoi(times);
	
	sprintf(ping_buf,"ping -c %d %s",timce,addr);
//	fp=popen(ping_buf,"r");
	 fp=popen("ping -c 4 64.233.189.104","r");
//	system(ping_buf);
	 MYDEBUG( printf("popen haha (%s  %d\n) ... ", __FILE__,__LINE__));
#if 1
	for(i=0;i<timce;i++)

	{	
		memset(dat,0,sizeof(dat));
		memset(buffer,0,sizeof(buffer));
//		printf(" % \n");
		fgets(buffer,sizeof(buffer),fp);
//		printf("%s",buffer);
		MYDEBUG( printf("run here (%s  %d\n) ... ", __FILE__,__LINE__));
		get_value(buffer,name,dat);
		MYDEBUG( printf("run here (%s  %d\n) ... ", __FILE__,__LINE__));
		printf("i = %d value= %s\n",i,dat);
		if(strlen(dat)==0){
			miss_cout++;
//			printf("%d miss_cout \n",miss_cout);
		}
		add=atoi(dat);
		all=all+add;
		sleep(1);
		
	}

	miss_cout++;
//	printf("dtalen miss=%d timce=%d \n",miss_cout,timce);
	average=all/(timce-1);
	miss = (miss_cout-1)*100/timce;
//	printf("%d dtalen miss=%f  timce= %d \n",strlen(dat),miss,timce);
	sprintf(value,"aeasf %f miss= %f %\n",average,miss);
//	printf("%s",value);

	if((wrt=fopen("/home/ping.txt","wb+"))==NULL)

	{

//		printf("cat");

		return 0;

	}

//	for(i=0;i<1;i++,pp++)

//	scanf("%d%d",&pp->ave,&pp->miss);

//	pp=ping0;

	pp=ping0;

	qq=ping1;

	pp->ave = average;

	pp->miss =miss;

	fwrite(pp,sizeof(struct stu),1,wrt);

	rewind(wrt);

	fread(qq,sizeof(struct stu),1,wrt);

//	printf("haha");

	for(i=0;i<1;i++,qq++)

//	printf("read \n %5f     %7f    \n",qq->ave,qq->miss);

	fclose(wrt);
#endif
	 MYDEBUG( printf("popen haha (%s  %d\n) ... ", __FILE__,__LINE__));
//	pclose(fp);

	return;

}







void read_ping(float dat[])
{
        struct stu *red;
        FILE *fp;
        red=ping0;
        memset(red,0,sizeof(*red));

        if((fp=fopen("/home/ping.txt","rb"))==NULL)
        {
//              printf("cat \n");
                return 0;
        }
         fread(red,sizeof(*red),1,fp);
//      red->ave=73.3;
//      red->miss=39.3;
        sprintf(dat,"average_time = %f ms + miss_raw = %f",red->ave,red->miss);
        strcat(dat,"%");
//      printf("%f ms + %f ms   \n",red->ave,red->miss);
        fclose(fp);

}
enseirb.h (application/octet-stream, 533 B)
/*
 * Note: this file originally auto-generated by mib2c using
 *        : mib2c.scalar.conf,v 1.1 2002/06/19 18:50:13 hardaker Exp $
 */
#ifndef ENSEIRB_H
#define ENSEIRB_H

/*
 * function declarations 
 */
void            init_enseirb(void);
Netsnmp_Node_Handler do_led0;
Netsnmp_Node_Handler do_led1;
Netsnmp_Node_Handler do_led2;
Netsnmp_Node_Handler do_led3;
Netsnmp_Node_Handler do_led4;
Netsnmp_Node_Handler do_led5;
Netsnmp_Node_Handler do_led6;
Netsnmp_Node_Handler do_led7;

#endif                          /* ENSEIRB_H */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.