⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sipp.cpp

📁 sipbomber - tool for testing SIP-protocol implementation (RFC3261). Current version can check only
💻 CPP
📖 第 1 页 / 共 5 页
字号:
              ERROR("Unable to create the BIO- New TLS connection - recv_message\n");	    } 	    	    // SSL_set_fd(ssl, new_sock);            SSL_set_bio(ssl,bio,bio);            if ( (err = SSL_accept(ssl)) < 0 ) {              if (reset_number > 0) {                WARNING("SSL_accept Fails - recv_message()\n");                start_calls = 1;                return -2;              } else {                ERROR("SSL_accept Fails - recv_message()\n");              }            }            ssl_list[new_sock] = ssl;          }          (*poll_idx) = pollset_add(0, new_sock);	  // TRACE_MSG((s,"new call server sock  %d and poll_idx  is %d \n", new_sock, (*poll_idx))); #else           pollset_add(0, new_sock);#endif          return -2;        }#ifdef _USE_OPENSSL        if ( transport == T_TLS ) {          int ss = s;          ssl = ssl_list[s];          size = recv_tls_message(ssl,                                  buffer,                                  buffer_size,                                  E_ALTER_YES);        } else {#endif        size = recv_tcp_message(s,                                buffer,                                buffer_size,                                E_ALTER_YES);#ifdef _USE_OPENSSL        }#endif                if(size <= 0) { /* Remote side closed TCP connection */                    nb_net_recv_errors++;          /* Preventive cleaning */          if(size < 0) {            WARNING_P2("TCP/TLS recv error on socket %d, index = %d",                       s, *poll_idx);            if (reset_number > 0) {              start_calls = 1;              return 0;            } else {               ERROR_NO("TCP/TLS recv_error");            }          } else {            /* Remote side closed TCP connection */          }          if(recv_call) {            recv_call -> call_socket = 0;            if(recv_call -> pollset_index) {              recv_call -> pollset_index = 0;            }          }                    pollset_remove((*poll_idx));          shutdown(s, SHUT_RDWR);          close(s);          return 0;        }              } else { /* T_UDP */                if(toolMode == MODE_SERVER) {          sipp_socklen_t len = SOCK_ADDR_SIZE(&remote_sockaddr);                    size  = recvfrom(s,                           buffer,                           buffer_size,                           0,                           (sockaddr *)(void *)&remote_sockaddr,                           &len);                  } else {          size  = recvfrom(s,                            buffer,                            buffer_size,                            0, NULL, NULL);        }                if(size < 0) {          WARNING_P3("Unexpected UDP recv error, idx = %d, "                     "socket = %d, recv_call = 0x%08x",                     (*poll_idx), s, recv_call);          ERROR_NO("Unexpected UDP recv error");#if 0          nb_net_recv_errors++;          pollset_remove((*poll_idx));          shutdown(s, SHUT_RDWR);          close(s);#endif          return 0;        }        if (size > 0) {          size = decompress_if_needed(s,                                      buffer,                                      size,                                      ((recv_call) ?                                        (&(recv_call -> comp_state)) :                                        &monosocket_comp_state));        }      } /* else ... T_UDP */            break;#ifdef __3PCC__      }#endif    } /* if(pollfiles[(*poll_idx)].revents) */	} // POLLOUT  } /* for((*poll_idx)) */    buffer[size] = 0;  if (useMessagef == 1) {  struct timeval currentTime;  GET_TIME (&currentTime);  TRACE_MSG((s, "----------------------------------------------- %s\n"             "%s message received [%d] bytes :\n\n%s\n",             CStat::instance()->formatTime(&currentTime),             TRANSPORT_TO_STRING(transport), size,             buffer));  }  return size;}void pollset_process(bool ipv6){  int rs; /* Number of times to execute recv().	     For TCP with 1 socket per call:	         no. of events returned by poll	     For UDP and TCP with 1 global socket:	         recv_count is a flag that stays up as	         long as there's data to read */  int loops = max_recv_loops;  int update_freq = (div(loops,update_nb)).quot ;    while((loops-- > 0) && /* Ensure some minimal statistics display sometime */        (rs = poll(pollfiles, pollnfds,  1)) > 0) {    if((rs < 0) && (errno == EINTR)) {      return;    }        if (update_freq > 0) {      if ((div(loops,update_freq)).rem == 0 ) {       /*if (loops % update_freq == 0 ) {*/        clock_tick = getmilliseconds();      }    }    if(rs < 0) {      ERROR_NO("poll() error");    }        while(rs > 0) {      char            msg[SIPP_MAX_MSG_SIZE];      int             msg_size;      char          * call_id;      call          * call_ptr;      int             pollset_index = 0;            memset(msg,0,sizeof(msg));      msg_size = recv_message(msg,                               SIPP_MAX_MSG_SIZE,                               &pollset_index			);            //    TRACE_MSG((s,"msg_size %d and pollset_index is %d \n", msg_size, pollset_index));      if(msg_size > 0) {		if (sipMsgCheck(msg, 			msg_size#ifdef __3PCC__			,pollset_index#endif // __3PCC__			) == true) {	            call_id = get_call_id(msg);          call_ptr = get_call(call_id);                  if(!call_ptr)            {              if(toolMode == MODE_SERVER)                {                  // Adding a new INCOMING call !                  CStat::instance()->computeStat                    (CStat::E_CREATE_INCOMING_CALL);#ifdef _USE_OPENSSL                    call_ptr = add_call(call_id , pollset_index, ipv6);                   pollset_attached(call_ptr,pollset_index);#else	                  call_ptr = add_call(call_id , ipv6); #endif                  if((pollset_index) &&                      (pollfiles[pollset_index].fd != main_socket) &&                      (pollfiles[pollset_index].fd != tcp_multiplex) ) {				                      call_ptr -> call_socket = pollfiles[pollset_index].fd;                  }                }#ifdef __3PCC__              else if(toolMode == MODE_3PCC_CONTROLLER_B || toolMode == MODE_3PCC_A_PASSIVE)                {                  // Adding a new OUTGOING call !                  CStat::instance()->computeStat                    (CStat::E_CREATE_OUTGOING_CALL);                  call_ptr = add_call(call_id ,ipv6);                              if((pollset_index) &&                      (pollfiles[pollset_index].fd != main_socket) &&                      (pollfiles[pollset_index].fd != tcp_multiplex) &&                     (pollfiles[pollset_index].fd != localTwinSippSocket) &&                     (pollfiles[pollset_index].fd != twinSippSocket)) {                    call_ptr -> call_socket = pollfiles[pollset_index].fd;                  }                }#endif              else // mode != from SERVER and 3PCC Controller B                {                  nb_out_of_the_blue++;                  CStat::instance()->computeStat                    (CStat::E_OUT_OF_CALL_MSGS);                  // This is a message that is not relating to any call                }            }		          if(call_ptr)            {#ifdef __3PCC__              if( (pollfiles[pollset_index].fd == localTwinSippSocket) ||                  (pollfiles[pollset_index].fd == twinSippSocket))                {                  if(!call_ptr -> process_twinSippCom(msg))                    {                      return;                    }                 }              else#endif                {                  if(!call_ptr -> process_incomming(msg))                    {                      /* Needs to rebuild the pollset (socket removed,                        * call deleted, etc... Cause pollcalls is now                        * invalid and will alway lead poll() to return                        * an error.*/                      return;                    }                }            }	} else { // sipMsgCheck == false	  // unrecognized message => discard it	  WARNING("non SIP message discarded");	}	if (pollnfds > 0) /* refer to note at the beginning of this function */               rs--;        if (!start_calls) {           rs = 0;        }                 } // end if msg >=0      else       rs--;    }  }  cpu_max = loops <= 0;}/* Send loop & trafic generation*/void traffic_thread(bool ipv6){  unsigned int calls_to_open = 0;  unsigned int new_time;  unsigned int last_time;  bool         firstPass;  /* create the file */  char         L_file_name [MAX_PATH];  sprintf (L_file_name, "%s_%d_screen.log", scenario_file, getpid());  firstPass = true;  last_time = getmilliseconds();   /* Prepare pollset with basic sockets */  pollset_reset();  while(1) {    scheduling_loops ++;    /* update local time, except if resetted*/    new_time = getmilliseconds();    clock_tick = new_time;    last_time = new_time;    if (start_calls == 1) {      reset_connections();    }    if (signalDump) {       /* Screen dumping in a file */       if (screenf) {          print_screens();       } else {         /* If the -trace_screen option has not been set, */         /* create the file at this occasion              */         screenf = fopen(L_file_name, "a");	 if (!screenf) {            WARNING_P1("Unable to create '%s'", L_file_name);          }	 print_screens();	 fclose(screenf);	 screenf = 0;       }       if(dumpInRtt) {          CStat::instance()->dumpDataRtt ();       }       signalDump = false ;    }    if ((!quitting) && (!paused) && (!start_calls)) {      long l=0;      calls_to_open = (unsigned int)              ((l=(long)floor((((clock_tick - last_rate_change_time) * rate/rate_period_s) / 1000)              - calls_since_last_rate_change))>0?l:0);      if( (toolMode == MODE_CLIENT)#ifdef __3PCC__          || (toolMode == MODE_3PCC_CONTROLLER_A)#endif          )        {          while((calls_to_open--) &&                 (open_calls < open_calls_allowed) &&                (total_calls < stop_after))             {              // adding a new OUTGOING CALL              CStat::instance()->computeStat(CStat::E_CREATE_OUTGOING_CALL);              call * call_ptr = add_call(ipv6);              call_ptr -> run();            }                  if(open_calls >= open_calls_allowed) {            set_rate(rate);          }        }        // Quit after asked number of calls is reached        if(total_calls >= stop_after) {          quitting = 1;        }                } else if (quitting) {      /* Quitting and no more openned calls, close all */      if(!open_calls) {        // Dump the latest statistics if necessary        if(dumpInFile) {          CStat::instance()->dumpData();        }        if(dumpInRtt) {          CStat::instance()->dumpDataRtt();        }        /* Screen dumping in a file if asked */        if(screenf) {          print_screens();        }#ifndef _USE_OPENSSL        if (multisocket) {          if (!socket_open) {             int    L_counter;             for (L_counter = 0; L_counter < pollnfds; L_counter++) {               if (pollfiles[L_counter].fd != 0) {                   pollset_remove(L_counter);               }             }             for (L_counter = min_socket; L_counter < (max_multi_socket+min_socket) ; L_counter ++) {                shutdown(L_counter, SHUT_RDWR);                close(L_counter);             }           }         if (tab_multi_socket != NULL) {           delete [] tab_multi_socket ;           tab_multi_socket = NULL ;         }        }#endif	        screen_exit(EXIT_TEST_RES_UNKNOWN);      }    }    if(compression) {      timer_resolution = 50;    }    new_time = getmilliseconds();    clock_tick = new_time;    last_time = new_time;    /* Schedule all pending calls and process their timers */    if((clock_tick - last_timer_cycle) > timer_resolution) {      call_map * calls = get_calls();      call_map::iterator iter;            /* Workaround hpux problem with iterators. Deleting the       * current object when iterating breaks the iterator and       * leads to iterate again on the destroyed (deleted)       * object. Thus, we have to wait ont step befere actual       * deletion of the object*/      call * last = NULL;      for(iter = calls->begin(); iter != calls->end(); iter++) {        if(last) { last -> run(); }        last = iter -> second;      }            if(last) { last -> run(); }      last_timer_cycle = clock_tick;      new_time = getmilliseconds();      clock_tick = new_time ;      last_time = new_time;    }        /* Receive incomming messages */    pollset_process(ipv6);       new_time = getmilliseconds();    clock_tick = new_time ;    last_time = new_time;    if(firstPass)      {        // dumping (to create file on disk) and showing         // screen at the beginning even if the report        // period is not reach        firstPass = false;        print_statistics(0);        /* Dumping once to 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -