]>
git.saurik.com Git - apple/network_cmds.git/blob - spray.tproj/spray.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1993 Winning Strategies, Inc.
26 * All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * This product includes software developed by Winning Strategies, Inc.
39 * 4. The name of the author may not be used to endorse or promote products
40 * derived from this software without specific prior written permission
42 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
43 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
44 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
45 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
46 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
48 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
49 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
50 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
51 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 * $Id: spray.c,v 1.1.1.1 1999/05/02 03:58:27 wsanchez Exp $
61 #include <rpcsvc/spray.h>
64 #define SPRAYOVERHEAD 86
68 void print_xferstats ();
71 char spray_buffer
[SPRAYMAX
];
74 struct timeval NO_DEFAULT
= { -1, -1 };
75 struct timeval ONE_WAY
= { 0, 0 };
76 struct timeval TIMEOUT
= { 25, 0 };
84 spraycumul host_stats
;
92 double xmit_time
; /* time to receive data */
95 while ((c
= getopt(argc
, argv
, "c:d:l:")) != -1) {
101 delay
= atoi(optarg
);
104 length
= atoi(optarg
);
120 /* Correct packet length. */
121 if (length
> SPRAYMAX
) {
123 } else if (length
< SPRAYOVERHEAD
) {
124 length
= SPRAYOVERHEAD
;
126 /* The RPC portion of the packet is a multiple of 32 bits. */
127 length
-= SPRAYOVERHEAD
- 3;
129 length
+= SPRAYOVERHEAD
;
134 * The default value of count is the number of packets required
135 * to make the total stream size 100000 bytes.
138 count
= 100000 / length
;
141 /* Initialize spray argument */
142 host_array
.sprayarr_len
= length
- SPRAYOVERHEAD
;
143 host_array
.sprayarr_val
= spray_buffer
;
146 /* create connection with server */
147 cl
= clnt_create(*argv
, SPRAYPROG
, SPRAYVERS
, "udp");
149 clnt_pcreateerror(progname
);
155 * For some strange reason, RPC 4.0 sets the default timeout,
156 * thus timeouts specified in clnt_call() are always ignored.
158 * The following (undocumented) hack resets the internal state
159 * of the client handle.
161 clnt_control(cl
, CLSET_TIMEOUT
, &NO_DEFAULT
);
164 /* Clear server statistics */
165 if (clnt_call(cl
, SPRAYPROC_CLEAR
, xdr_void
, NULL
, xdr_void
, NULL
, TIMEOUT
) != RPC_SUCCESS
) {
166 clnt_perror(cl
, progname
);
171 /* Spray server with packets */
172 printf ("sending %d packets of lnth %d to %s ...", count
, length
, *argv
);
175 for (i
= 0; i
< count
; i
++) {
176 clnt_call(cl
, SPRAYPROC_SPRAY
, xdr_sprayarr
, &host_array
, xdr_void
, NULL
, ONE_WAY
);
184 /* Collect statistics from server */
185 if (clnt_call(cl
, SPRAYPROC_GET
, xdr_void
, NULL
, xdr_spraycumul
, &host_stats
, TIMEOUT
) != RPC_SUCCESS
) {
186 clnt_perror(cl
, progname
);
190 xmit_time
= host_stats
.clock
.sec
+
191 (host_stats
.clock
.usec
/ 1000000.0);
193 printf ("\n\tin %.2f seconds elapsed time\n", xmit_time
);
196 /* report dropped packets */
197 if (host_stats
.counter
!= count
) {
198 int packets_dropped
= count
- host_stats
.counter
;
200 printf("\t%d packets (%.2f%%) dropped\n",
202 100.0 * packets_dropped
/ count
);
204 printf("\tno packets dropped\n");
208 print_xferstats(count
, length
, xmit_time
);
211 print_xferstats(host_stats
.counter
, length
, xmit_time
);
218 print_xferstats(packets
, packetlen
, xfertime
)
224 double pps
; /* packets per second */
225 double bps
; /* bytes per second */
227 datalen
= packets
* packetlen
;
228 pps
= packets
/ xfertime
;
229 bps
= datalen
/ xfertime
;
231 printf("\t%.0f packets/sec, ", pps
);
234 printf ("%.1fK ", bps
/ 1024);
236 printf ("%.0f ", bps
);
238 printf("bytes/sec\n");
245 fprintf(stderr
, "usage: spray [-c count] [-l length] [-d delay] host\n");