Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(int argc, char *argv[]) {
- struct timeval tempo1, tempo2;
- printf("\n# ##### Programa Envia Pkt Goose ##### #\n");
- int qtd_pacotes = 1;
- int tipo_seguranca = 0;
- if (argc > 1)
- sscanf(argv[1], "%d", &qtd_pacotes);
- printf("Quantidade a ser enviada: %d\n", qtd_pacotes);
- char buffer[TAMANHO_BUF]; //vetor onde sera montado o pacote
- int t_buffer = 0; //tamanho do pacote
- pthread_t threads[2];
- for (int i = 0; i < qtd_pacotes; i++) {
- gettimeofday(&tempo1, NULL);
- t_buffer = criaPacote(buffer);
- gettimeofday(&tempo2, NULL);
- printf("[PKT %d]Tempo de GERAÇÃO = %ld microssegundos\n", i + 1,
- (tempo2.tv_sec - tempo1.tv_sec) * 1000000
- + (tempo2.tv_usec - tempo1.tv_usec));
- gettimeofday(&tempo1, NULL);
- v = (argumentos*) malloc (sizeof(argumentos));
- v->mensagem = buffer;
- v->tamanho = t_buffer;
- v->interface = DEFAULT_IF;
- v_prp = (argumentos*) malloc (sizeof(argumentos));
- v_prp->mensagem = buffer;
- v_prp->tamanho = t_buffer;
- v_prp->interface = DEFAULT_IF_PRP;
- pthread_create(&threads[0], NULL, enviaPacote, (void *)v);
- pthread_create(&threads[1], NULL, enviaPacote, (void *)v_prp);
- //enviaPacote(buffer, t_buffer, DEFAULT_IF);
- //enviaPacote(buffer, t_buffer, DEFAULT_IF_PRP);
- gettimeofday(&tempo2, NULL);
- printf("[PKT %d]Tempo de ENVIO = %ld microssegundos\n\n", i + 1,
- (tempo2.tv_sec - tempo1.tv_sec) * 1000000
- + (tempo2.tv_usec - tempo1.tv_usec));
- }
- printf("Mensagem enviada com sucesso !");
- printf("\n\n");
- //Atentar para colocar uma variável caso haja mais que duas threads
- for(int i=0;i<2;i++){
- pthread_join(threads[i],NULL);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement