1 /***************************************************************************
2  * DBS: Distributed Benchmark System
3  * Copyright (c) 1995, 1996, 1997 Yukio Murayama
4  * Copyright (c) 1995, 1996, 1997 Nara Institute of Science and Technology
5  * All rights reserved.
6  *
7  * Permission to use, copy, modify and distribute this software and its
8  * documentation is hereby granted, provided only with the following
9  * conditions are satisfied:
10  *
11  * 1. Both the copyright notice and this permission notice appear in
12  *    all copies of the software, derivative works or modified versions,
13  *    and any portions thereof, and that both notices appear in
14  *    supporting documentation.
15  * 2. All advertising materials mentioning features or use of this
16  *    software must display the following acknowledgement:
17  *      This product includes software developed by Nara Institute of
18  *      Science and Technology and its contributors.
19  * 3. Neither the name of Nara Institute of Science and Technology nor
20  *    the names of its contributors may be used to endorse or promote
21  *    products derived from this software without specific prior written
22  *    permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND NARA
25  * INSTITUTE OF SCIENCE AND TECHNOLOGY DISCLAIMS ANY LIABILITY OF
26  * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF
27  * THIS SOFTWARE. ALSO, THERE IS NO WARRANTY IMPLIED OR OTHERWISE,
28  * NOR IS SUPPORT PROVIDED.
29  *
30  * Feedback of the results generated from any improvements or
31  * extensions made to this software would be much appreciated.
32  * Any such feedback should be sent to:
33  *
34  *  Yukio Murayama
35  *  E-mail:  <yukio-m@is.aist-nara.ac.jp>
36  *  URL:     <http://shika.aist-nara.ac.jp/member/yukio-m/index.html>
37  *  Address: Graduate School of Information Science,
38  *           Nara Institute of Science and Technology,
39  *           Takayama 8916-5, Ikoma, Nara, Japan
40  *
41  * Nara Institute of Science and Technology has the rights to
42  * redistribute these changes.
43  ***************************************************************************/
44 /******************************************************************
45  * Distributed Benchmark System
46  * DBS Header File
47  * $Revision: 1.27 $
48  * $Date: 1997/07/11 00:54:34 $
49  * $Author: yukio-m $
50  *****************************************************************/
51 
52 #ifdef __P
53 #undef __P
54 #endif
55 
56 #if  (defined(sun) && !defined(__svr4__)) || defined(__hpux)
57 #define __P(prots)      ()
58 #else
59 #define __P(prots)    prots
60 #endif
61 
62 #include <sys/time.h>
63 
64 /*
65  * Defines
66  */
67 
68 #define DBS_VERSION "DBS Version 1.1.5"
69 /*
70 dbs-1.1.5
71 */
72 #define DBS_MAJOR_VERSION     1
73 #define DBS_MINOR_VERSION     1
74 #define DBS_PATCH_VERSION     ".5"
75 
76 #define OFF                   0
77 #define ON                    1
78 #define BEFORE               11
79 #define AFTER                12
80 #define TCP                   1
81 #define UDP                   2
82 #define SEND                  1
83 #define RECEIVE               2
84 #define SERVER          RECEIVE
85 #define CLIENT             SEND
86 #define STREAM                1
87 #define PACKET                2
88 
89 #define MAXHOSTNAME         256
90 #define LISTEN_NUM           10
91 #define MAX_COLUMN         1024
92 #define CHAR_ARRAY          256
93 #define RECV_DELAY_OFFSET     1.0
94 #define START_TIME_OFFSET    10.0
95 #define END_TIME_OFFSET1      5
96 #define END_TIME_OFFSET2      5
97 /*#define END_TIME_OFFSET       (END_TIME_OFFSET1+END_TIME_OFFSET2)*/
98 #define WARN_TIME_SYNC        0.1
99 #define MAX_TIME_SYNC        10.0
100 #define WARN_END_TIME       600.0
101 #define MAX_END_TIME       3600.0
102 #define DEFAULT_PORT      10710
103 
104 /*
105  * Definition of Grobal Variable
106  */
107 
108 /*
109  * Error Code
110  */
111 #define NORMAL          0
112 #define ABNORMAL        1
113 #define BIND            2
114 #define GETHOSTBYNAME   3
115 #define SOCKET          4
116 #define ACCEPT          5
117 #define FORK            6
118 #define ACCESSDENY      7
119 #define MALLOC          8
120 #define TIME            9
121 #define CONNECT        10
122 #define SOSNDBUF       11
123 #define SORCVBUF       12
124 #define SODEBUG        13
125 #define TCPNODELAY     14
126 #define RECVERROR      15
127 #define RECVFROM       16
128 #define SIGNAL         17
129 #define TCPDEBUG       18
130 #define TIMESYNC       19
131 #define TIMEOUT        20
132 #define TCPMAXSEG      21
133 #define INTERNALERROR  22
134 
135 #ifdef DBSC
136 static char *errmsg[] = {
137     "NORMAL",                               /*  0 */
138     "ABNORMAL",                             /*  1 */
139     "bind error (Address already in use)",  /*  2 */
140     "gethostbyname error",                  /*  3 */
141     "socket error",                         /*  4 */
142     "accept error",                         /*  5 */
143     "fork error",                           /*  6 */
144     "DBS Daemon Access Denyed",             /*  7 */
145     "malloc error",                         /*  8 */
146     "TIME is Wrong",                        /*  9 */
147     "connect error",                        /* 10 */
148     "SO_SNDBUF error",                      /* 11 */
149     "SO_RCVBUF error",                      /* 12 */
150     "SO_DEBUG error",                       /* 13 */
151     "TCP_NODELAY error",                    /* 14 */
152     "recv error",                           /* 15 */
153     "recvfrom error",                       /* 16 */
154     "signal error",                         /* 17 */
155     "TCP DEBUG error",                      /* 18 */
156     "TIME SYNC error",                      /* 19 */
157     "TIME OUT",                             /* 20 */
158     "Set MSS error",                        /* 21 */
159     "Internal Error!!!!!!!!!! I'm Sorry."   /* 22 */
160 };
161 #endif
162 
163 /*
164  * DBS Macro Program
165  */
166 
167 #define RECV(FD, ADDR, SIZE)  {\
168                                    int _i, _r, _n;\
169                                    _r = (SIZE), _i=0;\
170                                    while(_r > 0){\
171                                        if((_n=recv((FD), (char *)(ADDR)+_i, _r, 0)) < 0){\
172                                            perror("RECV DATA");\
173                                            exit(1);\
174                                        }\
175                                        _r -= _n;\
176                                        _i += _n;\
177                                    }\
178                               }
179 
180 #if !defined(MIN)
181 #define MIN(A,B) (((A)<(B))?(A):(B))
182 #endif
183 
184 #if !defined(MAX)
185 #define MAX(A,B) (((A)>(B))?(A):(B))
186 #endif
187 
188 #define GET_IP_ADDR(A,B)  (0xff & ((A) >> ((B-1)*8)))
189 
190 #define DEBUGMSG(A,B)  if(debug >= (A)) fprintf(stderr, B), fflush(stderr);
191 #define DEBUGMSG2(A,B) if(debug >= (A)) {B; fflush(stderr);}
192 
193 #if !defined(__SVR4) && !defined(__svr4) && !defined(SYSTYPE_SVR4)
194 #define SIGNAL_INIT           int oldmask, mask=(sigmask(SIGINT)|sigmask(SIGPIPE)|sigmask(SIGQUIT))
195 #define BEGIN_CRITICAL_REGION oldmask=sigblock(mask)
196 #define END_CRITICAL_REGION   sigsetmask(oldmask)
197 #else
198 #define SIGNAL_INIT           (0)
199 #define BEGIN_CRITICAL_REGION (sighold(SIGINT),sighold(SIGPIPE),sighold(SIGQUIT))
200 #define END_CRITICAL_REGION   (sigrelse(SIGINT),sigrelse(SIGPIPE),sigrelse(SIGQUIT))
201 #endif
202 
203 #define timeval_get(tp) ((double)tp.tv_sec + (double)tp.tv_usec/1000000.0)
204 
205 void timeval_cp  __P(( struct timeval *origin_time, struct timeval *current_time ));
206 void timeval_add __P(( struct timeval *origin_time, struct timeval *offset_time ));
207 
208 void timeval_put __P(( struct timeval *tp, double a ));
209 void timeval_cp  __P(( struct timeval *tp1, struct timeval *tp2 ));
210 void timeval_add __P(( struct timeval *tp1, struct timeval *tp2 ));
211 void timeval_sub __P(( struct timeval *tp1,  struct timeval *tp2 ));
212 void timeval_add_double __P(( struct timeval *tp, double time ));
213 double timeval2double   __P(( struct timeval *tp1 ));
214 
215 /*
216  * Grobal Variable
217  */
218 
219 #if defined(DBSC) || defined(DBSD)
220 int debug = 0 ;                   /* ON or OFF (default OFF)    */
221 #else
222 extern int debug;
223 #endif
224 
225 /*
226  * Grobal Function
227  */
228 
229 #if  defined(sun) && !defined(__svr4__)
230 extern sys_nerr;
231 extern *sys_errlist[];
232 #define strerror(err) (*sys_errlist[err])
233 /*#define volatile */
234 #endif
235