Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.69 KB | None | 0 0
  1. int main(int argc, char *argv[]) {
  2.     struct timeval tempo1, tempo2;
  3.     printf("\n#  ##### Programa Envia Pkt Goose #####  #\n");
  4.     int qtd_pacotes = 1;
  5.     int tipo_seguranca = 0;
  6.     if (argc > 1)
  7.         sscanf(argv[1], "%d", &qtd_pacotes);
  8.     printf("Quantidade a ser enviada: %d\n", qtd_pacotes);
  9.  
  10.     char buffer[TAMANHO_BUF]; //vetor onde sera montado o pacote
  11.     int t_buffer = 0; //tamanho do pacote
  12.     pthread_t threads[2];
  13.  
  14.     for (int i = 0; i < qtd_pacotes; i++) {
  15.         gettimeofday(&tempo1, NULL);
  16.         t_buffer = criaPacote(buffer);
  17.         gettimeofday(&tempo2, NULL);
  18.         printf("[PKT %d]Tempo de GERAÇÃO   = %ld microssegundos\n", i + 1,
  19.                 (tempo2.tv_sec - tempo1.tv_sec) * 1000000
  20.                         + (tempo2.tv_usec - tempo1.tv_usec));
  21.  
  22.         gettimeofday(&tempo1, NULL);
  23.  
  24.         v = (argumentos*) malloc (sizeof(argumentos));
  25.         v->mensagem =   buffer;  
  26.         v->tamanho =    t_buffer;
  27.         v->interface =  DEFAULT_IF;
  28.  
  29.         v_prp = (argumentos*) malloc (sizeof(argumentos));
  30.         v_prp->mensagem =   buffer;  
  31.         v_prp->tamanho =    t_buffer;
  32.         v_prp->interface =  DEFAULT_IF_PRP;
  33.  
  34.         pthread_create(&threads[0], NULL, enviaPacote, (void *)v);
  35.        
  36.         pthread_create(&threads[1], NULL, enviaPacote, (void *)v_prp);
  37.  
  38.         //enviaPacote(buffer, t_buffer, DEFAULT_IF);
  39.         //enviaPacote(buffer, t_buffer, DEFAULT_IF_PRP);
  40.         gettimeofday(&tempo2, NULL);
  41.         printf("[PKT %d]Tempo de ENVIO     = %ld microssegundos\n\n", i + 1,
  42.                 (tempo2.tv_sec - tempo1.tv_sec) * 1000000
  43.                         + (tempo2.tv_usec - tempo1.tv_usec));
  44.     }
  45.     printf("Mensagem enviada com sucesso !");
  46.     printf("\n\n");
  47.  
  48.     //Atentar para colocar uma variável caso haja mais que duas threads
  49.     for(int i=0;i<2;i++){
  50.         pthread_join(threads[i],NULL);
  51.     }  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement