/* acopsink.c */ /* Network traffic sink */ #include #include #include #include #include #include #include #include #include #include #include #include "copuser.h" char bufi[1024 * 16]; struct timeval time1; struct timeval time2; static struct timezone dummy = {0,0}; static double tu1; static double tu2; static int frames = 0; static int drops = 0; static int dropcount = 0; void sigintr( int dummy) { tu1 = 1000000.0 * time1.tv_sec; tu1 += time1.tv_usec; printf("%d %d \n", time1.tv_sec, time1.tv_usec); printf("%d %d \n", time2.tv_sec, time2.tv_usec); tu2 = 1000000.0 * time2.tv_sec; tu2 += time2.tv_usec; printf("Frames recvd = %10d \n", frames); printf("Drops = %10d \n", drops); printf("Drop count = %10d \n", dropcount); printf("Total = %10d \n", frames + dropcount); printf("Elapsed usec = %10.0lf \n", tu2 - tu1); printf("Frames/sec = %10.2lf \n", frames * 1000000.0 / (tu2 - tu1)); exit(1); } void aip_recv( int s) /* socket handle */ { int rc; int amt = 0; int fc = 0; int fctrue; int first = 1; signal(SIGINT, sigintr); rc = read(s, bufi, sizeof(bufi)); gettimeofday(&time1, &dummy); while (rc >= 0) { amt += rc; /* write(1, bufi, rc); */ fctrue = ntohl(*(long *)bufi); /* printf("Got %d expected %d \n", fctrue, fc); */ /* Restart */ if (fctrue == 0) fc = fctrue; if (fctrue > fc) { printf("Drop %d %d \n", fctrue, fc); dropcount += fctrue - fc; drops += 1; } if (fctrue < fc) { printf("Out of order %d %d \n", fctrue, fc); dropcount += fctrue - fc; drops += 1; } frames += 1; fc = fctrue + 1; fprintf(stderr,"."); fflush(stderr); rc = read(s, bufi, sizeof(bufi)); gettimeofday(&time2, &dummy); if (rc == 0) printf("Read %d bytes first was %c \n", rc, bufi[0]); } printf("Receiver complete.. received %d \n", amt); } char buf[16 * 1024]; struct sockaddr_in name; struct sockaddr_in sname; int namelen; char hnamebuf[80]; main( int argc, char** argv) { int i, me, you; unsigned char c; int sock; int netaddr; int status; unsigned dummy; int msgcount; /* Create datagram socket */ sock = socket(AF_INET, SOCK_COP, IPPROTO_COP); if (sock < 0) { printf("Socket create failed \n"); exit(1); } dummy = 0; bcopy((char *)&dummy, (char *)&name.sin_addr, sizeof(dummy)); /* Fill in protocol family and port # from command line then */ /* bind the socket to the specified address. */ name.sin_family = AF_INET; if (argc > 1) name.sin_port = htons(atoi(argv[1])); else name.sin_port = htons(33456); status = bind(sock, (struct sockaddr *)&name, sizeof(name)); printf("Bind to port %d status is %d\n", ntohs(name.sin_port), status); if (status < 0) { perror("bind error"); exit(1); } /* Wait for someone to send me a datagram */ aip_recv(sock); }