4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
25 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
26 /* All Rights Reserved */
28 * University Copyright- Copyright (c) 1982, 1986, 1988
29 * The Regents of the University of California
32 * University Acknowledgment- Portions of this document are derived from
33 * software developed by the University of California, Berkeley, and its
37 #pragma ident "%Z%%M% %I% %E% SMI"
43 #include <rpcsvc/spray.h>
46 enum clnt_stat
sprayproc_spray_1nd(/*argp, clnt*/);
48 #define DEFBYTES 100000 /* default numbers of bytes to send */
49 #define MAXPACKETLEN 1514
50 #define SPRAYOVERHEAD 86 /* size of rpc packet when size=0 */
52 static void slp(int usecs
);
53 static void usage(void);
56 main(int argc
, char *argv
[])
61 register CLIENT
*clnt
;
64 unsigned int psec
, bsec
;
67 unsigned int lnth
, cnt
;
80 while (optind
< argc
) {
81 if (argv
[optind
][0] == '-') {
82 if ((c
= getopt(argc
, argv
, "d:c:t:l:")) == EOF
) {
90 cnt
= (unsigned int) atoi(optarg
);
96 lnth
= (unsigned int) atoi(optarg
);
102 host
= argv
[optind
++];
107 clnt
= clnt_create(host
, SPRAYPROG
, SPRAYVERS
, type
);
108 if (clnt
== (CLIENT
*)NULL
) {
109 sprintf(msgbuf
, "spray: cannot clnt_create %s:%s", host
, type
);
110 clnt_pcreateerror(msgbuf
);
115 if (lnth
< SPRAYOVERHEAD
)
116 lnth
= SPRAYOVERHEAD
;
117 else if (lnth
>= SPRAYMAX
)
119 if (lnth
<= MAXPACKETLEN
&& lnth
% 4 != 2)
120 lnth
= ((lnth
+ 5) / 4) * 4 - 2;
121 arr
.sprayarr_len
= lnth
- SPRAYOVERHEAD
;
122 arr
.sprayarr_val
= (char *)buf
;
123 printf("sending %u packets of length %u to %s ...", cnt
, lnth
, host
);
125 if (sprayproc_clear_1(NULL
, clnt
) == NULL
) {
126 clnt_perror(clnt
, "SPRAYPROC_CLEAR ");
129 for (i
= 0; i
< cnt
; i
++) {
130 sprayproc_spray_1nd(&arr
, clnt
);
134 if ((co
= sprayproc_get_1(NULL
, clnt
)) == NULL
) {
135 clnt_perror(clnt
, "SPRAYPROC_GET ");
139 if (cumul
.counter
< cnt
)
140 printf("\n\t%d packets (%.3f%%) dropped by %s\n",
142 100.0 * (cnt
- cumul
.counter
)/cnt
, host
);
144 printf("\n\tno packets dropped by %s\n", host
);
145 psec
= (1000000.0 * cumul
.counter
)
146 / (1000000.0 * cumul
.clock
.sec
+ cumul
.clock
.usec
);
147 bsec
= (lnth
* 1000000.0 * cumul
.counter
)/
148 (1000000.0 * cumul
.clock
.sec
+ cumul
.clock
.usec
);
149 printf("\t%u packets/sec, %u bytes/sec\n", psec
, bsec
);
155 * A special call, where the TIMEOUT is 0. So, every call times-out.
157 static struct timeval TIMEOUT
= { 0, 0 };
160 sprayproc_spray_1nd(argp
, clnt
)
164 return (clnt_call(clnt
, SPRAYPROC_SPRAY
, xdr_sprayarr
, (caddr_t
)argp
,
165 xdr_void
, NULL
, TIMEOUT
));
168 /* A cheap milliseconds sleep call */
172 static struct pollfd pfds
[1] = {
175 pfds
[0].fd
= fileno(stdout
);
176 poll(pfds
, 1, usecs
/1000);
182 printf("spray host [-t nettype] [-l lnth] [-c cnt] [-d delay]\n");