rem: printf("received reply from "); warning_extract(crlf); printf("after %.3f ms", deltaT(&sendtime, &recvtime));
add: printf("(%.3f ms) %s\n", deltaT(&sendtime, &recvtime), reply);
context: void shoot(char *buff){	struct sockaddr_in	addr, sockname;	struct timeval	tv, sendtime, recvtime, firstsendt;	struct timezone tz;	struct pollfd sockerr;	int ssock, redirected, retryAfter, nretries;	int sock, i, len, ret, usrlocstep, randretrys;	char *contact, *crlf, *foo, *bar;	char reply[BUFSIZE];	fd_set	fd;	socklen_t slen;	regex_t* regexp;	regex_t* redexp;	redirected = 1;	nretries = 5;	retryAfter = 5000;	usrlocstep = 0;	/* create a sending socket */	sock = (int)socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);	if (sock==-1) {		perror("no client socket");		exit(2);	}	/* create a listening socket */	ssock = (int)socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);	if (ssock==-1) {		perror("no server socket");		exit(2);	}	sockname.sin_family=AF_INET;	sockname.sin_addr.s_addr = htonl( INADDR_ANY );	sockname.sin_port = htons((short)lport);	if (bind( ssock, (struct sockaddr *) &sockname, sizeof(sockname) )==-1) {		perror("no bind");		exit(2);	}	/* for the via line we need our listening port number */	if ((via_ins||usrloc) && lport==0){		memset(&sockname, 0, sizeof(sockname));		slen=sizeof(sockname);		getsockname(ssock, (struct sockaddr *)&sockname, &slen);		lport=ntohs(sockname.sin_port);	}	/* set a regular expression according to the modus */	regexp=(regex_t*)malloc(sizeof(regex_t));	if (trace)		regcomp(regexp, "^SIP/[0-9]\\.[0-9] 483 ", REG_EXTENDED|REG_NOSUB|REG_ICASE); 	else if (usrloc)		regcomp(regexp, "^SIP/[0-9]\\.[0-9] 200 ", REG_EXTENDED|REG_NOSUB|REG_ICASE); 	else if (randtrash)		regcomp(regexp, "^SIP/[0-9]\\.[0-9] 4[0-9][0-9] ", REG_EXTENDED|REG_NOSUB|REG_ICASE); 	else		regcomp(regexp, "^SIP/[0-9]\\.[0-9] 1[0-9][0-9] ", REG_EXTENDED|REG_NOSUB|REG_ICASE); 	/* catching redirects */	redexp=(regex_t*)malloc(sizeof(regex_t));	regcomp(redexp, "^SIP/[0-9]\\.[0-9] 3[0-9][0-9] ", REG_EXTENDED|REG_NOSUB|REG_ICASE); 	if (usrloc){		nretries=3*(nameend-namebeg)+3;		create_msg(buff, REQ_REG);	}	else if (trace){		if (maxforw!=-1)			nretries=maxforw;		else			nretries=255;		namebeg=1;		maxforw=0;		create_msg(buff, REQ_OPT);		add_via(buff);	}	else if (flood){		if (namebeg==-1) namebeg=2147483647;		nretries=namebeg;		namebeg=1;		create_msg(buff, REQ_FLOOD);	}	else if (randtrash){		randretrys=0;		namebeg=1;		create_msg(buff, REQ_RAND);		nameend=strlen(buff);		if (trashchar){			if (trashchar < nameend)				nameend=trashchar;			else				printf("warning: number of trashed chars to big. setting to request lenght\n");		}		nretries=nameend-1;		trash_random(buff);	}	else {		if (!file_b) {			namebeg=1;			create_msg(buff, REQ_OPT);		}		retryAfter = 500;		if(maxforw!=-1)			set_maxforw(buff);		if(via_ins)			add_via(buff);	}	/* if we got a redirect this loop ensures sending to the 	   redirected server*/	while (redirected) {		redirected=0;		addr.sin_addr.s_addr = address;		addr.sin_port = htons((short)rport);		addr.sin_family = AF_INET;			/* we connect as per the RFC 2543 recommendations		modified from sendto/recvfrom */		ret = connect(sock, (struct sockaddr *)&addr, sizeof(addr));		if (ret==-1) {			perror("no connect");			exit(2);		}		for (i = 0; i <= nretries; i++)		{			if (trace) {				set_maxforw(buff);			}			else if (usrloc && verbose) {				switch (usrlocstep) {					case 0:						printf("registering user %s%i... ", username, namebeg);						break;					case 1:						printf("sending message... ");						break;					case 2:						printf("sending message reply... ");						break;				}			}			else if (flood && verbose) {				printf("flooding message number %i\n", i+1);			}			else if (randtrash && verbose) {				printf("message with %i randomized chars\n", i+1);#ifdef DEBUG				printf("request:\n%s\n", buff);#endif			}			else if (!trace && !usrloc && !flood && !randtrash && verbose){				printf("** request **\n%s\n", buff);			}			ret = send(sock, buff, strlen(buff), 0);			(void)gettimeofday(&sendtime, &tz);			if (ret==-1) {				perror("send failure");				exit( 1 );			}			if (!flood) {				tv.tv_sec = retryAfter/1000;				tv.tv_usec = (retryAfter % 1000) * 1000;				FD_ZERO(&fd);				FD_SET(ssock, &fd); 				ret = select(FD_SETSIZE, &fd, NULL, NULL, &tv);				(void)gettimeofday(&recvtime, &tz);				if (ret == 0)				{					sockerr.fd=sock;					sockerr.events=POLLERR;					if ((poll(&sockerr, 1, 10))==1) {						if (sockerr.revents && POLLERR) {							recv(sock, reply, strlen(reply), 0);							perror("send failure: ");							if (randtrash) 								printf ("last message before send failure:\n%s\n", buff);							exit(1);						}					}					if (trace) printf("%i: timeout after %i ms\n", i, retryAfter);					else if (verbose) printf("** timeout after %i ms**\n", retryAfter);					if (i==0) memcpy(&firstsendt, &sendtime, sizeof(struct timeval));					if (randtrash) {						printf("did not get a response on this request:\n%s\n", buff);						if (i+1 < nameend) {							if (randretrys == 2) {								printf("sended the following message three times without getting a response:\n%s\ngive up further retransmissions...\n", buff);								exit(1);							}							else {								printf("resending it without additional random changes...\n\n");								randretrys++;							}						}					}					retryAfter = retryAfter * 2;					if (retryAfter > 5000)						retryAfter = 5000;					continue;				} else if ( ret == -1 ) {					perror("select error");					exit(2);				} /* no timeout, no error ... something has happened :-) */				else if (FD_ISSET(ssock, &fd)) {				 	if (!trace && !usrloc && !randtrash)						printf ("\nmessage received\n");				} else {					puts("\nselect returned succesfuly, nothing received\n");					continue;				}				/* we are retrieving only the extend of a decent MSS = 1500 bytes */				len = sizeof(addr);				ret = recv(ssock, reply, BUFSIZE, 0);				if(ret > 0)				{					reply[ret] = 0;					if (redirects && regexec((regex_t*)redexp, reply, 0, 0, 0)==0) {						printf("** received redirect ");						if (warning_ext) {							printf("from ");							warning_extract(reply);							printf("\n");						}						else printf("\n");						/* we'll try to handle 301 and 302 here, other 3xx are to complex */						regcomp(redexp, "^SIP/[0-9]\\.[0-9] 30[1-2] ", REG_EXTENDED|REG_NOSUB|REG_ICASE);						if (regexec((regex_t*)redexp, reply, 0, 0, 0)==0) {							/* try to find the contact in the redirect */							if ((foo=strstr(reply, "Contact"))==NULL) {								printf("error: cannot find Contact in this redirect:\n%s\n", reply);								exit(2);							}							crlf=strchr(foo, '\n');							if ((contact=strchr(foo, '\r'))!=NULL && contact<crlf)								crlf=contact;							bar=malloc(crlf-foo+1);							strncpy(bar, foo, crlf-foo);							//sprintf(bar+(crlf-foo), "0");							*(bar+(crlf-foo))='\0';							if ((contact=strstr(bar, "sip"))==NULL) {								printf("error: cannot find sip in the Contact of this redirect:\n%s\n", reply);								exit(2);							}							if ((foo=strchr(contact, ';'))!=NULL)								*foo='\0';							if ((foo=strchr(contact, '>'))!=NULL)								*foo='\0';							if ((crlf=strchr(contact,':'))!=NULL){								crlf++;								/* extract the needed information*/								if ((foo=strchr(crlf,':'))!=NULL){									*foo='\0';									foo++;									rport = atoi(foo);									if (!rport) {										printf("error: cannot handle the port in the uri in Contact:\n%s\n", reply);										exit(2);									}								}								/* correct our request */								uri_replace(buff, contact);								if ((foo=strchr(contact,'@'))!=NULL){									foo++;									crlf=foo;								}								/* get the new destination IP*/								address = getaddress(crlf);								if (!address){									printf("error: cannot determine host address from Contact of redirect:\%s\n", reply);									exit(2);								}							}							else{								printf("error: missing : in Contact of this redirect:\n%s\n", reply);								exit(2);							}							free(bar);							memset(&addr, 0, sizeof(addr));							redirected=1;							i=nretries;						}						else {							printf("error: cannot handle this redirect:\n%s\n", reply);							exit(2);						}					}					else if (trace) {						/* in trace we only look for 483, anything else is 						   treated as the final reply*/						printf("%i: ", i);						if (regexec((regex_t*)regexp, reply, 0, 0, 0)==0) {							printf("* (483) ");							warning_extract(reply);							printf(" %.3f ms\n", deltaT(&sendtime, &recvtime));#ifdef DEBUG							printf("%s\n", reply);#endif							namebeg++;							maxforw++;							create_msg(buff, REQ_OPT);							add_via(buff);							continue;						}						else {							crlf=strchr(reply,'\n');							*crlf='\0';							crlf++;							contact=strstr(crlf, "Contact");							printf("received reply from ");							warning_extract(crlf);							printf("after %.3f ms", deltaT(&sendtime, &recvtime));							if (contact){								crlf=strchr(contact,'\n');								*crlf='\0';								printf(":\n     %s\n", contact);							}							else {								printf(" without contact:\n     %s\n", reply);							}							exit(0);						}					}					else if (usrloc) {						switch (usrlocstep) {							case 0:								/* at first we have sended a register a look at the 								   response now*/								if (regexec((regex_t*)regexp, reply, 0, 0, 0)==0) {									if (verbose)										printf ("  OK\n");#ifdef DEBUG									printf("\n%s\n", reply);#endif									strcpy(buff, message);									usrlocstep=1;								}								else {									if (verbose)										printf("received:\n%s\n", reply);									printf("error: didn't received '200 OK' on regsiter. aborting\n");									exit(1);								}								break;							case 1:								/* now we sended the message and look if its 								   forwarded to us*/								if (!strncmp(reply, messusern, strlen(messusern))) {									if (verbose) {										crlf=strstr(reply, "\r\n\r\n");										crlf=crlf+4;										printf("         received message\n  '%s'\n", crlf);									}#ifdef DEBUG									printf("\n%s\n", reply);#endif									cpy_vias(reply);									strcpy(buff, mes_reply);									usrlocstep=2;								}								else {									if (verbose)										printf("\nreceived:\n%s\n", reply);									printf("error: didn't received the 'MESSAGE' we sended. aborting\n");									exit(1);								}								break;							case 2:								/* finnaly we sended our reply on the message and 								   look if this is also forwarded to us*/								while (!strncmp(reply, messusern, strlen(messusern))){									printf("warning: received 'MESSAGE' retransmission!\n");									ret = recv(ssock, reply, BUFSIZE, 0);								}								if (regexec((regex_t*)regexp, reply, 0, 0, 0)==0) {									if (verbose)										printf("   reply received\n\n");									else										printf("USRLOC for %s%i completed successful\n", username, namebeg);									if (namebeg==nameend) {										printf("All USRLOC tests completed successful.\n");										exit(0);									}									namebeg++;									create_msg(buff, REQ_REG);									usrlocstep=0;								}								else {									if (verbose)										printf("\nreceived:\n%s\n", reply);									printf("error: didn't received the '200 OK' that we sended as the reply on the message\n");									exit(1);								}							break;						}					}					else if (randtrash) {						/* in randomzing trash we are expexting 4?? error codes						 * everything should not be normal */						if (regexec((regex_t*)regexp, reply, 0, 0, 0)==0) {#ifdef DEBUG							printf("received:\n%s\n", reply);#endif							if (verbose) printf("received expected 4xx ");							if (warning_ext) {								printf ("from ");								warning_extract(reply);								printf("\n");							}							else printf("\n");						}						else {							printf("warning: did not received 4xx\n");							if (verbose) printf("sended:\n%s\nreceived:\n%s\n", buff, reply);						}						if (nameend==(i+1)) {							if (randretrys == 0) {								printf("random end reached. server survived :) respect!\n");							}							else {								printf("maximum sendings reached but did not get a response on this request:\n%s\n", buff);							}							exit(0);						}						else trash_random(buff);					}					else {						/* in the normal send and reply case anything other 						   then 1xx will be treated as final response*/						printf("** reply received ");						if (i==0) printf("after %.3f ms **\n", deltaT(&sendtime, &recvtime));						else printf("%.3f ms after first send\n   and %.3f ms after last send **\n", deltaT(&firstsendt, &recvtime), deltaT(&sendtime, &recvtime));						if (verbose) printf("%s\n", reply);						if (regexec((regex_t*)regexp, reply, 0, 0, 0)==0) {							puts(" provisional received; still waiting for a final response\n ");							continue;						} else {							puts(" final received; congratulations!\n ");							exit(0);						}					}						} /* ret > 0 */				else {					perror("recv error");					exit(2);				}			} /* !flood */			else {				if (namebeg==nretries) {					printf("flood end reached\n");					exit(0);				}				namebeg++;				create_msg(buff, REQ_FLOOD);			}		} /* for nretries */	} /* while redirected */	if (randtrash) exit(0);	printf("** I give up retransmission....\n");	exit(1);}