1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
$NetBSD: patch-ab,v 1.8 2005/12/21 11:49:51 tron Exp $
--- ttcp.c.orig 1997-02-27 21:30:23.000000000 +0000
+++ ttcp.c 2005-12-21 11:40:39.000000000 +0000
@@ -44,17 +44,19 @@
/* #define BSD41a */
/* #define SYSV */ /* required on SGI IRIX releases before 3.3 */
-#include <stdio.h>
-#include <signal.h>
-#include <ctype.h>
-#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
+#include <stdio.h>
+#include <signal.h>
+#include <ctype.h>
+#include <errno.h>
#include <netdb.h>
#include <sys/time.h> /* struct timeval */
+#include <stdlib.h>
+#include <string.h>
#if defined(SYSV)
#include <sys/times.h>
@@ -71,7 +73,8 @@
struct sockaddr_in sinhim;
struct sockaddr_in frominet;
-int domain, fromlen;
+int domain;
+socklen_t fromlen;
int fd; /* fd of network socket */
int buflen = 8 * 1024; /* length of buffer */
@@ -99,7 +102,6 @@
int touchdata = 0; /* access data after reading */
struct hostent *addr;
-extern int errno;
extern int optind;
extern char *optarg;
@@ -151,7 +153,7 @@
int argc;
char **argv;
{
- unsigned long addr_tmp;
+ in_addr_t addr_tmp;
int c;
if (argc < 2) goto usage;
@@ -263,29 +265,30 @@
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 +329,7 @@
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 +351,11 @@
}
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,
+ socklen_t peerlen = sizeof(peer);
+ if (getpeername(fd, (struct sockaddr *) &peer,
&peerlen) < 0) {
err("getpeername");
}
@@ -412,25 +415,25 @@
}
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);
@@ -749,10 +752,10 @@
int count;
{
struct sockaddr_in from;
- int len = sizeof(from);
+ socklen_t 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 +785,7 @@
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 +806,7 @@
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 );
}
/*
|