void send_test_packet(pcap_t* handle, int testno, int packetsize, int source, int dest) { printf("==========> Test %d: generating packets of %d bytes...\n", testno, packetsize); int pktlen = generate_test_packet(packetOut, packetsize, testno, source, dest); print_rl_packet(stdout, packetOut, pktlen); //encrypt((const u_char *)packetOut, packetOut_e, &schedule1, pktlen); int ret = 0; if ((ret = pcap_inject(handle, packetOut_e, pktlen)) < 0){ fprintf(stderr, "Fail to inject packet\n"); // exit(1); } printf( "DONE\n"); usleep(50); //sleep(1); }
void fprintp(FILE* logfile, u_char* packet, int size) { fprintf(logfile, "============================== packet received, size = %d ==============================\n", size); struct rthdr* rth = (struct rthdr*) (packet + sizeof(struct ethhdr)); switch(rth->protocol) { case ROUTE_ON_CONTROL: print_ctl_packet(logfile, packet, size); break; case ROUTE_ON_UNRELIABLE: print_ur_packet(logfile, packet, size); break; case ROUTE_ON_RELIABLE: print_rl_packet(logfile, packet, size); break; default: fprintf(logfile, "this is a non route-on defined packet\n"); print_data(logfile, packet, size); break; } fprintf(logfile, "============================== end of packet ==============================\n\n\n\n\n\n"); }