/***************************************************************************
 * DBS: Distributed Benchmark System
 * Copyright (c) 1995, 1996, 1997 Yukio Murayama
 * Copyright (c) 1995, 1996, 1997 Nara Institute of Science and Technology
 * All rights reserved.
 *
 * Permission to use, copy, modify and distribute this software and its
 * documentation is hereby granted, provided only with the following
 * conditions are satisfied:
 *
 * 1. Both the copyright notice and this permission notice appear in
 *    all copies of the software, derivative works or modified versions,
 *    and any portions thereof, and that both notices appear in
 *    supporting documentation.
 * 2. All advertising materials mentioning features or use of this
 *    software must display the following acknowledgement:
 *      This product includes software developed by Nara Institute of 
 *      Science and Technology and its contributors.
 * 3. Neither the name of Nara Institute of Science and Technology nor 
 *    the names of its contributors may be used to endorse or promote 
 *    products derived from this software without specific prior written
 *    permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND NARA 
 * INSTITUTE OF SCIENCE AND TECHNOLOGY DISCLAIMS ANY LIABILITY OF 
 * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF 
 * THIS SOFTWARE. ALSO, THERE IS NO WARRANTY IMPLIED OR OTHERWISE, 
 * NOR IS SUPPORT PROVIDED.
 *
 * Feedback of the results generated from any improvements or
 * extensions made to this software would be much appreciated.
 * Any such feedback should be sent to:
 *
 *  Yukio Murayama
 *  E-mail:  <yukio-m@is.aist-nara.ac.jp>
 *  URL:     <http://shika.aist-nara.ac.jp/member/yukio-m/index.html>
 *  Address: Graduate School of Information Science, 
 *           Nara Institute of Science and Technology,
 *           Takayama 8916-5, Ikoma, Nara, Japan
 *
 * Nara Institute of Science and Technology has the rights to 
 * redistribute these changes.
 ***************************************************************************/
/******************************************************************
 * Distributed Benchmark System
 * DBS Header File
 * $Revision: 1.27 $
 * $Date: 1997/07/11 00:54:34 $
 * $Author: yukio-m $
 *****************************************************************/

#ifdef __P
#undef __P
#endif

#if  (defined(sun) && !defined(__svr4__)) || defined(__hpux)
#define __P(prots)      ()
#else
#define __P(prots)    prots
#endif

#include <sys/time.h>

/*
 * Defines
 */

#define DBS_VERSION "DBS Version 1.1.5"
/*
dbs-1.1.5
*/
#define DBS_MAJOR_VERSION     1
#define DBS_MINOR_VERSION     1
#define DBS_PATCH_VERSION     ".5"

#define OFF                   0
#define ON                    1
#define BEFORE               11
#define AFTER                12
#define TCP                   1
#define UDP                   2
#define SEND                  1
#define RECEIVE               2
#define SERVER          RECEIVE
#define CLIENT             SEND
#define STREAM                1
#define PACKET                2

#define MAXHOSTNAME         256
#define LISTEN_NUM           10
#define MAX_COLUMN         1024
#define CHAR_ARRAY          256
#define RECV_DELAY_OFFSET     1.0
#define START_TIME_OFFSET    10.0
#define END_TIME_OFFSET1      5
#define END_TIME_OFFSET2      5
/*#define END_TIME_OFFSET       (END_TIME_OFFSET1+END_TIME_OFFSET2)*/
#define WARN_TIME_SYNC        0.1
#define MAX_TIME_SYNC        10.0
#define WARN_END_TIME       600.0
#define MAX_END_TIME       3600.0
#define DEFAULT_PORT      10710

/*
 * Definition of Grobal Variable
 */

/*
 * Error Code 
 */
#define NORMAL          0
#define ABNORMAL        1
#define BIND            2
#define GETHOSTBYNAME   3
#define SOCKET          4
#define ACCEPT          5
#define FORK            6
#define ACCESSDENY      7
#define MALLOC          8
#define TIME            9
#define CONNECT        10
#define SOSNDBUF       11
#define SORCVBUF       12
#define SODEBUG        13
#define TCPNODELAY     14
#define RECVERROR      15
#define RECVFROM       16
#define SIGNAL         17
#define TCPDEBUG       18
#define TIMESYNC       19
#define TIMEOUT        20
#define TCPMAXSEG      21
#define INTERNALERROR  22

#ifdef DBSC
static char *errmsg[] = {
    "NORMAL",                               /*  0 */
    "ABNORMAL",                             /*  1 */
    "bind error (Address already in use)",  /*  2 */
    "gethostbyname error",                  /*  3 */
    "socket error",                         /*  4 */
    "accept error",                         /*  5 */
    "fork error",                           /*  6 */
    "DBS Daemon Access Denyed",             /*  7 */
    "malloc error",                         /*  8 */
    "TIME is Wrong",                        /*  9 */
    "connect error",                        /* 10 */
    "SO_SNDBUF error",                      /* 11 */
    "SO_RCVBUF error",                      /* 12 */
    "SO_DEBUG error",                       /* 13 */
    "TCP_NODELAY error",                    /* 14 */
    "recv error",                           /* 15 */
    "recvfrom error",                       /* 16 */
    "signal error",                         /* 17 */
    "TCP DEBUG error",                      /* 18 */
    "TIME SYNC error",                      /* 19 */
    "TIME OUT",                             /* 20 */
    "Set MSS error",                        /* 21 */
    "Internal Error!!!!!!!!!! I'm Sorry."   /* 22 */
};
#endif

/*
 * DBS Macro Program
 */

#define RECV(FD, ADDR, SIZE)  {\
                                   int _i, _r, _n;\
                                   _r = (SIZE), _i=0;\
                                   while(_r > 0){\
                                       if((_n=recv((FD), (char *)(ADDR)+_i, _r, 0)) < 0){\
                                           perror("RECV DATA");\
                                           exit(1);\
                                       }\
                                       _r -= _n;\
                                       _i += _n;\
                                   }\
                              }

#if !defined(MIN)
#define MIN(A,B) (((A)<(B))?(A):(B))
#endif

#if !defined(MAX)
#define MAX(A,B) (((A)>(B))?(A):(B))
#endif

#define GET_IP_ADDR(A,B)  (0xff & ((A) >> ((B-1)*8)))

#define DEBUGMSG(A,B)  if(debug >= (A)) fprintf(stderr, B), fflush(stderr);
#define DEBUGMSG2(A,B) if(debug >= (A)) {B; fflush(stderr);}

#if !defined(__SVR4) && !defined(__svr4) && !defined(SYSTYPE_SVR4)
#define SIGNAL_INIT           int oldmask, mask=(sigmask(SIGINT)|sigmask(SIGPIPE)|sigmask(SIGQUIT))
#define BEGIN_CRITICAL_REGION oldmask=sigblock(mask)
#define END_CRITICAL_REGION   sigsetmask(oldmask)
#else
#define SIGNAL_INIT           (0)
#define BEGIN_CRITICAL_REGION (sighold(SIGINT),sighold(SIGPIPE),sighold(SIGQUIT))
#define END_CRITICAL_REGION   (sigrelse(SIGINT),sigrelse(SIGPIPE),sigrelse(SIGQUIT))
#endif

#define timeval_get(tp) ((double)tp.tv_sec + (double)tp.tv_usec/1000000.0)

void timeval_cp  __P(( struct timeval *origin_time, struct timeval *current_time ));
void timeval_add __P(( struct timeval *origin_time, struct timeval *offset_time ));

void timeval_put __P(( struct timeval *tp, double a ));
void timeval_cp  __P(( struct timeval *tp1, struct timeval *tp2 ));
void timeval_add __P(( struct timeval *tp1, struct timeval *tp2 ));
void timeval_sub __P(( struct timeval *tp1,  struct timeval *tp2 ));
void timeval_add_double __P(( struct timeval *tp, double time ));
double timeval2double   __P(( struct timeval *tp1 ));

/*
 * Grobal Variable
 */

#if defined(DBSC) || defined(DBSD) 
int debug = 0 ;                   /* ON or OFF (default OFF)    */
#else
extern int debug;
#endif

/*
 * Grobal Function
 */

#if  defined(sun) && !defined(__svr4__)
extern sys_nerr;
extern *sys_errlist[];
#define strerror(err) (*sys_errlist[err])
/*#define volatile */
#endif


syntax highlighted by Code2HTML, v. 0.9.1