/* aipsend.c */ /* Send a datagram without using a connected socket */ #include #include #include #include #include #include #include #include #include char buf[1024*16]; struct sockaddr_in name; char hnamebuf[80]; struct tms timeb; static struct timezone dummy = {0,0}; static int frames = 0; static struct timeval time1; static struct timeval time2; static double tu1; static double tu2; static int count = 0; static int fsize; static void sigintx( int dummyp) { int fc; fc = frames; gettimeofday(&time2,&dummy); tu1 = 1000000 * time1.tv_sec; tu1 += time1.tv_usec; tu2 = 1000000 * time2.tv_sec; tu2 += time2.tv_usec; printf("Frames sent = %8d \n", fc); printf("MBits / sec = %8.3lf \n", 8.0 * fc * fsize / (tu2 - tu1)); printf("Frames/msec = %8.3lf \n", 1000 * fc / (tu2 - tu1)); exit(1); } char buf[16 * 1024]; void aip_send( int s, /* socket handle */ int blk, /* Block size */ int count) /* Total count. */ { int rc; int fc = 0; int sent = count; fsize = blk; signal(SIGINT, sigintx); rc = 0; memset(buf, 'a', sizeof(buf)); gettimeofday(&time1,&dummy); while ((sent > 0) || (count <= 0)) { long *loc; loc = (long *)buf; *loc = ntohl(fc); rc = write(s, buf, blk); if (rc < 0) break; sent -= rc; fc += 1; frames += 1; } } main( int argc, char **argv) { int i, me, you; unsigned char c; int sock; int status; long msglen; int msgcount; int blk; unsigned dummyip; int fc; int fd; int vci; int psr; struct hostent *hp; int dummyad; #if 0 /* This stuff here assumes that IP over PVCS is in use */ /* Its basically meaningless over SVCS! */ vci = 32; psr = 1; fd = open("/dev/ape25", O_RDWR); ape_tmqcfg(fd, vci & 7, 26 * 1024 * 1024, 1, 1); ape_lccfg(fd, vci, psr, 4096); #endif blk = 1024 - 40; if (argc < 2) { printf("You must give dest host name as parm 1.. \n"); printf("You may give blk size in decimal as parm 2. \n"); printf("You may give byte count in decimal as parm 3. \n"); printf("You may give dest port in decimal as parm 4. \n"); exit(1); } if (argc > 2) sscanf(argv[2], "%d", &blk); if (argc > 3) sscanf(argv[3], "%d", &count); sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) { printf("Socket create failed \n"); exit(1); } hp = gethostbyname(argv[1]); if (hp == 0) { printf("Host %s not found\n", argv[1]); exit(1); } bcopy((char *)hp->h_addr, (char *)&name.sin_addr, hp->h_length); printf("Addr = "); for (i = 0; i < sizeof(dummyad); i++) { c = *((char *)&name.sin_addr + i); printf(" %2x", c); } printf("\n"); name.sin_family = AF_INET; if (argc > 4) name.sin_port = htons(atoi(argv[4])); else name.sin_port = htons(33456); memset(buf, 'A', sizeof(buf)); status = connect(sock, (struct sockaddr *)&name, sizeof(name)); printf("Bind status = %d\n", status); if (status < 0) { perror("bind error"); exit(1); } aip_send(sock, blk, count); times(&timeb); gettimeofday(&time2,&dummy); printf("time 1: %d %d\n",time1.tv_sec, time1.tv_usec); printf("time 2: %d %d\n",time2.tv_sec, time2.tv_usec); tu1 = 1000000 * time1.tv_sec; tu1 += time1.tv_usec; tu2 = 1000000 * time2.tv_sec; tu2 += time2.tv_usec; fc = frames; printf("Frames sent = %8d \n", fc); printf("MBits / sec = %8.3lf \n", 8.0 * fc * fsize / (tu2 - tu1)); printf("Frames/msec = %8.3lf \n", 1000 * fc / (tu2 - tu1)); fprintf(stderr, "%6d \t %6d.%02d \t %6d.%02d \t %8.2lf \t %8.3lf \t %8d \t %8.3lf \n", blk, timeb.tms_utime / 100, timeb.tms_utime % 100, timeb.tms_stime / 100, timeb.tms_stime % 100, (tu2 - tu1)/ 1000000, 8 * count / (tu2 - tu1), fc, fc / (tu2 - tu1)); }