#include <stdio.h>
#include <fcntl.h>
#include <sys/time.h>
#include <string.h>
#include "nicinfo_shm.h"

int main(int argc, char *argv[])
{
	NETCARD_INFO ni;
	int ret = 0;
	char dev[10];
	struct timeval st,et;
	unsigned long uset, stl, etl, to;
	if( argc >=2 ) strncpy(dev,argv[1],9);
	else  strcpy(dev, "eth0");

	if( argc >=3 ) to = strtol(argv[2], NULL, 10 );
	else to= 500000ull;

	while(1) {
		gettimeofday(&st, NULL);
		ret = get_nic_info( dev, &ni );
		gettimeofday(&et, NULL);
		stl = st.tv_sec;
	        stl = stl*1000000 + st.tv_usec;
		etl = et.tv_sec;
		etl = etl*1000000 + et.tv_usec;
		uset = etl - stl;
//		printf("%d, %x, %x\n", ret, uset, to);
		if( ret != 0 || uset > to) {
///home/d5000/var/log/netcard/testnic.log
		   char buf[120];
		   int log = open("/home/d5000/var/log/netcard/testnic.log", O_CREAT|O_RDWR|O_APPEND, 0666);
		   snprintf(buf,sizeof(buf),"ret:%d, %lld-%lld=%lld\n", ret, etl, stl, uset);
		   write(log, buf, strlen(buf));
		   close(log);
		}

//		sleep(1);
	}


}

