Home | History | Annotate | Download | only in src
      1 /*
      2         Copyright (C) 1993-2012 Hewlett-Packard Company
      3 */
      4 
      5 #ifdef HAVE_CONFIG_H
      6 #include "config.h"
      7 #endif
      8 
      9 #if defined(HAVE_SYS_SOCKET_H)
     10 # include <sys/socket.h>
     11 #endif
     12 #if defined(HAVE_NETDB_H)
     13 # include <netdb.h>
     14 #endif
     15 #if !defined(HAVE_GETADDRINFO) || !defined(HAVE_GETNAMEINFO)
     16 # include "missing/getaddrinfo.h"
     17 #endif
     18 
     19 #define PAD_TIME 4
     20 /* library routine specifc defines                                      */
     21 #define         MAXSPECDATA     162     /* how many ints worth of data  */
     22                                         /* can tests send...            */
     23 #define         MAXTIMES        4       /* how many times may we loop   */
     24                                         /* to calibrate                 */
     25 #define         MAXCPUS         256     /* how many CPU's can we track */
     26 #define         MAXMESSAGESIZE  65536
     27 #define         MAXALIGNMENT    16384
     28 #define         MAXOFFSET        4096
     29 #define         DATABUFFERLEN   MAXMESSAGESIZE+MAXALIGNMENT+MAXOFFSET
     30 
     31 #define         DEBUG_ON                1
     32 #define         DEBUG_OFF               2
     33 #define         DEBUG_OK                3
     34 #define         NODE_IDENTIFY           4
     35 #define         CPU_CALIBRATE           5
     36 #define         PASSPHRASE              6
     37 
     38 #define         DO_TCP_STREAM           10
     39 #define         TCP_STREAM_RESPONSE     11
     40 #define         TCP_STREAM_RESULTS      12
     41 
     42 #define         DO_TCP_RR               13
     43 #define         TCP_RR_RESPONSE         14
     44 #define         TCP_RR_RESULTS          15
     45 
     46 #define         DO_UDP_STREAM           16
     47 #define         UDP_STREAM_RESPONSE     17
     48 #define         UDP_STREAM_RESULTS      18
     49 
     50 #define         DO_UDP_RR               19
     51 #define         UDP_RR_RESPONSE         20
     52 #define         UDP_RR_RESULTS          21
     53 
     54 #define         DO_DLPI_CO_STREAM       22
     55 #define         DLPI_CO_STREAM_RESPONSE 23
     56 #define         DLPI_CO_STREAM_RESULTS  24
     57 
     58 #define         DO_DLPI_CO_RR           25
     59 #define         DLPI_CO_RR_RESPONSE     26
     60 #define         DLPI_CO_RR_RESULTS      27
     61 
     62 #define         DO_DLPI_CL_STREAM       28
     63 #define         DLPI_CL_STREAM_RESPONSE 29
     64 #define         DLPI_CL_STREAM_RESULTS  30
     65 
     66 #define         DO_DLPI_CL_RR           31
     67 #define         DLPI_CL_RR_RESPONSE     32
     68 #define         DLPI_CL_RR_RESULTS      33
     69 
     70 #define         DO_TCP_CRR              34
     71 #define         TCP_CRR_RESPONSE        35
     72 #define         TCP_CRR_RESULTS         36
     73 
     74 #define         DO_STREAM_STREAM        37
     75 #define         STREAM_STREAM_RESPONSE  38
     76 #define         STREAM_STREAM_RESULTS   39
     77 
     78 #define         DO_STREAM_RR            40
     79 #define         STREAM_RR_RESPONSE      41
     80 #define         STREAM_RR_RESULTS       42
     81 
     82 #define         DO_DG_STREAM            43
     83 #define         DG_STREAM_RESPONSE      44
     84 #define         DG_STREAM_RESULTS       45
     85 
     86 #define         DO_DG_RR                46
     87 #define         DG_RR_RESPONSE          47
     88 #define         DG_RR_RESULTS           48
     89 
     90 #define         DO_FORE_STREAM          49
     91 #define         FORE_STREAM_RESPONSE    50
     92 #define         FORE_STREAM_RESULTS     51
     93 
     94 #define         DO_FORE_RR              52
     95 #define         FORE_RR_RESPONSE        53
     96 #define         FORE_RR_RESULTS         54
     97 
     98 #define         DO_HIPPI_STREAM         55
     99 #define         HIPPI_STREAM_RESPONSE   56
    100 #define         HIPPI_STREAM_RESULTS    57
    101 
    102 #define         DO_HIPPI_RR             52
    103 #define         HIPPI_RR_RESPONSE       53
    104 #define         HIPPI_RR_RESULTS        54
    105 
    106 #define         DO_XTI_TCP_STREAM       55
    107 #define         XTI_TCP_STREAM_RESPONSE 56
    108 #define         XTI_TCP_STREAM_RESULTS  57
    109 
    110 #define         DO_XTI_TCP_RR           58
    111 #define         XTI_TCP_RR_RESPONSE     59
    112 #define         XTI_TCP_RR_RESULTS      60
    113 
    114 #define         DO_XTI_UDP_STREAM       61
    115 #define         XTI_UDP_STREAM_RESPONSE 62
    116 #define         XTI_UDP_STREAM_RESULTS  63
    117 
    118 #define         DO_XTI_UDP_RR           64
    119 #define         XTI_UDP_RR_RESPONSE     65
    120 #define         XTI_UDP_RR_RESULTS      66
    121 
    122 #define         DO_XTI_TCP_CRR          67
    123 #define         XTI_TCP_CRR_RESPONSE    68
    124 #define         XTI_TCP_CRR_RESULTS     69
    125 
    126 #define         DO_TCP_TRR              70
    127 #define         TCP_TRR_RESPONSE        71
    128 #define         TCP_TRR_RESULTS         72
    129 
    130 #define         DO_TCP_NBRR             73
    131 #define         TCP_NBRR_RESPONSE       74
    132 #define         TCP_NBRR_RESULTS        75
    133 
    134 #define         DO_TCPIPV6_STREAM           76
    135 #define         TCPIPV6_STREAM_RESPONSE     77
    136 #define         TCPIPV6_STREAM_RESULTS      78
    137 
    138 #define         DO_TCPIPV6_RR               79
    139 #define         TCPIPV6_RR_RESPONSE         80
    140 #define         TCPIPV6_RR_RESULTS          81
    141 
    142 #define         DO_UDPIPV6_STREAM           82
    143 #define         UDPIPV6_STREAM_RESPONSE     83
    144 #define         UDPIPV6_STREAM_RESULTS      84
    145 
    146 #define         DO_UDPIPV6_RR               85
    147 #define         UDPIPV6_RR_RESPONSE         86
    148 #define         UDPIPV6_RR_RESULTS          87
    149 
    150 #define         DO_TCPIPV6_CRR              88
    151 #define         TCPIPV6_CRR_RESPONSE        89
    152 #define         TCPIPV6_CRR_RESULTS         90
    153 
    154 #define         DO_TCPIPV6_TRR              91
    155 #define         TCPIPV6_TRR_RESPONSE        92
    156 #define         TCPIPV6_TRR_RESULTS         93
    157 
    158 #define         DO_TCP_MAERTS               94
    159 #define         TCP_MAERTS_RESPONSE         95
    160 #define         TCP_MAERTS_RESULTS          96
    161 
    162 #define         DO_OMNI                     97
    163 #define         OMNI_RESPONSE               98
    164 #define         OMNI_RESULTS                99
    165 
    166 #define         DO_LWPSTR_STREAM           100
    167 #define         LWPSTR_STREAM_RESPONSE     110
    168 #define         LWPSTR_STREAM_RESULTS      120
    169 
    170 #define         DO_LWPSTR_RR               130
    171 #define         LWPSTR_RR_RESPONSE         140
    172 #define         LWPSTR_RR_RESULTS          150
    173 
    174 #define         DO_LWPDG_STREAM            160
    175 #define         LWPDG_STREAM_RESPONSE      170
    176 #define         LWPDG_STREAM_RESULTS       180
    177 
    178 #define         DO_LWPDG_RR                190
    179 #define         LWPDG_RR_RESPONSE          200
    180 #define         LWPDG_RR_RESULTS           210
    181 
    182 #define         DO_TCP_CC                  300
    183 #define         TCP_CC_RESPONSE            301
    184 #define         TCP_CC_RESULTS             302
    185 
    186 /* The DNS_RR test has been removed from netperf but we leave these
    187    here for historical purposes.  Those wanting to do DNS_RR tests
    188    should use netperf4 instead. */
    189 #define         DO_DNS_RR                  400
    190 #define         DNS_RR_RESPONSE            401
    191 #define         DNS_RR_RESULTS             402
    192 
    193 #define         DO_SCTP_STREAM             500
    194 #define         SCTP_STREAM_RESPONSE       501
    195 #define         SCTP_STREAM_RESULT         502
    196 
    197 #define         DO_SCTP_STREAM_MANY        510
    198 #define         SCTP_STREAM_MANY_RESPONSE  511
    199 #define         SCTP_STREAM_MANY_RESULT    512
    200 
    201 #define         DO_SCTP_RR                 520
    202 #define         SCTP_RR_RESPONSE           521
    203 #define         SCTP_RR_RESULT             502
    204 
    205 #define         DO_SCTP_RR_MANY            530
    206 #define         SCTP_RR_MANY_RESPONSE      531
    207 #define         SCTP_RR_MANY_RESULT        532
    208 
    209 #define         DO_SDP_STREAM              540
    210 #define         SDP_STREAM_RESPONSE        541
    211 #define         SDP_STREAM_RESULTS         542
    212 
    213 #define         DO_SDP_RR                  543
    214 #define         SDP_RR_RESPONSE            544
    215 #define         SDP_RR_RESULTS             545
    216 
    217 #define         DO_SDP_MAERTS              546
    218 #define         SDP_MAERTS_RESPONSE        547
    219 #define         SDP_MAERTS_RESULTS         548
    220 
    221 #define         DO_SDP_CRR                 549
    222 #define         SDP_CRR_RESPONSE           550
    223 #define         SDP_CRR_RESULTS            551
    224 
    225 #define         DO_SDP_CC                  552
    226 #define         SDP_CC_RESPONSE            553
    227 #define         SDP_CC_RESULTS             554
    228 
    229 #define         DO_SYSINFO                 600
    230 #define         SYSINFO_RESPONSE           601
    231 
    232 #if HAVE_INTTYPES_H
    233 # include <inttypes.h>
    234 #else
    235 # if HAVE_STDINT_H
    236 #  include <stdint.h>
    237 #else
    238 # ifdef WIN32
    239 #  include "missing\inttypes.h"
    240 # endif
    241 # endif
    242 #endif
    243 
    244 enum sock_buffer{
    245   SEND_BUFFER,
    246   RECV_BUFFER
    247 };
    248 
    249 enum netperf_output_modes {
    250   HUMAN = 0,
    251   CSV,
    252   KEYVAL,
    253 };
    254 
    255 /* some defines for security types, perhaps these would be better
    256    elsewhere but for now here they are */
    257 
    258 #define NSEC_UNKNOWN  -1
    259 #define NSEC_DISABLED 0
    260 #define NSEC_PERMISSIVE  1
    261 #define NSEC_ENFORCING 2
    262 
    263 #define NSEC_TYPE_UNKNOWN -1
    264 #define NSEC_TYPE_SELINUX 1
    265 
    266 #define NETFW_UNKNOWN -1
    267 #define NETFW_IPTABLES 1
    268 
    269  /* some of the fields in these structures are going to be doubles and */
    270  /* such. so, we probably want to ensure that they will start on */
    271  /* "double" boundaries. this will break compatability to pre-2.1 */
    272  /* releases, but then, backwards compatability has never been a */
    273  /* stated goal of netperf. raj 11/95 */
    274 
    275 union netperf_request_struct {
    276   struct {
    277     int     request_type;
    278     int     dummy;
    279     int     test_specific_data[MAXSPECDATA];
    280   } content;
    281   double dummy;
    282 };
    283 
    284 union netperf_response_struct {
    285   struct {
    286     int response_type;
    287     int serv_errno;
    288     int test_specific_data[MAXSPECDATA];
    289   } content;
    290   double dummy;
    291 };
    292 
    293 struct ring_elt {
    294   struct ring_elt *next;  /* next element in the ring */
    295   char *buffer_base;      /* in case we have to free it at somepoint */
    296   char *buffer_ptr;       /* the aligned and offset pointer */
    297   void *completion_ptr;   /* a pointer to information for async completion */
    298   /* these are for sendfile calls and at some point we should consider
    299      using a union but it isn't really all that much extra space */
    300   struct iovec *hdtrl;            /* a pointer to a header/trailer
    301 				     that we do not initially use and
    302 				     so should be set to NULL when the
    303 				     ring is setup. */
    304   off_t offset;                   /* the offset from the beginning of
    305 				     the file for this send */
    306   size_t length;                  /* the number of bytes to send -
    307 				     this is redundant with the
    308 				     send_size variable but I decided
    309 				     to include it anyway */
    310   int fildes;                     /* the file descriptor of the source
    311 				     file */
    312   int flags;                      /* the flags to pass to sendfile() -
    313 				     presently unused and should be
    314 				     set to zero when the ring is
    315 				     setup. */
    316 };
    317 
    318 /* everything in percent except otherwise stated */
    319 struct cpu_stats_struct {
    320   float cpu_util;  /* mandatory = 100% - %idle */
    321 
    322   /* The following are optional, dependent upon netcpu implementation */
    323   float cpu_user;
    324   float cpu_system;
    325   float cpu_iowait;
    326   float cpu_irq;
    327   float cpu_swintr;
    328 
    329   /* mandatory */
    330   float peak_cpu_util;
    331   int   peak_cpu_id;  /* ID of most loaded CPU */
    332 };
    333 
    334 /* +*+ SAF  Sorry about the hacks with errno; NT made me do it :(
    335 
    336  WinNT does define an errno.
    337  It is mostly a legacy from the XENIX days.
    338 
    339  Depending upon the version of the C run time that is linked in, it is
    340  either a simple variable (like UNIX code expects), but more likely it
    341  is the address of a procedure to return the error number.  So any
    342  code that sets errno is likely to be overwriting the address of this
    343  procedure.  Worse, only a tiny fraction of NT's errors get set
    344  through errno.
    345 
    346  So I have changed the netperf code to use a define Set_errno when
    347  that is it's intent.  On non-windows platforms this is just an
    348  assignment to errno.  But on NT this calls SetLastError.
    349 
    350  I also define errno (now only used on right side of assignments)
    351  on NT to be GetLastError.
    352 
    353  Similarly, perror is defined on NT, but it only accesses the same
    354  XENIX errors that errno covers.  So on NT this is redefined to be
    355  Perror and it expands all GetLastError texts. */
    356 
    357 
    358 #ifdef WIN32
    359 /* INVALID_SOCKET == INVALID_HANDLE_VALUE == (unsigned int)(~0) */
    360 /* SOCKET_ERROR == -1 */
    361 #define ENOTSOCK WSAENOTSOCK
    362 #define EINTR    WSAEINTR
    363 #define ENOBUFS  WSAENOBUFS
    364 #define EWOULDBLOCK    WSAEWOULDBLOCK
    365 #define EAFNOSUPPORT  WSAEAFNOSUPPORT
    366 /* I don't use a C++ style of comment because it upsets some C
    367    compilers, possibly even when it is inside an ifdef WIN32... */
    368 /* from public\sdk\inc\crt\errno.h */
    369 #define ENOSPC          28
    370 
    371 #ifdef errno
    372 /* delete the one from stdlib.h  */
    373 /*#define errno       (*_errno()) */
    374 #undef errno
    375 #endif
    376 #define errno GetLastError()
    377 #define Set_errno(num) SetLastError((num))
    378 
    379 #define perror(text) PrintWin32Error(stderr, (text))
    380 #define Print_errno(stream, text) PrintWin32Error((stream), (text))
    381 
    382 extern void PrintWin32Error(FILE *stream, LPSTR text);
    383 
    384 #if !defined(NT_PERF) && !defined(USE_LOOPER)
    385 #define NT_PERF
    386 #endif
    387 #else
    388 /* Really shouldn't use manifest constants! */
    389 /*+*+SAF There are other examples of "== -1" and "<0" that probably */
    390 /*+*+SAF should be cleaned up as well. */
    391 #define INVALID_SOCKET -1
    392 #define SOCKET_ERROR -1
    393 
    394 #define SOCKET int
    395 #define Set_errno(num) errno = (num)
    396 
    397 #define Print_errno(stream, text) fprintf((stream), "%s  errno %d\n", (text), errno)
    398 #endif
    399 
    400 /* Robin & Rick's kludge to try to have a timer signal EINTR by closing  */
    401 /* the socket from another thread can also return several other errors. */
    402 /* Let's define a macro to hide all of this. */
    403 
    404 #ifndef WIN32
    405 #define SOCKET_EINTR(return_value) (errno == EINTR)
    406 #define SOCKET_ECONNREFUSED(return_value) (errno == ECONNREFUSED)
    407 #define SOCKET_EADDRINUSE(return_value) (errno == EADDRINUSE)
    408 #define SOCKET_EADDRNOTAVAIL(return_value) (errno == EADDRNOTAVAIL)
    409 #define SOCKET_EAGAIN(return_value) (errno == EAGAIN)
    410 #define SOCKET_EWOULDBLOCK(return_value) (errno == EWOULDBLOCK)
    411 
    412 #else
    413 
    414 /* not quite sure I like the extra cases for WIN32 but that is what my
    415    WIN32 expert sugested.  I'm not sure what WSA's to put for
    416    EADDRINUSE */
    417 
    418 #define SOCKET_EINTR(return_value) \
    419 		(((return_value) == SOCKET_ERROR) && \
    420 	     ((errno == EINTR) || \
    421 	      (errno == WSAECONNABORTED) || \
    422 	      (errno == WSAECONNRESET) || \
    423 	      (errno == ENOTSOCK) ))
    424 #define SOCKET_EADDRINUSE(return_value) \
    425 		(((return_value) == SOCKET_ERROR) && \
    426 	     ((errno == WSAEADDRINUSE) ))
    427 #define SOCKET_EADDRNOTAVAIL(return_value) \
    428 		(((return_value) == SOCKET_ERROR) && \
    429 	     ((errno == WSAEADDRNOTAVAIL) ))
    430 /* guessing here, and equating for one that doesn't exist */
    431 #define SOCKET_EAGAIN(return_value) \
    432 (((return_value) == SOCKET_ERROR) && (errno == WSAEWOULDBLOCK))
    433 #define SOCKET_EWOULDBLOCK(return_value) \
    434   (((return_value) == SOCKET_ERROR) && (errno == WSAEWOULDBLOCK))
    435 #endif
    436 
    437 #ifdef HAVE_SENDFILE
    438 
    439 #endif /* HAVE_SENDFILE */
    440 
    441  /* the diferent codes to denote the type of CPU utilization */
    442  /* methods used */
    443 #define CPU_UNKNOWN     0
    444 #define HP_IDLE_COUNTER 1
    445 #define PSTAT           2
    446 #define TIMES           3
    447 #define LOOPER          4
    448 #define GETRUSAGE       5
    449 #define NT_METHOD       6
    450 #define KSTAT           7
    451 #define PROC_STAT       8
    452 #define SYSCTL          9
    453 #define PERFSTAT       10
    454 #define KSTAT_10       11
    455 #define OSX            12
    456 
    457 #define BADCH ('?')
    458 
    459 #ifndef NETLIB
    460 #ifdef WIN32
    461 #ifndef _GETOPT_
    462 #define _GETOPT_
    463 
    464 int getopt(int argc, char **argv, char *optstring);
    465 
    466 extern char *optarg;		/* returned arg to go with this option */
    467 extern int optind;		/* index to next argv element to process */
    468 extern int opterr;		/* should error messages be printed? */
    469 extern int optopt;		/* */
    470 
    471 #endif /* _GETOPT_ */
    472 
    473 extern  SOCKET     win_kludge_socket, win_kludge_socket2;
    474 #endif /* WIN32 */
    475 
    476 extern  int   local_proc_affinity, remote_proc_affinity;
    477 
    478 /* these are to allow netperf to be run easily through those evil,
    479    end-to-end breaking things known as firewalls */
    480 extern char local_data_port[10];
    481 extern char remote_data_port[10];
    482 
    483 extern char *local_data_address;
    484 extern char *remote_data_address;
    485 
    486 extern char *local_sysname, *remote_sysname;
    487 extern char *local_release, *remote_release;
    488 extern char *local_version, *remote_version;
    489 extern char *local_machine, *remote_machine;
    490 
    491 extern int local_data_family;
    492 extern int remote_data_family;
    493 extern int control_family;
    494 
    495 extern  union netperf_request_struct netperf_request;
    496 extern  union netperf_response_struct netperf_response;
    497 
    498 extern struct cpu_stats_struct lib_local_cpu_stats;
    499 extern struct cpu_stats_struct lib_remote_cpu_stats;
    500 extern float                   lib_elapsed;
    501 extern float                   lib_local_maxrate;
    502 
    503 extern  char    libfmt;
    504 
    505 extern  int     cpu_method;
    506 extern  int     lib_num_loc_cpus;
    507 extern  int     lib_num_rem_cpus;
    508 extern  SOCKET  server_sock;
    509 extern  int     times_up;
    510 extern  FILE    *where;
    511 extern  int     loops_per_msec;
    512 extern  float   lib_local_per_cpu_util[];
    513 
    514 extern enum netperf_output_modes netperf_output_mode;
    515 
    516 #if defined(WANT_INTERVALS) || defined(WANT_DEMO)
    517 
    518 extern int    demo_mode;
    519 extern double demo_interval;
    520 extern double demo_units;
    521 extern double units_this_tick;
    522 #if defined(WANT_DEMO)
    523 extern void   demo_rr_interval(uint32_t units);
    524 extern void   demo_rr_setup(uint32_t units);
    525 extern void   demo_stream_interval(uint32_t units);
    526 extern void   demo_interval_tick(uint32_t units);
    527 extern void   demo_interval_final();
    528 #endif
    529 #endif
    530 
    531 extern  void    netlib_init();
    532 extern  int     netlib_get_page_size();
    533 extern  void    install_signal_catchers();
    534 extern  struct addrinfo *resolve_host(char hostname[],
    535 				      char port[],
    536 				      int af);
    537 extern  void    establish_control(char hostname[],
    538 				  char port[],
    539 				  int af,
    540 				  char local_hostname[],
    541 				  char local_port[],
    542 				  int local_af);
    543 extern  void    shutdown_control();
    544 extern  void    init_stat();
    545 extern  void    send_request();
    546 extern  void    recv_response();
    547 extern  void    send_response();
    548 extern  int     recv_request();
    549 extern  int     recv_request_timed_n(int n, int seconds);
    550 extern  void    send_request_n(int n);  /* convert only the first N ints */
    551 extern  void    recv_response_n(int n); /* of the test-specific data via */
    552 extern  void    send_response_n(int n); /* htonl/ntonl as required */
    553 extern  int     recv_request_n(int n);
    554 extern  void    fixup_request_n(int n);
    555 extern  void    dump_request();
    556 extern  void    dump_addrinfo(FILE *dumploc, struct addrinfo *info,
    557 			      char *host, char *port, int family);
    558 extern  void    start_timer(int time);
    559 extern  void    stop_timer();
    560 extern  void    cpu_start(int measure_cpu);
    561 extern  void    cpu_stop(int measure_cpu, float *elapsed);
    562 extern  void	calculate_confidence(int confidence_iterations,
    563 		     float time,
    564 		     double result,
    565 		     float loc_cpu,
    566 		     float rem_cpu,
    567 		     float loc_sd,
    568 		     float rem_sd);
    569 extern  void	retrieve_confident_values(float *elapsed_time,
    570 			  double *thruput,
    571 			  float *local_cpu_utilization,
    572 			  float *remote_cpu_utilization,
    573 			  float *local_service_demand,
    574 			  float *remote_service_demand);
    575 extern  double  get_result_confid();
    576 extern  double  get_loc_cpu_confid();
    577 extern  double  get_rem_cpu_confid();
    578 extern  void    display_confidence();
    579 extern  void    get_sock_buffer(SOCKET sd,
    580 				enum sock_buffer which,
    581 				int *effective_sizep);
    582 extern  void    set_sock_buffer(SOCKET sd,
    583 				enum sock_buffer which,
    584 				int requested_size,
    585 				int *effective_sizep);
    586 extern  char   *format_units();
    587 
    588 extern  void    get_remote_system_info();
    589 
    590 extern  char    *inet_ftos(int family);
    591 extern  char    *inet_ttos(int type);
    592 extern  char    *inet_ptos(int protocol);
    593 extern  char    *nsec_enabled_to_str(int enabled);
    594 extern  char    *nsec_type_to_str(int type);
    595 extern  double  ntohd(double net_double);
    596 extern  double  htond(double host_double);
    597 extern  int     inet_nton(int af, const void *src, char *dst, int cnt);
    598 extern  void    random_ip_address(struct addrinfo *res, int mask_len);
    599 extern  void    libmain();
    600 extern  double  calc_thruput(double units_received);
    601 extern  double  calc_thruput_interval(double units_received,double elapsed);
    602 extern  double  calc_thruput_omni(double units_received);
    603 extern  double  calc_thruput_interval_omni(double units_received,double elapsed);
    604 extern  float   calibrate_local_cpu(float local_cpu_rate);
    605 extern  float   calibrate_remote_cpu();
    606 extern  void    bind_to_specific_processor(int processor_affinity,int use_cpu_map);
    607 extern int      set_nonblock (SOCKET sock);
    608 extern char     *find_egress_interface(struct sockaddr *source, struct sockaddr *dest);
    609 extern char     *find_interface_slot(char *interface_name);
    610 extern void     find_interface_ids(char *interface_name, int *vendor, int *device, int *sub_vend, int *sub_dev);
    611 extern void     find_driver_info(char *ifname, char *driver, char *version, char *firmware, char *bus, int len);
    612 extern void     find_system_info(char **system_model, char **cpu_model, int *cpu_frequency);
    613 extern int      HIST_get_percentile();
    614 extern void     HIST_get_stats();
    615 extern void     HIST_purge();
    616 extern void     find_security_info(int *enabled, int *type, char **specific);
    617 extern void     demo_first_timestamp();
    618 extern void     demo_reset();
    619 extern void     demo_stream_setup(uint32_t a, uint32_t b);
    620 #ifndef WIN32
    621 
    622 /* WIN32 requires that at least one of the file sets to select be
    623  non-null.  Since msec_sleep routine is only called by nettest_dlpi &
    624  nettest_unix, let's duck this issue. */
    625 
    626 extern int msec_sleep( int msecs );
    627 #endif  /* WIN32 */
    628 extern  float   calc_cpu_util(float elapsed_time);
    629 extern  float	calc_service_demand(double units_sent,
    630 				    float elapsed_time,
    631 				    float cpu_utilization,
    632 				    int num_cpus);
    633 /* this one determines the unit divisor based on libfmt */
    634 extern  float	calc_service_demand_fmt(double units_sent,
    635 					float elapsed_time,
    636 					float cpu_utilization,
    637 					int num_cpus);
    638 #if defined(__hpux)
    639 extern  void    catcher(int, siginfo_t *,void *);
    640 #else
    641 extern  void    catcher(int);
    642 #endif /* __hpux */
    643 extern  struct ring_elt *allocate_buffer_ring();
    644 extern void access_buffer(char *buffer_ptr,
    645 			  int length,
    646 			  int dirty_count,
    647 			  int clean_count);
    648 
    649 #ifdef HAVE_ICSC_EXS
    650 extern  struct ring_elt *allocate_exs_buffer_ring();
    651 #endif /* HAVE_ICSC_EXS */
    652 
    653 #ifdef HAVE_SENDFILE
    654 extern  struct ring_elt *alloc_sendfile_buf_ring();
    655 extern  int netperf_sendfile(SOCKET send_socket, struct ring_elt *send_ring);
    656 #endif /* HAVE_SENDFILE */
    657 
    658 #ifdef WANT_DLPI
    659 /* it seems that AIX in its finite wisdom has some bogus define in an
    660    include file which defines "rem_addr" which then screws-up this extern
    661    unless we change the names to protect the guilty. reported by Eric
    662    Jones */
    663 extern int dl_connect(int fd, unsigned char *remote_addr, int remote_addr_len);
    664 extern int dl_bind(int fd, int sap, int mode, char *dlsap_ptr, int *dlsap_len);
    665 extern  int     dl_open(char devfile[], int ppa);
    666 #endif /* WANT_DLPI */
    667 extern  char    format_cpu_method(int method);
    668 extern unsigned int convert(char *string);
    669 extern unsigned int convert_timespec(char *string);
    670 
    671 #ifdef WANT_INTERVALS
    672 extern void start_itimer(unsigned int interval_len_msec);
    673 extern void stop_itimer(void);
    674 #endif
    675  /* these are all for the confidence interval stuff */
    676 extern double confidence;
    677 extern double result_confid;
    678 extern double loc_cpu_confid;
    679 extern double rem_cpu_confid;
    680 extern int lib_cpu_map[];
    681 #endif
    682 
    683 #ifdef WIN32
    684 #define close(x)	closesocket(x)
    685 #define strcasecmp(a,b) _stricmp(a,b)
    686 #define getpid() ((int)GetCurrentProcessId())
    687 #endif
    688 
    689 #ifdef WIN32
    690 extern HANDLE WinTimer;
    691 #if 0
    692 /* Should really use safe string functions; but not for now... */
    693 #include <strsafe.h>
    694 /* Microsoft has deprecated _snprintf; it isn't guarenteed to null terminate the result buffer. */
    695 /* They want us to call StringCbPrintf instead; it always null terminates the string. */
    696 #endif
    697 
    698 #define snprintf _snprintf
    699 #define strdup   _strdup
    700 #endif
    701 
    702 /* Define a macro to align a buffer with an offset from a power of 2
    703    boundary. */
    704 
    705 #ifndef WIN32
    706 #define ULONG_PTR unsigned long
    707 #endif
    708 
    709 #define ALIGN_BUFFER(BufPtr, Align, Offset) \
    710   (char *)(( (ULONG_PTR)(BufPtr) + \
    711 			(ULONG_PTR) (Align) -1) & \
    712 			~((ULONG_PTR) (Align) - 1)) + (ULONG_PTR)(Offset)
    713 
    714  /* if your system has bcopy and bzero, include it here, otherwise, we */
    715  /* will try to use memcpy aand memset. fix from Bruce Barnett @ GE. */
    716 #if defined(hpux) || defined (__VMS)
    717 #define HAVE_BCOPY
    718 #define HAVE_BZERO
    719 #endif
    720 
    721 #ifdef WIN32
    722 #define HAVE_MIN
    723 #else
    724 #define _stdcall
    725 #define _cdecl
    726 #endif
    727 
    728 #ifndef HAVE_BCOPY
    729 #define bcopy(s,d,h) memcpy((d),(s),(h))
    730 #endif /* HAVE_BCOPY */
    731 
    732 #ifndef HAVE_BZERO
    733 #define bzero(p,h) memset((p),0,(h))
    734 #endif /* HAVE_BZERO */
    735 
    736 #ifndef HAVE_MIN
    737 #define min(a,b) ((a < b) ? a : b)
    738 #endif /* HAVE_MIN */
    739 
    740 #ifdef USE_PERFSTAT
    741 # include <libperfstat.h>
    742 #endif
    743