$NetBSD: patch-ab,v 1.7 2005/12/05 20:49:51 rillig Exp $ --- ttcp.c.orig 1997-02-27 21:30:23.000000000 +0000 +++ ttcp.c @@ -55,6 +55,7 @@ #include #include #include /* struct timeval */ +#include #if defined(SYSV) #include @@ -99,7 +100,6 @@ char fmt = 'K'; /* output format: k = int touchdata = 0; /* access data after reading */ struct hostent *addr; -extern int errno; extern int optind; extern char *optarg; @@ -151,7 +151,7 @@ main(argc,argv) int argc; char **argv; { - unsigned long addr_tmp; + in_addr_t addr_tmp; int c; if (argc < 2) goto usage; @@ -263,29 +263,30 @@ char **argv; if ( (buf = (char *)malloc(buflen+bufalign)) == (char *)NULL) err("malloc"); if (bufalign != 0) - buf +=(bufalign - ((int)buf % bufalign) + bufoffset) % bufalign; + buf +=(bufalign - ((u_long)buf % bufalign) + bufoffset) % bufalign; if (trans) { - fprintf(stdout, + fprintf(stderr, "ttcp-t: buflen=%d, nbuf=%d, align=%d/%d, port=%d", buflen, nbuf, bufalign, bufoffset, port); if (sockbufsize) - fprintf(stdout, ", sockbufsize=%d", sockbufsize); + fprintf(stderr, ", sockbufsize=%d", sockbufsize); fprintf(stdout, " %s -> %s\n", udp?"udp":"tcp", host); } else { - fprintf(stdout, + fprintf(stderr, "ttcp-r: buflen=%d, nbuf=%d, align=%d/%d, port=%d", buflen, nbuf, bufalign, bufoffset, port); if (sockbufsize) - fprintf(stdout, ", sockbufsize=%d", sockbufsize); - fprintf(stdout, " %s\n", udp?"udp":"tcp"); + fprintf(stderr, ", sockbufsize=%d", sockbufsize); + fprintf(stderr, " %s\n", udp?"udp":"tcp"); } if ((fd = socket(AF_INET, udp?SOCK_DGRAM:SOCK_STREAM, 0)) < 0) err("socket"); mes("socket"); - if (bind(fd, &sinme, sizeof(sinme)) < 0) + sinme.sin_family = AF_INET; + if (bind(fd, (struct sockaddr *)&sinme, sizeof(sinme)) < 0) err("bind"); #if defined(SO_SNDBUF) || defined(SO_RCVBUF) @@ -326,7 +327,7 @@ char **argv; mes("nodelay"); } #endif - if(connect(fd, &sinhim, sizeof(sinhim) ) < 0) + if(connect(fd, (struct sockaddr *)&sinhim, sizeof(sinhim) ) < 0) err("connect"); mes("connect"); } else { @@ -348,11 +349,11 @@ char **argv; } fromlen = sizeof(frominet); domain = AF_INET; - if((fd=accept(fd, &frominet, &fromlen) ) < 0) + if((fd=accept(fd, (struct sockaddr *)&frominet, &fromlen) ) < 0) err("accept"); { struct sockaddr_in peer; int peerlen = sizeof(peer); - if (getpeername(fd, (struct sockaddr_in *) &peer, + if (getpeername(fd, (struct sockaddr *) &peer, &peerlen) < 0) { err("getpeername"); } @@ -412,25 +413,25 @@ char **argv; } if( cput <= 0.0 ) cput = 0.001; if( realt <= 0.0 ) realt = 0.001; - fprintf(stdout, + fprintf(stderr, "ttcp%s: %.0f bytes in %.2f real seconds = %s/sec +++\n", trans?"-t":"-r", nbytes, realt, outfmt(nbytes/realt)); if (verbose) { - fprintf(stdout, + fprintf(stderr, "ttcp%s: %.0f bytes in %.2f CPU seconds = %s/cpu sec\n", trans?"-t":"-r", nbytes, cput, outfmt(nbytes/cput)); } - fprintf(stdout, + fprintf(stderr, "ttcp%s: %d I/O calls, msec/call = %.2f, calls/sec = %.2f\n", trans?"-t":"-r", numCalls, 1024.0 * realt/((double)numCalls), ((double)numCalls)/realt); - fprintf(stdout,"ttcp%s: %s\n", trans?"-t":"-r", stats); + fprintf(stderr,"ttcp%s: %s\n", trans?"-t":"-r", stats); if (verbose) { - fprintf(stdout, + fprintf(stderr, "ttcp%s: buffer address %#x\n", trans?"-t":"-r", buf); @@ -752,7 +753,7 @@ int count; int len = sizeof(from); register int cnt; if( udp ) { - cnt = recvfrom( fd, buf, count, 0, &from, &len ); + cnt = recvfrom( fd, buf, count, 0, (struct sockaddr *)&from, &len ); numCalls++; } else { if( b_flag ) @@ -782,7 +783,7 @@ int count; register int cnt; if( udp ) { again: - cnt = sendto( fd, buf, count, 0, &sinhim, sizeof(sinhim) ); + cnt = sendto( fd, buf, count, 0, (struct sockaddr *)&sinhim, sizeof(sinhim) ); numCalls++; if( cnt<0 && errno == ENOBUFS ) { delay(18000); @@ -803,7 +804,7 @@ delay(us) tv.tv_sec = 0; tv.tv_usec = us; - (void)select( 1, (char *)0, (char *)0, (char *)0, &tv ); + (void)select( 1, (void *)0, (void *)0, (void *)0, &tv ); } /*