netperf.c
Upload User: kvgkvg
Upload Date: 2015-05-07
Package Size: 1129k
Code Size: 8k
Development Platform:

C/C++

  1. /*
  2.  
  3.    Copyright (C) 1993-2007 Hewlett-Packard Company
  4.                          ALL RIGHTS RESERVED.
  5.  
  6.   The enclosed software and documentation includes copyrighted works
  7.   of Hewlett-Packard Co. For as long as you comply with the following
  8.   limitations, you are hereby authorized to (i) use, reproduce, and
  9.   modify the software and documentation, and to (ii) distribute the
  10.   software and documentation, including modifications, for
  11.   non-commercial purposes only.
  12.       
  13.   1.  The enclosed software and documentation is made available at no
  14.       charge in order to advance the general development of
  15.       high-performance networking products.
  16.  
  17.   2.  You may not delete any copyright notices contained in the
  18.       software or documentation. All hard copies, and copies in
  19.       source code or object code form, of the software or
  20.       documentation (including modifications) must contain at least
  21.       one of the copyright notices.
  22.  
  23.   3.  The enclosed software and documentation has not been subjected
  24.       to testing and quality control and is not a Hewlett-Packard Co.
  25.       product. At a future time, Hewlett-Packard Co. may or may not
  26.       offer a version of the software and documentation as a product.
  27.   
  28.   4.  THE SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS".
  29.       HEWLETT-PACKARD COMPANY DOES NOT WARRANT THAT THE USE,
  30.       REPRODUCTION, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR
  31.       DOCUMENTATION WILL NOT INFRINGE A THIRD PARTY'S INTELLECTUAL
  32.       PROPERTY RIGHTS. HP DOES NOT WARRANT THAT THE SOFTWARE OR
  33.       DOCUMENTATION IS ERROR FREE. HP DISCLAIMS ALL WARRANTIES,
  34.       EXPRESS AND IMPLIED, WITH REGARD TO THE SOFTWARE AND THE
  35.       DOCUMENTATION. HP SPECIFICALLY DISCLAIMS ALL WARRANTIES OF
  36.       MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  37.   
  38.   5.  HEWLETT-PACKARD COMPANY WILL NOT IN ANY EVENT BE LIABLE FOR ANY
  39.       DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
  40.       (INCLUDING LOST PROFITS) RELATED TO ANY USE, REPRODUCTION,
  41.       MODIFICATION, OR DISTRIBUTION OF THE SOFTWARE OR DOCUMENTATION.
  42.  
  43. */
  44. char netperf_id[]="
  45. @(#)netperf.c (c) Copyright 1993-2007 Hewlett-Packard Company. Version 2.4.3";
  46. #ifdef HAVE_CONFIG_H
  47. #include "config.h"
  48. #endif
  49. #include <stdio.h>
  50. #include <stdlib.h>
  51. #ifdef HAVE_STRINGS_H
  52. #include <strings.h>
  53. #endif
  54. /* FreeBSD doesn't like socket.h before types are set. */
  55. #if __FreeBSD__
  56. # include <sys/types.h>
  57. #endif
  58. #ifndef WIN32
  59. /* this should only be temporary */
  60. #include <sys/socket.h>
  61. #endif
  62. #ifdef WIN32
  63. #include <winsock2.h>
  64. #include <windows.h>
  65. #endif /* WIN32 */
  66. #include "netsh.h"
  67. #include "netlib.h"
  68. #include "nettest_bsd.h"
  69. #ifdef WANT_UNIX
  70. #include "nettest_unix.h"
  71. #endif /* WANT_UNIX */
  72. #ifdef WANT_XTI
  73. #include "nettest_xti.h"
  74. #endif /* WANT_XTI */
  75. #ifdef WANT_DLPI
  76. #include "nettest_dlpi.h"
  77. #endif /* WANT_DLPI */
  78. #ifdef WANT_SDP
  79. #include "nettest_sdp.h"
  80. #endif
  81. /* The DNS tests have been removed from netperf2. Those wanting to do
  82.    DNS_RR tests should use netperf4 instead. */
  83. #ifdef DO_DNS
  84. #error DNS tests have been removed from netperf. Use netperf4 instead
  85. #endif /* DO_DNS */
  86. #ifdef WANT_SCTP
  87. #include "nettest_sctp.h"
  88. #endif
  89.  /* this file contains the main for the netperf program. all the other */
  90.  /* routines can be found in the file netsh.c */
  91. int _cdecl
  92. main(int argc, char *argv[])
  93. {
  94. #ifdef WIN32
  95.   WSADATA wsa_data ;
  96.   
  97.   /* Initialize the winsock lib ( version 2.2 ) */
  98.   if ( WSAStartup(MAKEWORD(2,2), &wsa_data) == SOCKET_ERROR ){
  99.     printf("WSAStartup() failed : %dn", GetLastError()) ;
  100.     return 1 ;
  101.   }
  102. #endif /* WIN32 */
  103.   
  104.   netlib_init();
  105.   set_defaults();
  106.   scan_cmd_line(argc,argv);
  107.   
  108.   if (debug) {
  109.     dump_globals();
  110.     install_signal_catchers();
  111.   }
  112.   
  113.   if (debug) {
  114.     printf("remotehost is %s and port %sn",host_name,test_port);
  115.     fflush(stdout);
  116.   }
  117.   
  118.   
  119.   if (!no_control) {
  120.     establish_control(host_name,test_port,address_family,
  121.       local_host_name,local_test_port,local_address_family);
  122.   }
  123.   
  124.   if (strcasecmp(test_name,"TCP_STREAM") == 0) {
  125.     send_tcp_stream(host_name);
  126.   }
  127.   else if (strcasecmp(test_name,"TCP_MAERTS") == 0) {
  128.     send_tcp_maerts(host_name);
  129.   }
  130. #ifdef HAVE_ICSC_EXS
  131.   else if (strcasecmp(test_name,"EXS_TCP_STREAM") == 0) {
  132.     send_exs_tcp_stream(host_name);
  133.   }
  134. #endif /* HAVE_ICSC_EXS */
  135. #ifdef HAVE_SENDFILE
  136.   else if (strcasecmp(test_name,"TCP_SENDFILE") == 0) {
  137.     sendfile_tcp_stream(host_name);
  138.   }
  139. #endif /* HAVE_SENDFILE */
  140.   else if (strcasecmp(test_name,"TCP_RR") == 0) {
  141.     send_tcp_rr(host_name);
  142.   }
  143.   else if (strcasecmp(test_name,"TCP_CRR") == 0) {
  144.     send_tcp_conn_rr(host_name);
  145.   }
  146.   else if (strcasecmp(test_name,"TCP_CC") == 0) {
  147.     send_tcp_cc(host_name);
  148.   }
  149. #ifdef DO_1644
  150.   else if (strcasecmp(test_name,"TCP_TRR") == 0) {
  151.     send_tcp_tran_rr(host_name);
  152.   }
  153. #endif /* DO_1644 */
  154. #ifdef DO_NBRR
  155.   else if (strcasecmp(test_name,"TCP_NBRR") == 0) {
  156.     send_tcp_nbrr(host_name);
  157.   }
  158. #endif /* DO_NBRR */
  159.   else if (strcasecmp(test_name,"UDP_STREAM") == 0) {
  160.     send_udp_stream(host_name);
  161.   }
  162.   else if (strcasecmp(test_name,"UDP_RR") == 0) {
  163.     send_udp_rr(host_name);
  164.   }
  165.   else if (strcasecmp(test_name,"LOC_CPU") == 0) {
  166.     loc_cpu_rate();
  167.   }
  168.   else if (strcasecmp(test_name,"REM_CPU") == 0) {
  169.     rem_cpu_rate();
  170.   }
  171. #ifdef WANT_DLPI
  172.   else if (strcasecmp(test_name,"DLCO_RR") == 0) {
  173.     send_dlpi_co_rr(host_name);
  174.   }
  175.   else if (strcasecmp(test_name,"DLCL_RR") == 0) {
  176.     send_dlpi_cl_rr(host_name);
  177.   }
  178.   else if (strcasecmp(test_name,"DLCO_STREAM") == 0) {
  179.     send_dlpi_co_stream(host_name);
  180.   }
  181.   else if (strcasecmp(test_name,"DLCL_STREAM") == 0) {
  182.     send_dlpi_cl_stream(host_name);
  183.   }
  184. #endif /* WANT_DLPI */
  185. #ifdef WANT_UNIX
  186.   else if (strcasecmp(test_name,"STREAM_RR") == 0) {
  187.     send_stream_rr(host_name);
  188.   }
  189.   else if (strcasecmp(test_name,"DG_RR") == 0) {
  190.     send_dg_rr(host_name);
  191.   }
  192.   else if (strcasecmp(test_name,"STREAM_STREAM") == 0) {
  193.     send_stream_stream(host_name);
  194.   }
  195.   else if (strcasecmp(test_name,"DG_STREAM") == 0) {
  196.     send_dg_stream(host_name);
  197.   }
  198. #endif /* WANT_UNIX */
  199. #ifdef WANT_XTI
  200.   else if (strcasecmp(test_name,"XTI_TCP_STREAM") == 0) {
  201.     send_xti_tcp_stream(host_name);
  202.   }
  203.   else if (strcasecmp(test_name,"XTI_TCP_RR") == 0) {
  204.     send_xti_tcp_rr(host_name);
  205.   }
  206.   else if (strcasecmp(test_name,"XTI_UDP_STREAM") == 0) {
  207.     send_xti_udp_stream(host_name);
  208.   }
  209.   else if (strcasecmp(test_name,"XTI_UDP_RR") == 0) {
  210.     send_xti_udp_rr(host_name);
  211.   }
  212. #endif /* WANT_XTI */
  213.   
  214. #ifdef WANT_SCTP
  215.   else if (strcasecmp(test_name, "SCTP_STREAM") == 0) {
  216.     send_sctp_stream(host_name);
  217.   }       
  218.   else if (strcasecmp(test_name, "SCTP_RR") == 0) {
  219.     send_sctp_rr(host_name);
  220.   }
  221.   else if (strcasecmp(test_name, "SCTP_STREAM_MANY") == 0) {
  222.     send_sctp_stream_1toMany(host_name);
  223.   }
  224.   else if (strcasecmp(test_name, "SCTP_RR_MANY") == 0) {
  225.     send_sctp_stream_1toMany(host_name);
  226.   }
  227. #endif
  228.   
  229. #ifdef DO_DNS
  230.   else if (strcasecmp(test_name,"DNS_RR") == 0) {
  231.     fprintf(stderr,
  232.   "DNS tests can now be found in netperf4.n");
  233.     fflush(stderr);
  234.     exit(-1);
  235.   }
  236. #endif /* DO_DNS */
  237. #ifdef WANT_SDP
  238.   else if (strcasecmp(test_name,"SDP_STREAM") == 0) {
  239.     send_sdp_stream(host_name);
  240.   }
  241.   else if (strcasecmp(test_name,"SDP_MAERTS") == 0) {
  242.     send_sdp_maerts(host_name);
  243.   }
  244.   else if (strcasecmp(test_name,"SDP_RR") == 0) {
  245.     send_sdp_rr(host_name);
  246.   }
  247. #endif /* WANT_SDP */
  248.   else {
  249.     printf("The test you requested is unknown to this netperf.n");
  250.     printf("Please verify that you have the correct test name, n");
  251.     printf("and that test family has been compiled into this netperf.n");
  252.     exit(1);
  253.   }
  254.   
  255.   if (!no_control) {
  256.     shutdown_control();
  257.   }
  258.   
  259. #ifdef WIN32
  260.   /* Cleanup the winsock lib */
  261.   WSACleanup();
  262. #endif
  263.   
  264.   return(0);
  265. }