Ejemplo n.º 1
0
// show packet list of that sequence
int sequence_show (struct cli_def *cli, char *command, char *argv[], int argc)
{
	char str[512], name[32], layers[16], proto[16];
	struct pseq *seq;
	int i;
	
	if  (strcmp(argv[argc-1],"?")==0)  {
		cli_print(cli, "Shows all packets of the current sequence.\n");
		return CLI_OK;
	}

	if (argc>0) {
		cli_print(cli, "This command has currently no arguments!\n");
		return CLI_OK;
	}
	
	seq = (struct pseq*) cli_seq->data;
	
	if (seq->count==0) {
		cli_print(cli, "Current sequence '%s' has no entries.\n", cli_seq->name);
	}
	else { // show all packets in this sequence
		cli_print(cli, "%i sequence(s) defined.\r", packet_sequences->refcount-1);                 // total info
		snprintf(str,512, "Current sequence '%s' has %i entries:", cli_seq->name, seq->count);    // num entries here
		cli_print(cli, "%s\n", str);
		cli_print(cli, "Nr  PId  PktName          Layers  Protocol  Device");
		for (i=0; i<seq->count; i++) { 
			strncpy (name, seq->packet[i]->packet_name, 13); // only show first 13 chars
			if (strnlen(seq->packet[i]->packet_name, MAX_MOPS_PACKET_NAME_LEN)>13) {
				name[13]=0x00;        
				strcat(name, "...");
			}
			mops_get_proto_info(seq->packet[i], layers, proto);
			snprintf(str,512, "%2i %4i  %-16s %s  %-8s  %-6s", i+1, seq->packet[i]->id, name, layers, proto, seq->packet[i]->device);
			cli_print(cli, "%s\r", str);
			if ((seq->gap[i].tv_sec !=0) || (seq->gap[i].tv_nsec !=0)) { // gap also defined?
				timespec2str(&seq->gap[i], str);
				cli_print(cli, "  \\___ %s pause ___/\r", str);
			}
		}
	}
	return CLI_OK;
}
Ejemplo n.º 2
0
void ListArrayClass::save_to_file_and_clear() {
    ListArrayClass *lac;

    //const uint timestr_size = strlen("2014-12-31 12:59:59.123456789") + 1;
    const uint timestr_size = 30;
    char timestr1[timestr_size];
    char timestr2[timestr_size];

    for (lac = this; lac != NULL; lac = lac->nextListArrayClass) {
        if (lac->array_paket_header != NULL) {

            int min;
            if (lac->count_paket_header_in_one_array < lac->count_paket_headers) {
                min = lac->count_paket_header_in_one_array;
            } else {
                min = lac->count_paket_headers;
            }

            if (file_csv != NULL) {
                for (int i = 0; i < min; i++) {

                    timespec2str(timestr1, timestr_size, &lac->array_paket_header[i].recv_time);
                    timespec2str(timestr2, timestr_size, &lac->array_paket_header[i].send_time);

                    fprintf(file_csv, "%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%s;%s;%f\n",
                            lac->array_paket_header[i].train_id,
                            lac->array_paket_header[i].retransfer_train_id,
                            lac->array_paket_header[i].paket_id,
                            lac->array_paket_header[i].retransfer_train_id,
                            lac->array_paket_header[i].recv_data_rate,
                            lac->array_paket_header[i].first_recv_train_id,
                            lac->array_paket_header[i].first_recv_retransfer_train_id,
                            lac->array_paket_header[i].first_recv_paket_id,
                            lac->array_paket_header[i].last_recv_paket_bytes,
                            lac->array_paket_header[i].timeout_time_tv_sec,
                            lac->array_paket_header[i].timeout_time_tv_usec,
                            timestr1,
                            timestr2,
                            lac->array_paket_header[i].rtt
                            );

                    fflush(file_csv);
                }
            }

            int bytezahl = min * lac->paket_header_size;
            if (bytezahl != write(File_Deskriptor, lac->array_paket_header, bytezahl)) {
                printf("ERROR:\n  Fehler beim Schreiben der Datei \"%s\" \n(%s)\n", filename, strerror(errno));
                fflush(stdout);
                exit(EXIT_FAILURE);
            }

        }
    }

    count_paket_headers = 0;

    first_paket_header = NULL;
    last_paket_header = NULL;

    if (nextListArrayClass != NULL) {
        return nextListArrayClass->clear();
    }
}