socket.c
1 /* $Id: socket.c 1.1 1995/01/01 07:11:14 cthuang Exp $ 2 * 3 * This module has been modified by Radim Kolar for OS/2 emx 4 */ 5 6 /*********************************************************************** 7 module: socket.c 8 program: popclient 9 SCCS ID: @(#)socket.c 1.5 4/1/94 10 programmer: Virginia Tech Computing Center 11 compiler: DEC RISC C compiler (Ultrix 4.1) 12 environment: DEC Ultrix 4.3 13 description: UNIX sockets code. 14 ***********************************************************************/ 15 16 #include <sys/types.h> 17 #include <sys/socket.h> 18 #include <fcntl.h> 19 #include <netinet/in.h> 20 #include <arpa/inet.h> 21 #include <netdb.h> 22 #include <sys/time.h> 23 #include <string.h> 24 #include <unistd.h> 25 #include <stdio.h> 26 #include <stdlib.h> 27 #include <stdarg.h> 28 29 int Socket(const char *host, int clientPort) 30 { 31 int sock; 32 unsigned long inaddr; 33 struct sockaddr_in ad; 34 struct hostent *hp; 35 36 memset(&ad, 0, sizeof(ad)); 37 ad.sin_family = AF_INET; 38 39 inaddr = inet_addr(host); 40 if (inaddr != INADDR_NONE) 41 memcpy(&ad.sin_addr, &inaddr, sizeof(inaddr)); 42 else 43 { 44 hp = gethostbyname(host); 45 if (hp == NULL) 46 return -1; 47 memcpy(&ad.sin_addr, hp->h_addr, hp->h_length); 48 } 49 ad.sin_port = htons(clientPort); 50 51 sock = socket(AF_INET, SOCK_STREAM, 0); 52 if (sock < 0) 53 return sock; 54 if (connect(sock, (struct sockaddr *)&ad, sizeof(ad)) < 0) 55 return -1; 56 return sock; 57 }
webbench.c
1 /* 2 * (C) Radim Kolar 1997-2004 3 * This is free software, see GNU Public License version 2 for 4 * details. 5 * 6 * Simple forking WWW Server benchmark: 7 * 8 * Usage: 9 * webbench --help 10 * 11 * Return codes: 12 * 0 - sucess 13 * 1 - benchmark failed (server is not on-line) 14 * 2 - bad param 15 * 3 - internal error, fork failed 16 * 17 */ 18 #include "socket.c" 19 #include <unistd.h> 20 #include <sys/param.h> 21 #include <rpc/types.h> 22 #include <getopt.h> 23 #include <strings.h> 24 #include <time.h> 25 #include <signal.h> 26 27 /* values */ 28 volatile int timerexpired=0; 29 int speed=0; 30 int failed=0; 31 int bytes=0; 32 /* globals */ 33 int http10=1; /* 0 - http/0.9, 1 - http/1.0, 2 - http/1.1 */ 34 /* Allow: GET, HEAD, OPTIONS, TRACE */ 35 #define METHOD_GET 0 36 #define METHOD_HEAD 1 37 #define METHOD_OPTIONS 2 38 #define METHOD_TRACE 3 39 #define PROGRAM_VERSION "1.5" 40 int method=METHOD_GET; 41 int clients=1; 42 int force=0; 43 int force_reload=0; 44 int proxyport=80; 45 char *proxyhost=NULL; 46 int benchtime=30; 47 /* internal */ 48 int mypipe[2]; 49 char host[MAXHOSTNAMELEN]; 50 #define REQUEST_SIZE 2048 51 char request[REQUEST_SIZE]; 52 53 static const struct option long_options[]= 54 { 55 {"force",no_argument,&force,1}, 56 {"reload",no_argument,&force_reload,1}, 57 {"time",required_argument,NULL,'t'}, 58 {"help",no_argument,NULL,'?'}, 59 {"http09",no_argument,NULL,'9'}, 60 {"http10",no_argument,NULL,'1'}, 61 {"http11",no_argument,NULL,'2'}, 62 {"get",no_argument,&method,METHOD_GET}, 63 {"head",no_argument,&method,METHOD_HEAD}, 64 {"options",no_argument,&method,METHOD_OPTIONS}, 65 {"trace",no_argument,&method,METHOD_TRACE}, 66 {"version",no_argument,NULL,'V'}, 67 {"proxy",required_argument,NULL,'p'}, 68 {"clients",required_argument,NULL,'c'}, 69 {NULL,0,NULL,0} 70 }; 71 72 /* prototypes */ 73 static void benchcore(const char* host,const int port, const char *request); 74 static int bench(void); 75 static void build_request(const char *url); 76 77 static void alarm_handler(int signal) 78 { 79 timerexpired=1; 80 } 81 82 static void usage(void) 83 { 84 fprintf(stderr, 85 "webbench [option]... URL " 86 " -f|--force Don't wait for reply from server. " 87 " -r|--reload Send reload request - Pragma: no-cache. " 88 " -t|--time <sec> Run benchmark for <sec> seconds. Default 30. " 89 " -p|--proxy <server:port> Use proxy server for request. " 90 " -c|--clients <n> Run <n> HTTP clients at once. Default one. " 91 " -9|--http09 Use HTTP/0.9 style requests. " 92 " -1|--http10 Use HTTP/1.0 protocol. " 93 " -2|--http11 Use HTTP/1.1 protocol. " 94 " --get Use GET request method. " 95 " --head Use HEAD request method. " 96 " --options Use OPTIONS request method. " 97 " --trace Use TRACE request method. " 98 " -?|-h|--help This information. " 99 " -V|--version Display program version. " 100 ); 101 }; 102 int main(int argc, char *argv[]) 103 { 104 int opt=0; 105 int options_index=0; 106 char *tmp=NULL; 107 108 if(argc==1) 109 { 110 usage(); 111 return 2; 112 } 113 114 while((opt=getopt_long(argc,argv,"912Vfrt:p:c:?h",long_options,&options_index))!=EOF ) 115 { 116 switch(opt) 117 { 118 case 0 : break; 119 case 'f': force=1;break; 120 case 'r': force_reload=1;break; 121 case '9': http10=0;break; 122 case '1': http10=1;break; 123 case '2': http10=2;break; 124 case 'V': printf(PROGRAM_VERSION" ");exit(0); 125 case 't': benchtime=atoi(optarg);break; 126 case 'p': 127 /* proxy server parsing server:port */ 128 tmp=strrchr(optarg,':'); 129 proxyhost=optarg; 130 if(tmp==NULL) 131 { 132 break; 133 } 134 if(tmp==optarg) 135 { 136 fprintf(stderr,"Error in option --proxy %s: Missing hostname. ",optarg); 137 return 2; 138 } 139 if(tmp==optarg+strlen(optarg)-1) 140 { 141 fprintf(stderr,"Error in option --proxy %s Port number is missing. ",optarg); 142 return 2; 143 } 144 *tmp='