qfTraceSource_t *qfTraceOpen(const char *uri, const char *bpf, int snaplen, GError **err) { qfTraceSource_t *lts; libtrace_err_t terr; lts = g_new0(qfTraceSource_t, 1); if (!(lts->packet = trace_create_packet())) { g_set_error(err, YAF_ERROR_DOMAIN, YAF_ERROR_IO, "Could not initialize libtrace packet"); goto err; } lts->trace = trace_create(uri); if (trace_is_err(lts->trace)) { terr = trace_get_err(lts->trace); g_set_error(err, YAF_ERROR_DOMAIN, YAF_ERROR_IO, "Could not open libtrace URI %s: %s", uri, terr.problem); goto err; } if (trace_config(lts->trace, TRACE_OPTION_SNAPLEN, &snaplen) == -1) { terr = trace_get_err(lts->trace); g_set_error(err, YAF_ERROR_DOMAIN, YAF_ERROR_IO, "Could not set snaplen on libtrace URI %s: %s", uri, terr.problem); goto err; } if (bpf) { if (!(lts->filter = trace_create_filter(bpf))) { g_warning("Could not compile libtrace BPF %s", bpf); goto err; } if (trace_config(lts->trace, TRACE_OPTION_FILTER, lts->filter) == -1) { terr = trace_get_err(lts->trace); g_warning("Could not set libtrace filter: %s", terr.problem); goto err; } } /* start processing */ if (trace_start(lts->trace) == -1) { terr = trace_get_err(lts->trace); g_warning("libtrace trace_start() error: %s", terr.problem); goto err; } return lts; err: qfTraceClose(lts); return NULL; }
static void _iodbcdm_env_settracing (GENV_t *genv) { char buf[1024]; genv = genv; /*UNUSED*/ /* * Check TraceFile keyword */ SQLSetConfigMode (ODBC_BOTH_DSN); if( SQLGetPrivateProfileString ("ODBC", "TraceFile", "", buf, sizeof(buf) / sizeof(SQLTCHAR), "odbc.ini") == 0 || !buf[0]) STRCPY (buf, SQL_OPT_TRACE_FILE_DEFAULT); trace_set_filename (buf); /* * Check Trace keyword */ SQLSetConfigMode (ODBC_BOTH_DSN); if ( SQLGetPrivateProfileString ("ODBC", "Trace", "", buf, sizeof(buf) / sizeof(SQLTCHAR), "odbc.ini") && (STRCASEEQ (buf, "on") || STRCASEEQ (buf, "yes") || STRCASEEQ (buf, "1"))) trace_start (); return; }
int aos_kernel_init(kinit_t *kinit) { #ifdef AOS_VFS vfs_init(); vfs_device_init(); #endif #ifdef CONFIG_AOS_CLI if (kinit->cli_enable) aos_cli_init(); #endif #ifdef AOS_KV aos_kv_init(); #endif #ifdef WITH_SAL sal_device_init(); #endif #ifdef AOS_LOOP aos_loop_init(); #endif #ifdef VCALL_RHINO trace_start(); #endif #ifdef AOS_FOTA ota_service_init(); #endif #ifdef AOS_SENSOR sensor_init(); #endif // auto_component generated by the compiler system, now gcc support #if defined (__GNUC__) aos_components_init(); #endif #ifdef AOS_BINS app_pre_init(); framework_pre_init(); if (framework_info->framework_entry) { framework_info->framework_entry((void *)syscall_ktbl, kinit->argc, kinit->argv); } #else #ifdef AOS_FRAMEWORK_COMMON aos_framework_init(); #endif application_start(kinit->argc, kinit->argv); #endif return 0; }
int main(int argc, char *argv[]) { /* This is essentially the same main function from readdemo.c */ libtrace_t *trace = NULL; libtrace_packet_t *packet = NULL; /* Ensure we have at least one argument after the program name */ if (argc < 2) { fprintf(stderr, "Usage: %s inputURI\n", argv[0]); return 1; } packet = trace_create_packet(); if (packet == NULL) { perror("Creating libtrace packet"); libtrace_cleanup(trace, packet); return 1; } trace = trace_create(argv[1]); if (trace_is_err(trace)) { trace_perror(trace,"Opening trace file"); libtrace_cleanup(trace, packet); return 1; } if (trace_start(trace) == -1) { trace_perror(trace,"Starting trace"); libtrace_cleanup(trace, packet); return 1; } while (trace_read_packet(trace,packet)>0) { per_packet(packet); } if (trace_is_err(trace)) { trace_perror(trace,"Reading packets"); libtrace_cleanup(trace, packet); return 1; } /* Print the stats for the final reporting period that was probably * not complete when the trace finished */ printf("%u\t", next_report); printf("%.2f\t\t", ((double)wire_count) / packet_count); printf("%.2f\n", ((double)capture_count) / packet_count); libtrace_cleanup(trace, packet); return 0; }
int main(int argc, char* argv[]) { if(argc != 2) { fprintf(stderr, "Missing *.pcap file path as argument"); exit(1); } char* filepath = argv[1]; setvbuf(stdout, NULL, _IOLBF, 0); printf("Starting...\n"); long int total_ns; struct timespec start_time; struct timespec end_time; int exit_code = 0; int i, psize = 0; libtrace_packet_t **packets = malloc(100 * sizeof(libtrace_packet_t*)); i = 0; char* trace_string = malloc(5 + strlen(filepath) + 1); strcpy(trace_string, "pcap:"); strcat(trace_string, filepath); libtrace_t* trace = trace_create(trace_string); iferr(trace); trace_start(trace); libtrace_packet_t* packet = trace_create_packet(); while ((psize = trace_read_packet(trace, packet)) > 0){ libtrace_tcp_t* tcp = trace_get_tcp(packet); if(tcp != NULL){ packets[i++] = packet; packet = trace_create_packet(); } } int len = i; for (i = 0; i < 1000; i++) { clock_gettime(CLOCK_MONOTONIC, &start_time); test(packets, len); clock_gettime(CLOCK_MONOTONIC, &end_time); total_ns += (end_time.tv_sec - start_time.tv_sec) * 1000000000 + (end_time.tv_nsec - start_time.tv_nsec); } int runs = i; for (i = 0; i < len; i++){ trace_destroy_packet(packets[i]); } free(packets); printf("Took %ld nanoseconds.\n", total_ns/runs); }
int main(int argc, char *argv[]) { /* This is essentially the same main function from readdemo.c */ libtrace_t *trace = NULL; libtrace_packet_t *packet = NULL; /* Ensure we have at least one argument after the program name */ if (argc < 2) { fprintf(stderr, "Usage: %s inputURI\n", argv[0]); return 1; } packet = trace_create_packet(); if (packet == NULL) { perror("Creating libtrace packet"); libtrace_cleanup(trace, packet); return 1; } trace = trace_create(argv[1]); if (trace_is_err(trace)) { trace_perror(trace,"Opening trace file"); libtrace_cleanup(trace, packet); return 1; } if (trace_start(trace) == -1) { trace_perror(trace,"Starting trace"); libtrace_cleanup(trace, packet); return 1; } while (trace_read_packet(trace,packet)>0) { per_packet(packet); } if (trace_is_err(trace)) { trace_perror(trace,"Reading packets"); libtrace_cleanup(trace, packet); return 1; } printf("Packet Count = %" PRIu64 "\n", count); libtrace_cleanup(trace, packet); return 0; }
/*===========================================================================* * blockdriver_handle_request * *===========================================================================*/ int blockdriver_handle_request(struct blockdriver *bdp, message *m_ptr, thread_id_t id) { /* Call the appropiate driver function, based on the type of request. Return * the result code that is to be sent back to the caller, or EDONTREPLY if no * reply is to be sent. */ int r; /* We might get spurious requests if the driver has been restarted. Deny any * requests on devices that have not previously been opened, signaling the * caller that something went wrong. */ if (IS_BDEV_RQ(m_ptr->m_type) && !is_open_dev(m_ptr->BDEV_MINOR)) { /* Reply ERESTART to spurious requests for unopened devices. */ if (m_ptr->m_type != BDEV_OPEN) return ERESTART; /* Mark the device as opened otherwise. */ set_open_dev(m_ptr->BDEV_MINOR); } trace_start(id, m_ptr); /* Call the appropriate function(s) for this request. */ switch (m_ptr->m_type) { case BDEV_OPEN: r = do_open(bdp, m_ptr); break; case BDEV_CLOSE: r = do_close(bdp, m_ptr); break; case BDEV_READ: case BDEV_WRITE: r = do_rdwt(bdp, m_ptr); break; case BDEV_GATHER: case BDEV_SCATTER: r = do_vrdwt(bdp, m_ptr, id); break; case BDEV_IOCTL: r = do_ioctl(bdp, m_ptr); break; default: if (bdp->bdr_other) r = bdp->bdr_other(m_ptr); else r = EINVAL; } /* Let the driver perform any cleanup. */ if (bdp->bdr_cleanup != NULL) (*bdp->bdr_cleanup)(); trace_finish(id, r); return r; }
static ssize_t trace_running_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t n) { unsigned int value; int ret; if (sscanf(buf, "%u", &value) != 1) return -EINVAL; mutex_lock(&tracer.mutex); ret = value ? trace_start(&tracer) : trace_stop(&tracer); mutex_unlock(&tracer.mutex); return ret ? : n; }
int main(int argc, char *argv[]) { char *uri = lookup_uri(argv[1]); int psize = 0; int error = 0; int count = 0; libtrace_packet_t *packet; trace = trace_create(uri); iferr(trace); trace_start(trace); iferr(trace); packet=trace_create_packet(); for (;;) { double ts; double tsdiff; struct timeval tv; if ((psize = trace_read_packet(trace, packet)) <0) { error = 1; break; } if (psize == 0) { error = 0; break; } count ++; tv=trace_get_timeval(packet); ts=trace_get_seconds(packet); tsdiff = (tv.tv_sec+tv.tv_usec/1000000.0)-ts; assert(tsdiff > -0.001 && tsdiff < 0.001); } trace_destroy_packet(packet); if (error == 0) { if (count == 100) { printf("success: 100 packets read\n"); } else { printf("failure: 100 packets expected, %d seen\n",count); error = 1; } } else { iferr(trace); } trace_destroy(trace); return error; }
static ssize_t run_store(struct device *kobj, struct device_attribute *attr, const char *buf, size_t n) { unsigned int value; if (unlikely(sscanf(buf, "%u", &value) != 1)) return -EINVAL; if (value == 1) { trace_start(); } else if(value == 0) { trace_stop(); } else { return -EINVAL; } return n; }
/* If you don't specify O_WONLY or O_RDWR on the fileflags, then this should * fail. */ void test_forgotten_wronly() { libtrace_out_t *out; libtrace_t *trace; libtrace_packet_t *packet; int err; int zero = 0; out = trace_create_output("pcapfile:traces/100_packets_out.pcap"); assert(out); assert (!trace_is_err_output(out)); /* Note: no WRONLY/RDWR */ err = trace_config_output(out,TRACE_OPTION_OUTPUT_FILEFLAGS,&zero); assert(err==0); assert(!trace_is_err_output(out)); err = trace_start_output(out); assert(err == 0); assert(!trace_is_err_output(out)); trace = trace_create("pcapfile:traces/100_packets.pcap"); assert(trace); assert(!trace_is_err(trace)); err = trace_start(trace); assert(!trace_is_err(trace)); assert(err == 0); packet = trace_create_packet(); assert(packet); err = trace_read_packet(trace, packet); assert(err>0); err = trace_write_packet(out,packet); assert(err == -1); /* Should fail */ assert(trace_is_err_output(out)); trace_destroy_output(out); trace_destroy_packet(packet); trace_destroy(trace); }
int main() { trace_start("127.0.0.1", 8889, "/home/share/Log/TraceWorkerDebug.cpp"); CFTPManager ftpManager; trace_printf("NULL"); ftpManager.login2Server("10.17.128.105:21"); trace_printf("NULL"); ftpManager.inputUserName("huangyuan1"); trace_printf("NULL"); ftpManager.inputPassWord("7ujMko0admin"); trace_printf("NULL"); //ftpManager.Put("/Log/Makefile", "Makefile"); for (int i=0; i<5; ++i) { ftpManager.WriteData("/Log/WriteTest.txt", "12345\n", 7); } trace_printf("NULL"); ftpManager.quitServer(); return 0; }
void oz_knl_ast_setqinfo (OZ_Ast *ast, OZ_Thread_state thread_state, OZ_Astmode astmode, Long thcpuidx, Hwthctx *hwthctx, int wasempty) { #if 000 Hwthsav *exesp; int i; void **ebp; extern char trace_begaddr[1], trace_endaddr[1]; extern OZ_Thread *trace_thread; extern void trace_start (int itscurrent); ast -> thread_state = thread_state; /* save thread's state just before queuing ast */ ast -> astmode = astmode; ast -> q_wasempty = wasempty; ast -> thcpuidx = thcpuidx; /* save the cpu that the thread's context is loaded in (-1 if not) */ ast -> mycpuidx = oz_hw_cpu_getcur (); /* get my current cpu index */ if (thcpuidx == ast -> mycpuidx) { /* see if thread's context is loaded on the current cpu */ for (i = 0; i < MAXRTNADRS; i ++) { /* if so, save some return addresses */ ast -> rtnadrs[i] = oz_hw_getrtnadr (i + 1); if (wasempty && (ast -> thread == trace_thread) && (ast -> rtnadrs[i] >= trace_begaddr) && (ast -> rtnadrs[i] < trace_endaddr)) trace_start (1); if (ast -> rtnadrs[i] == NULL) break; } } else if (thcpuidx < 0) { exesp = hwthctx -> exesp; // grab its saved stack pointer ast -> exesp = exesp; // save it in the ast ast -> rtnadrs[0] = (void *)0x87654321; // in case exec stack not writable if (OZ_HW_WRITABLE (sizeof *exesp, exesp, OZ_PROCMODE_KNL)) { // make sure exec stack accessible ebp = exesp -> ebp; // ok, get its frame pointer for (i = 0; i < MAXRTNADRS; i ++) { // save this many frames at most if (!OZ_HW_WRITABLE (8, ebp, OZ_PROCMODE_KNL)) break; // break it off if not accessible ast -> rtnadrs[i] = ebp[1]; // ok, save the return address if (wasempty && (ast -> thread == trace_thread) && (ast -> rtnadrs[i] >= trace_begaddr) && (ast -> rtnadrs[i] < trace_endaddr)) trace_start (0); ebp = ebp[0]; // pop out a level } if (i < MAXRTNADRS) ast -> rtnadrs[i] = ebp; // if room, save the ebp that ended it all } } #endif }
/* Process a trace, counting packets that match filter(s) */ static void run_trace(char *uri, libtrace_filter_t *filter, int count) { struct libtrace_packet_t *packet = trace_create_packet(); /* Already read the maximum number of packets - don't need to read * anything from this trace */ if ((count >= 0 && packets_read >= count) || done) return; trace = trace_create(uri); if (trace_is_err(trace)) { trace_perror(trace,"trace_create"); return; } if (filter) { trace_config(trace,TRACE_OPTION_FILTER,filter); } if (trace_start(trace)==-1) { trace_perror(trace,"trace_start"); return; } while (1) { int psize; if (count >= 0 && packets_read >= count) break; if (done) break; if ((psize = trace_read_packet(trace, packet)) <1) { break; } if (IS_LIBTRACE_META_PACKET(packet)) continue; if (reports_required & REPORT_TYPE_MISC) misc_per_packet(packet); if (reports_required & REPORT_TYPE_ERROR) error_per_packet(packet); if (reports_required & REPORT_TYPE_PORT) port_per_packet(packet); if (reports_required & REPORT_TYPE_PROTO) protocol_per_packet(packet); if (reports_required & REPORT_TYPE_TOS) tos_per_packet(packet); if (reports_required & REPORT_TYPE_TTL) ttl_per_packet(packet); if (reports_required & REPORT_TYPE_FLOW) flow_per_packet(packet); if (reports_required & REPORT_TYPE_TCPOPT) tcpopt_per_packet(packet); if (reports_required & REPORT_TYPE_SYNOPT) synopt_per_packet(packet); if (reports_required & REPORT_TYPE_NLP) nlp_per_packet(packet); if (reports_required & REPORT_TYPE_DIR) dir_per_packet(packet); if (reports_required & REPORT_TYPE_ECN) ecn_per_packet(packet); if (reports_required & REPORT_TYPE_TCPSEG) tcpseg_per_packet(packet); packets_read ++; } if (reports_required & REPORT_TYPE_DROPS) drops_per_trace(trace); trace_destroy_packet(packet); trace_destroy(trace); }
int main(int argc, char *argv[]) { libtrace_t *trace; libtrace_packet_t *packet; libtrace_filter_t *filter=NULL; int snaplen=-1; int promisc=-1; while(1) { int option_index; struct option long_options[] = { { "filter", 1, 0, 'f' }, { "snaplen", 1, 0, 's' }, { "promisc", 1, 0, 'p' }, { "help", 0, 0, 'h' }, { "libtrace-help", 0, 0, 'H' }, { NULL, 0, 0, 0 } }; int c= getopt_long(argc, argv, "f:s:p:hH", long_options, &option_index); if (c==-1) break; switch (c) { case 'f': filter=trace_create_filter(optarg); break; case 's': snaplen=atoi(optarg); break; case 'p': promisc=atoi(optarg); break; case 'H': trace_help(); return 1; default: fprintf(stderr,"Unknown option: %c\n",c); /* FALL THRU */ case 'h': usage(argv[0]); return 1; } } if (optind>=argc) { fprintf(stderr,"Missing input uri\n"); usage(argv[0]); return 1; } while (optind<argc) { trace = trace_create(argv[optind]); ++optind; if (trace_is_err(trace)) { trace_perror(trace,"Opening trace file"); return 1; } if (snaplen>0) if (trace_config(trace,TRACE_OPTION_SNAPLEN,&snaplen)) { trace_perror(trace,"ignoring: "); } if (filter) if (trace_config(trace,TRACE_OPTION_FILTER,filter)) { trace_perror(trace,"ignoring: "); } if (promisc!=-1) { if (trace_config(trace,TRACE_OPTION_PROMISC,&promisc)) { trace_perror(trace,"ignoring: "); } } if (trace_start(trace)) { trace_perror(trace,"Starting trace"); trace_destroy(trace); return 1; } packet = trace_create_packet(); while (trace_read_packet(trace,packet)>0) { per_packet(packet); } trace_destroy_packet(packet); if (trace_is_err(trace)) { trace_perror(trace,"Reading packets"); } trace_destroy(trace); } return 0; }
int main(int argc, char *argv[]) { libtrace_t *trace; libtrace_packet_t *packet; libtrace_filter_t *filter=NULL; session_manager_t *sm; uint64_t f; while(1) { int option_index; struct option long_options[] = { { "filter", 1, 0, 'f' }, { "interval", 1, 0, 'i' }, { "count", 1, 0, 'c' }, { "exit", 1, 0, 'e' }, { "relative", 0, 0, 'r' }, { "help", 0, 0, 'h' }, { "libtrace-help",0, 0, 'H' }, { NULL, 0, 0, 0 } }; int c= getopt_long(argc, argv, "c:e:f:i:hHr", long_options, &option_index); if (c==-1) break; switch (c) { case 'f': filter=trace_create_filter(optarg); break; case 'i': packet_interval=atof(optarg); break; case 'c': packet_count=atoi(optarg); packet_interval=UINT32_MAX; // make sure only one is defined break; case 'e': report_periods=atoi(optarg); break; case 'r': report_rel_time = 1; break; case 'H': trace_help(); return 1; default: fprintf(stderr,"Unknown option: %c\n",c); /* FALL THRU */ case 'h': usage(argv[0]); return 1; } } if (optind>=argc) { fprintf(stderr,"Missing input uri\n"); usage(argv[0]); return 1; } while (optind<argc) { // create tcp session manager sm = session_manager_create(); // create and register the data-ack based RTT module session_manager_register_module(sm,rtt_n_sequence_module()); fprintf(stderr, "Processing %s\n",argv[optind]); trace = trace_create(argv[optind]); ++optind; if (trace_is_err(trace)) { trace_perror(trace,"Opening trace file"); return 1; } if (filter && trace_config(trace,TRACE_OPTION_FILTER,filter)==1) { trace_perror(trace,"Configuring filter"); } if (trace_start(trace)) { trace_perror(trace,"Starting trace"); trace_destroy(trace); return 1; } packet = trace_create_packet(); print_report_hdr(); reset_report(); last_report_ts = 0; last_packet_ts = 0; while (trace_read_packet(trace,packet)>0) { per_packet(packet,session_manager_update(sm,packet)); if (report_periods != UINT64_MAX && reported >= report_periods) { break; } } // remaining pkts (or all if no period set) if ((reports[OUT].count+reports[IN].count) > 0 || (packet_interval == UINT32_MAX && packet_count == UINT64_MAX)) { double ts = trace_get_seconds(packet); if (report_rel_time) { print_report(ts-last_report_ts); } else { print_report(ts); } } trace_destroy_packet(packet); if (trace_is_err(trace)) { trace_perror(trace,"Reading packets"); } // some stats f=trace_get_received_packets(trace); if (f!=UINT64_MAX) fprintf(stderr,"%" PRIu64 " packets on input\n",f); f=trace_get_filtered_packets(trace); if (f!=UINT64_MAX) fprintf(stderr,"%" PRIu64 " packets filtered\n",f); f=trace_get_dropped_packets(trace); if (f!=UINT64_MAX) fprintf(stderr,"%" PRIu64 " packets dropped\n",f); f=trace_get_accepted_packets(trace); if (f!=UINT64_MAX) fprintf(stderr,"%" PRIu64 " packets accepted\n",f); trace_destroy(trace); session_manager_destroy(sm); } return 0; }
int main(int argc, char *argv[]) { char *uri = 0; int psize = 0; struct libtrace_ip *ipptr = 0; struct libtrace_packet_t *packet = trace_create_packet(); libtrace_err_t trace_err; uint32_t last_second = 0; double ts = 0.0; if (argc == 2) { uri = strdup(argv[1]); } // create an trace to uri trace = trace_create(uri); if (trace_is_err(trace)) { trace_err = trace_get_err(trace); printf("Error in trace_create: %s\n", trace_err.problem); return -1; } trace_start(trace); if (trace_is_err(trace)) { trace_err = trace_get_err(trace); printf("Error in trace_start: %s\n", trace_err.problem); return -1; } for (;;) { if ((psize = trace_read_packet(trace,packet)) < 1) { // terminate break; } if (psize == 0) { continue; } if((ipptr = trace_get_ip(packet)) == 0) { continue; } counter[BYTES][INSTANT] += ntohs(ipptr->ip_len); counter[PACKETS][INSTANT] ++; ts = trace_get_seconds(packet); if(last_second == 0) { last_second = ts; } else if (last_second < ts) { last_second = ts; docalc++; } if(docalc) { secondreport(); } } trace_destroy(trace); return 0; }
int main(int argc, char *argv[]) { clock_t start; clock_t end; double function_time; struct time_adjust_record time_adjust_flow1 = {"0.0.0.0", 0, "0.0.0.0", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}; char * p = NULL; FILE * fp_time_adjust = NULL; FILE * fp_write = NULL; char time_adjust_file[128]; char file_write[256]; char input_file[256]; char buffer[256]; if (argc < 4) { printf("Please enter two parameters: read_file and write_file\n"); return 1; } strcpy(input_file, argv[1]); strcpy(time_adjust_file, argv[2]); strcpy(file_write, argv[3]); if((fp_time_adjust = fopen(time_adjust_file, "r")) == NULL) //open the file to read { fprintf(stderr, "Open time adjust file: %s failed\n", time_adjust_file); exit(1); } memset(buffer, '\0', sizeof(buffer)); fgets(buffer, sizeof(buffer), fp_time_adjust); p = strtok(buffer, " "); if(p) { strcpy( time_adjust_flow1.src_ip, p); } p = strtok(NULL, " "); if(p) { time_adjust_flow1.src_port = atoi(p); } p = strtok(NULL, " "); if(p) { strcpy( time_adjust_flow1.dest_ip, p); } p = strtok(NULL, " "); if(p) { time_adjust_flow1.dest_port = atoi(p); } //printf("flow: %s:%d %s:%d\n", time_adjust_flow1.src_ip, time_adjust_flow1.src_port, time_adjust_flow1.dest_ip, time_adjust_flow1.dest_port); memset(buffer, '\0', sizeof(buffer)); fgets(buffer, sizeof(buffer), fp_time_adjust); if( Set_Time_Adjust(buffer, &time_adjust_flow1.first_pkt_sec, &time_adjust_flow1.first_pkt_usec) != 0 ) { printf("line: %d\n", __LINE__); exit(1); } //printf("First packet second: %d, usecond: %d\n", time_adjust_flow1.first_pkt_sec, time_adjust_flow1.first_pkt_usec); memset(buffer, '\0', sizeof(buffer)); fgets(buffer, sizeof(buffer), fp_time_adjust); if( Set_Time_Adjust(buffer, &time_adjust_flow1.client_inter_sec, &time_adjust_flow1.client_inter_usec) != 0 ) { printf("line: %d\n", __LINE__); exit(1); } //printf("Client packet inter arrival second: %d, usecond: %d\n", time_adjust_flow1.client_inter_sec, time_adjust_flow1.client_inter_usec); memset(buffer, '\0', sizeof(buffer)); fgets(buffer, sizeof(buffer), fp_time_adjust); if( Set_Time_Adjust(buffer, &time_adjust_flow1.server_inter_sec, &time_adjust_flow1.server_inter_usec) != 0 ) { printf("line: %d\n", __LINE__); exit(1); } //printf("Server packet inter arrival second: %d, usecond: %d\n", time_adjust_flow1.server_inter_sec, time_adjust_flow1.server_inter_usec); memset(buffer, '\0', sizeof(buffer)); fgets(buffer, sizeof(buffer), fp_time_adjust); if( Set_Time_Adjust(buffer, &time_adjust_flow1.reaction_sec, &time_adjust_flow1.reaction_usec) != 0 ) { printf("line: %d\n", __LINE__); exit(1); } //printf("Client reaction second: %d, usecond: %d\n", time_adjust_flow1.reaction_sec, time_adjust_flow1.reaction_usec); memset(buffer, '\0', sizeof(buffer)); fgets(buffer, sizeof(buffer), fp_time_adjust); if( Set_Time_Adjust(buffer, &time_adjust_flow1.rtt_sec, &time_adjust_flow1.rtt_usec) != 0 ) { printf("line: %d\n", __LINE__); exit(1); } //time_adjust_flow1.rtt_usec = time_adjust_flow1.rtt_sec*1000 + time_adjust_flow1.rtt_usec*1000; //time_adjust_flow1.rtt_sec = time_adjust_flow1.rtt_sec/1000; //printf("Client RTT second: %d, usecond: %d\n", time_adjust_flow1.rtt_sec, time_adjust_flow1.rtt_usec); fclose(fp_time_adjust); if((fp_write=fopen(file_write, "w")) == NULL) //open the file to read { fprintf(stderr, "Open write file: %s failed\n", file_write); exit(1); } libtrace_t *trace = 0; libtrace_out_t *writer = 0; libtrace_packet_t *pkt = trace_create_packet(); // Open traces for reading and writing. trace = trace_create(input_file); if (trace_is_err(trace)) { trace_perror(trace, "trace_create"); trace_destroy(trace); return 1; } if (trace_start(trace) == -1) { trace_perror(trace,"Starting trace"); //libtrace_cleanup(trace, output, packet); return 1; } //char output_file[] = "pcap:ttt.pcap"; //writer = trace_create_output("pcap:testcp"); /*writer = trace_create_output(output_file); if (trace_is_err_output(writer)) { trace_perror_output(writer, "trace_create_output"); trace_destroy_output(writer); trace_destroy(trace); trace_destroy_packet(pkt); return 1; } if (trace_start_output(writer) == -1) { trace_perror_output(writer,"Starting output trace"); //libtrace_cleanup(trace, output, packet); return 1; }*/ int psize = 0; int pkt_count = 0; for (;;) { psize = trace_read_packet(trace, pkt); if (psize == 0) { break; } if (psize < 0) { trace_perror(trace, "read_packet"); break; } //if(pkt_count < 50) { //printf("packet: %d\n", pkt_count); if ((per_packet(pkt, fp_write, &time_adjust_flow1)) == -1) { fprintf(stderr, "Something went wrong in per_packet.\n"); break; } } pkt_count++; } trace_destroy_packet(pkt); trace_destroy(trace); //trace_destroy_output(writer); fclose(fp_write); return 0; }
corsaro_file_in_t *corsaro_file_ropen(const char *filename) { corsaro_file_in_t *f = NULL; char buffer[1024]; int len; /* 2013-01-22 AK has removed all of the logging output on failures this is because i dont want to need a corsaro_t object to open a file. but also because i think it should be up to the caller to log the errors. logs from this deep in corsaro just confuse people when somewhat common errors occur (file not found etc). */ if((f = malloc(sizeof(corsaro_file_in_t))) == NULL) { return NULL; } /* we need to try and guess the mode... */ /* if there is a : in the uri, we guess it is a libtrace file */ /* this should be refined to do something more intelligent */ if(strchr(filename, ':') != NULL) { f->mode = CORSARO_FILE_MODE_TRACE; /* open this as a trace file */ f->trace_io = trace_create(filename); if(trace_is_err(f->trace_io)) { free(f); return NULL; } if (trace_start(f->trace_io) == -1) { free(f); return NULL; } /* trace is set to go! */ return f; } else { /* lets open the file and take a peek to see what we find */ if((f->wand_io = wandio_create(filename)) == NULL) { free(f); return NULL; } len = wandio_peek(f->wand_io, buffer, sizeof(buffer)); /* an ASCII corsaro file will start with "# CORSARO_VERSION" */ if(len >= strlen(CORSARO_FILE_ASCII_CHECK) && memcmp(CORSARO_FILE_ASCII_CHECK, buffer, strlen(CORSARO_FILE_ASCII_CHECK)) == 0) { f->mode = CORSARO_FILE_MODE_ASCII; } /* a binary corsaro file will start with an corsaro header "EDGRHEAD" but, it is possible that an old binary corsaro file can just start with an interval header - "EDGRINTR", so we will only look for "EDGR" */ else if(len >= 4 && buffer[0] == 'E' && buffer[1] == 'D' && buffer[2] == 'G' && buffer[3] == 'R') { f->mode = CORSARO_FILE_MODE_BINARY; } else { /* who knows, but maybe someone wants to read a non-corsaro file */ f->mode = CORSARO_FILE_MODE_UNKNOWN; } } return f; }
int main(int argc, char *argv[]) { char *compress_type_str=NULL; struct libtrace_filter_t *filter=NULL; struct libtrace_t *input = NULL; struct libtrace_packet_t *packet = trace_create_packet(); struct sigaction sigact; int i; if (argc<2) { usage(argv[0]); return 1; } /* Parse command line options */ while(1) { int option_index; struct option long_options[] = { { "filter", 1, 0, 'f' }, { "count", 1, 0, 'c' }, { "bytes", 1, 0, 'b' }, { "starttime", 1, 0, 's' }, { "endtime", 1, 0, 'e' }, { "interval", 1, 0, 'i' }, { "libtrace-help", 0, 0, 'H' }, { "maxfiles", 1, 0, 'm' }, { "snaplen", 1, 0, 'S' }, { "verbose", 0, 0, 'v' }, { "compress-level", 1, 0, 'z' }, { "compress-type", 1, 0, 'Z' }, { NULL, 0, 0, 0 }, }; int c=getopt_long(argc, argv, "f:c:b:s:e:i:m:S:Hvz:Z:", long_options, &option_index); if (c==-1) break; switch (c) { case 'f': filter=trace_create_filter(optarg); break; case 'c': count=atoi(optarg); break; case 'b': bytes=atoi(optarg); break; case 's': starttime=atof(optarg); /* FIXME: use getdate */ break; case 'e': endtime=atof(optarg); break; case 'i': interval=atoi(optarg); break; case 'm': maxfiles=atoi(optarg); break; case 'S': snaplen=atoi(optarg); break; case 'H': trace_help(); exit(1); break; case 'v': verbose++; break; case 'z': compress_level=atoi(optarg); if (compress_level<0 || compress_level>9) { usage(argv[0]); exit(1); } break; case 'Z': compress_type_str=optarg; break; default: fprintf(stderr,"Unknown option: %c\n",c); usage(argv[0]); return 1; } } if (compress_type_str == NULL && compress_level >= 0) { fprintf(stderr, "Compression level set, but no compression type was defined, setting to gzip\n"); compress_type = TRACE_OPTION_COMPRESSTYPE_ZLIB; } else if (compress_type_str == NULL) { /* If a level or type is not specified, use the "none" * compression module */ compress_type = TRACE_OPTION_COMPRESSTYPE_NONE; } /* I decided to be fairly generous in what I accept for the * compression type string */ else if (strncmp(compress_type_str, "gz", 2) == 0 || strncmp(compress_type_str, "zlib", 4) == 0) { compress_type = TRACE_OPTION_COMPRESSTYPE_ZLIB; } else if (strncmp(compress_type_str, "bz", 2) == 0) { compress_type = TRACE_OPTION_COMPRESSTYPE_BZ2; } else if (strncmp(compress_type_str, "lzo", 3) == 0) { compress_type = TRACE_OPTION_COMPRESSTYPE_LZO; } else if (strncmp(compress_type_str, "no", 2) == 0) { compress_type = TRACE_OPTION_COMPRESSTYPE_NONE; } else { fprintf(stderr, "Unknown compression type: %s\n", compress_type_str); return 1; } if (optind+2>argc) { fprintf(stderr,"missing inputuri or outputuri\n"); usage(argv[0]); } output_base = argv[argc - 1]; sigact.sa_handler = cleanup_signal; sigemptyset(&sigact.sa_mask); sigact.sa_flags = SA_RESTART; sigaction(SIGINT, &sigact, NULL); sigaction(SIGTERM, &sigact, NULL); output=NULL; signal(SIGINT,&cleanup_signal); signal(SIGTERM,&cleanup_signal); for (i = optind; i < argc - 1; i++) { input = trace_create(argv[i]); if (trace_is_err(input)) { trace_perror(input,"%s",argv[i]); return 1; } if (filter && trace_config(input, TRACE_OPTION_FILTER, filter) == 1) { trace_perror(input, "Configuring filter for %s", argv[i]); return 1; } if (trace_start(input)==-1) { trace_perror(input,"%s",argv[i]); return 1; } while (trace_read_packet(input,packet)>0) { if (per_packet(packet) < 1) done = 1; if (done) break; } if (done) break; if (trace_is_err(input)) { trace_perror(input,"Reading packets"); trace_destroy(input); break; } trace_destroy(input); } if (verbose) { uint64_t f; f=trace_get_received_packets(input); if (f!=UINT64_MAX) fprintf(stderr,"%" PRIu64 " packets on input\n",f); f=trace_get_filtered_packets(input); if (f!=UINT64_MAX) fprintf(stderr,"%" PRIu64 " packets filtered\n",f); f=trace_get_dropped_packets(input); if (f!=UINT64_MAX) fprintf(stderr,"%" PRIu64 " packets dropped\n",f); f=trace_get_accepted_packets(input); if (f!=UINT64_MAX) fprintf(stderr,"%" PRIu64 " packets accepted\n",f); } if (output) trace_destroy_output(output); trace_destroy_packet(packet); return 0; }
/* Process a trace, counting packets that match filter(s) */ static void run_trace(char *uri) { struct libtrace_packet_t *packet = trace_create_packet(); int i; uint64_t count = 0; uint64_t bytes = 0; uint64_t packets; fprintf(stderr,"%s:\n",uri); trace = trace_create(uri); if (trace_is_err(trace)) { trace_perror(trace,"Failed to create trace"); return; } if (trace_start(trace)==-1) { trace_perror(trace,"Failed to start trace"); return; } for (;;) { int psize; int wlen; int match = 0; if ((psize = trace_read_packet(trace, packet)) <1) { break; } if (done) break; wlen = trace_get_wire_length(packet); for(i=0; i<filter_count; ++i) { if (filters[i].filter == NULL) continue; if(trace_apply_filter(filters[i].filter,packet) > 0) { ++filters[i].count; filters[i].bytes+=wlen; match = 1; } if (trace_is_err(trace)) { trace_perror(trace, "trace_apply_filter"); fprintf(stderr, "Removing filter from filterlist\n"); filters[i].filter = NULL; } } if(match == 1 || filter_count == 0) { libtrace_ip_t *ip_hdr = trace_get_ip(packet); if(ip_hdr != NULL) { char src_ip[INET_ADDRSTRLEN]; char dst_ip[INET_ADDRSTRLEN]; inet_ntop(AF_INET, &ip_hdr->ip_src, &src_ip[0], INET_ADDRSTRLEN); inet_ntop(AF_INET, &ip_hdr->ip_dst, &dst_ip[0], INET_ADDRSTRLEN); printf("%f\t%s\t%s\t%"PRIu16"\t%"PRIu16"\t" "%"PRIu8"\t%"PRIu16"\t%"PRIu16"\n", trace_get_seconds(packet), src_ip, dst_ip, trace_get_source_port(packet), trace_get_destination_port(packet), ip_hdr->ip_p, ntohs(ip_hdr->ip_id), ntohs(ip_hdr->ip_len) ); } } ++count; bytes+=wlen; } fprintf(stderr, "%-30s\t%12s\t%12s\t%7s\n","filter","count","bytes","%"); for(i=0; i<filter_count; ++i) { fprintf(stderr, "%30s:\t%12"PRIu64"\t%12"PRIu64"\t%7.03f\n", filters[i].expr,filters[i].count, filters[i].bytes,filters[i].count*100.0/count); filters[i].bytes=0; filters[i].count=0; } packets=trace_get_received_packets(trace); if (packets!=UINT64_MAX) fprintf(stderr,"%30s:\t%12" PRIu64"\n", "Input packets", packets); packets=trace_get_filtered_packets(trace); if (packets!=UINT64_MAX) fprintf(stderr,"%30s:\t%12" PRIu64"\n", "Filtered packets", packets); packets=trace_get_dropped_packets(trace); if (packets!=UINT64_MAX) fprintf(stderr,"%30s:\t%12" PRIu64"\n", "Dropped packets",packets); packets=trace_get_accepted_packets(trace); if (packets!=UINT64_MAX) fprintf(stderr,"%30s:\t%12" PRIu64 "\n", "Accepted Packets",packets); fprintf(stderr, "%30s:\t%12"PRIu64"\t%12" PRIu64 "\n","Total",count,bytes); totcount+=count; totbytes+=bytes; if (trace_is_err(trace)) trace_perror(trace,"%s",uri); trace_destroy(trace); }
RtTraceMotif::RtTraceMotif( void *tr_parent_ctx, Widget tr_parent_wid, pwr_tObjid tr_objid, pwr_tStatus *status) : RtTrace( tr_parent_ctx, tr_objid, status), parent_wid(tr_parent_wid) { // FlowWidget fwidget; char uid_filename[120] = {"xtt_trace.uid"}; char *uid_filename_p = uid_filename; Arg args[20]; unsigned long sts; pwr_tOName name; int i; pwr_tObjid window_objid; pwr_tClassId cid; char title[220]; pwr_tOName hostname; pwr_tOName plcconnect; MrmHierarchy s_DRMh; MrmType dclass; Widget trace_widget; static MrmRegisterArg reglist[] = { {(char*) "tra_ctx", 0 }, {(char*) "tra_activate_close",(caddr_t)activate_close }, {(char*) "tra_activate_print",(caddr_t)activate_print }, {(char*) "tra_activate_printselect",(caddr_t)activate_printselect }, {(char*) "tra_activate_savetrace",(caddr_t)activate_savetrace }, {(char*) "tra_activate_restoretrace",(caddr_t)activate_restoretrace }, {(char*) "tra_activate_cleartrace",(caddr_t)activate_cleartrace }, {(char*) "tra_activate_trace",(caddr_t)activate_trace }, {(char*) "tra_activate_display_object",(caddr_t)activate_display_object }, {(char*) "tra_activate_open_object",(caddr_t)activate_open_object }, {(char*) "tra_activate_show_cross",(caddr_t)activate_show_cross }, {(char*) "tra_activate_open_classgraph",(caddr_t)activate_open_classgraph }, {(char*) "tra_activate_collect_insert",(caddr_t)activate_collect_insert }, {(char*) "tra_activate_view",(caddr_t)activate_view }, {(char*) "tra_activate_simulate",(caddr_t)activate_simulate }, {(char*) "tra_activate_zoomin",(caddr_t)activate_zoomin }, {(char*) "tra_activate_zoomout",(caddr_t)activate_zoomout }, {(char*) "tra_activate_zoomreset",(caddr_t)activate_zoomreset }, {(char*) "tra_activate_scantime1",(caddr_t)activate_scantime1 }, {(char*) "tra_activate_scantime2",(caddr_t)activate_scantime2 }, {(char*) "tra_activate_scantime3",(caddr_t)activate_scantime3 }, {(char*) "tra_activate_scantime4",(caddr_t)activate_scantime4 }, {(char*) "tra_activate_scantime5",(caddr_t)activate_scantime5 }, {(char*) "tra_activate_help",(caddr_t)activate_help }, {(char*) "tra_activate_helpplc",(caddr_t)activate_helpplc }, {(char*) "tra_create_form",(caddr_t)create_form }, {(char*) "tra_create_menu",(caddr_t)create_menu } }; static int reglist_num = (sizeof reglist / sizeof reglist[0]); lng_get_uid( uid_filename, uid_filename); sts = gdh_ObjidToName( tr_objid, name, sizeof(name), cdh_mNName); if (EVEN(sts)) { *status = sts; return; } strcpy( title, "Trace "); strcat( title, name); /* Find plcwindow */ sts = gdh_GetObjectClass( tr_objid, &cid); if ( EVEN(sts)) { *status = sts; return; } if ( !(cid == pwr_cClass_windowplc || cid == pwr_cClass_windowcond || cid == pwr_cClass_windoworderact || cid == pwr_cClass_windowsubstep )) { sts = gdh_GetChild( tr_objid, &window_objid); if ( EVEN(sts)) { *status = sts; return; } } else window_objid = tr_objid; sts = gdh_GetObjectClass( window_objid, &cid); if ( EVEN(sts)) { *status = sts; return; } if ( !(cid == pwr_cClass_windowplc || cid == pwr_cClass_windowcond || cid == pwr_cClass_windoworderact || cid == pwr_cClass_windowsubstep )) { *status = 0; return; } sts = get_filename( window_objid, filename, &m_has_host, hostname, plcconnect); if ( EVEN(sts)) { *status = sts; return; } /* Create object context */ objid = window_objid; if ( m_has_host) { strcpy( m_hostname, hostname); strcpy( m_plcconnect, plcconnect); } reglist[0].value = (caddr_t) this; toplevel = XtCreatePopupShell( name, topLevelShellWidgetClass, parent_wid, args, 0); /* Save the context structure in the widget */ XtSetArg (args[0], XmNuserData, (XtPointer) this); sts = MrmOpenHierarchy( 1, &uid_filename_p, NULL, &s_DRMh); if (sts != MrmSUCCESS) printf("can't open %s\n", uid_filename); MrmRegisterNames(reglist, reglist_num); sts = MrmFetchWidgetOverride( s_DRMh, (char*) "trace_window", toplevel, title, args, 1, &trace_widget, &dclass); if (sts != MrmSUCCESS) printf("can't fetch %s\n", name); MrmCloseHierarchy(s_DRMh); i = 0; XtSetArg(args[i],XmNwidth,800);i++; XtSetArg(args[i],XmNheight,600);i++; XtSetValues( toplevel ,args,i); XtManageChild( trace_widget); i = 0; /* XtSetArg(args[i],XmNwidth,790);i++; XtSetArg(args[i],XmNheight,560);i++; */ XtSetArg( args[i], XmNtopAttachment, XmATTACH_WIDGET);i++; XtSetArg( args[i], XmNtopWidget, menu);i++; XtSetArg( args[i], XmNrightAttachment, XmATTACH_FORM);i++; XtSetArg( args[i], XmNleftAttachment, XmATTACH_FORM);i++; XtSetArg( args[i], XmNbottomAttachment, XmATTACH_FORM);i++; flow_widget = FlowCreate( form, (char*) "Flow window", args, i, init_flow, (void *)this); XtManageChild( (Widget) flow_widget); /* XtRealizeWidget(toplevel); */ XtPopup( toplevel, XtGrabNone); // fwidget = (FlowWidget) flow_widget; // flow_ctx = (flow_tCtx)fwidget->flow.flow_ctx; // flow_SetCtxUserData( flow_ctx, this); /* Create navigator popup */ i = 0; XtSetArg(args[i],XmNallowShellResize, TRUE); i++; XtSetArg(args[i],XmNallowResize, TRUE); i++; XtSetArg(args[i],XmNwidth,200);i++; XtSetArg(args[i],XmNheight,200);i++; XtSetArg(args[i],XmNx,500);i++; XtSetArg(args[i],XmNy,500);i++; nav_shell = XmCreateDialogShell( flow_widget, (char*) "Navigator", args, i); XtManageChild( nav_shell); i = 0; XtSetArg(args[i],XmNwidth,200);i++; XtSetArg(args[i],XmNheight,200);i++; nav_widget = FlowCreateNav( nav_shell, (char*) "navigator", args, i, flow_widget); XtManageChild( nav_widget); XtRealizeWidget( nav_shell); // Connect the window manager close-button to exit flow_AddCloseVMProtocolCb( toplevel, (XtCallbackProc)activate_close, this); wow = new CoWowMotif( toplevel); trace_timerid = wow->timer_new(); viewsetup(); flow_Open( flow_ctx, filename); trasetup(); trace_start(); #if defined OS_LINUX { struct stat info; if ( stat( filename, &info) != -1) version = info.st_ctime; } #endif }
int main(int argc, char *argv[]) { int psize = 0; int error = 0; int count = 0; int level = 0; int expected = 100; libtrace_t *trace; libtrace_out_t *outtrace; libtrace_packet_t *packet; trace = trace_create(lookup_uri("pcap")); iferr(trace); outtrace = trace_create_output(lookup_out_uri("pcap")); iferrout(outtrace); level=0; trace_config_output(outtrace,TRACE_OPTION_OUTPUT_COMPRESS,&level); iferrout(outtrace); trace_start(trace); iferr(trace); trace_start_output(outtrace); iferrout(outtrace); packet=trace_create_packet(); for (;;) { if ((psize = trace_read_packet(trace, packet)) <0) { error = 1; break; } if (psize == 0) { error = 0; break; } count ++; /* Force promotion */ if (trace_get_source_port(packet)==80) { trace_set_direction(packet,TRACE_DIR_OUTGOING); assert(trace_get_direction(packet)==TRACE_DIR_OUTGOING); assert(trace_get_source_port(packet)==80); } else { trace_set_direction(packet,TRACE_DIR_INCOMING); assert(trace_get_direction(packet)==TRACE_DIR_INCOMING); } /* And then force demotion */ trace_write_packet(outtrace,packet); iferrout(outtrace); if (count>100) break; } trace_destroy_packet(packet); if (error == 0) { if (count != expected) { printf("failure: %d packets expected, %d seen\n",expected,count); error = 1; } } else { iferr(trace); } trace_destroy(trace); trace_destroy_output(outtrace); return error; }
int main(int argc, char *argv[]) { int psize = 0; int error = 0; int ip_count = 0; int arp_count = 0; libtrace_t *trace; libtrace_packet_t *packet; (void)argc; (void)argv; trace = trace_create("pcapfile:traces/vxlan.pcap"); iferr(trace); trace_start(trace); iferr(trace); packet=trace_create_packet(); for (;;) { uint8_t proto; uint32_t remaining; void *transport; void *layer2; void *vxlan; if ((psize = trace_read_packet(trace, packet)) < 0) { error = 1; iferr(trace); break; } if (psize == 0) { break; } transport = trace_get_transport(packet, &proto, &remaining); if (proto != TRACE_IPPROTO_UDP) { printf("Failed to find a UDP header\n"); error = 1; continue; } vxlan = trace_get_vxlan_from_udp(transport, &remaining); if (!vxlan) { printf("Failed to find a VXLAN header\n"); error = 1; continue; } layer2 = trace_get_payload_from_vxlan(vxlan, &remaining); switch (ntohs(((libtrace_ether_t *)layer2)->ether_type)) { case 0x0800: ip_count++; break; case 0x0806: arp_count++; break; default: fprintf(stderr, "Unexpected vxlan ethertype: %08x\n", ntohs(((libtrace_ether_t *)layer2)->ether_type)); error = 1; continue; } } trace_destroy_packet(packet); if (ip_count != 8 || arp_count != 2) { fprintf(stderr, "Incorrect number of ip/arp packets\n"); error = 1; } if (error == 0) { printf("success\n"); } else { iferr(trace); } trace_destroy(trace); return error; }
/*===========================================================================* * blockdriver_process_on_thread * *===========================================================================*/ void blockdriver_process_on_thread(struct blockdriver *bdp, message *m_ptr, int ipc_status, thread_id_t id) { /* Call the appropiate driver function, based on the type of request. Send * a result code to the caller. The call is processed in the context of the * given thread ID, which may be SINGLE_THREAD for single-threaded callers. */ int r; /* Check for notifications first. We never reply to notifications. */ if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(m_ptr->m_source)) { case HARDWARE: if (bdp->bdr_intr) (*bdp->bdr_intr)(m_ptr->m_notify.interrupts); break; case CLOCK: if (bdp->bdr_alarm) (*bdp->bdr_alarm)(m_ptr->m_notify.timestamp); break; default: if (bdp->bdr_other) (*bdp->bdr_other)(m_ptr, ipc_status); } return; /* do not send a reply */ } /* Reply to character driver open requests with an error code. Otherwise, if * someone creates a character device node for a block driver, opening that * device node will cause the corresponding VFS thread to block forever. */ if (m_ptr->m_type == CDEV_OPEN) { do_char_open(m_ptr, ipc_status); return; } /* We might get spurious requests if the driver has been restarted. Deny any * requests on devices that have not previously been opened, signaling the * caller that something went wrong. */ if (IS_BDEV_RQ(m_ptr->m_type) && !is_open_dev(m_ptr->m_lbdev_lblockdriver_msg.minor)) { /* Reply ERESTART to spurious requests for unopened devices. */ if (m_ptr->m_type != BDEV_OPEN) { blockdriver_reply(m_ptr, ipc_status, ERESTART); return; } /* Mark the device as opened otherwise. */ set_open_dev(m_ptr->m_lbdev_lblockdriver_msg.minor); } trace_start(id, m_ptr); /* Call the appropriate function(s) for this request. */ switch (m_ptr->m_type) { case BDEV_OPEN: r = do_open(bdp, m_ptr); break; case BDEV_CLOSE: r = do_close(bdp, m_ptr); break; case BDEV_READ: case BDEV_WRITE: r = do_rdwt(bdp, m_ptr); break; case BDEV_GATHER: case BDEV_SCATTER: r = do_vrdwt(bdp, m_ptr, id); break; case BDEV_IOCTL: r = do_ioctl(bdp, m_ptr); break; default: if (bdp->bdr_other != NULL) (*bdp->bdr_other)(m_ptr, ipc_status); return; /* do not send a reply */ } /* Let the driver perform any cleanup. */ if (bdp->bdr_cleanup != NULL) (*bdp->bdr_cleanup)(); trace_finish(id, r); blockdriver_reply(m_ptr, ipc_status, r); }
int main(int argc, char *argv[]) { struct libtrace_t *input = NULL; struct libtrace_out_t *in_write = NULL; struct libtrace_out_t *out_write = NULL; libtrace_err_t trace_err; struct libtrace_packet_t *packet = trace_create_packet(); if (argc < 3) { usage(argv[0]); return 1; } input = trace_create(argv[1]); if (trace_is_err(input)) { trace_err = trace_get_err(input); printf("Problem reading input trace: %s\n", trace_err.problem); return 1; } if (trace_start(input)==-1) { trace_perror(input,"Unable to start trace: %s",argv[1]); return 1; } while(1) { if (trace_read_packet(input, packet) < 1) break; switch(trace_get_direction(packet)) { case TRACE_DIR_INCOMING: if (!out_write) { out_write = create_output(argv[3]); if (!out_write) return 1; } if (trace_write_packet(out_write, packet)==-1){ trace_perror_output(in_write,"write"); return 1; } break; case TRACE_DIR_OUTGOING: if (!in_write) { in_write = create_output(argv[2]); if (!in_write) return 1; } if (trace_write_packet(in_write, packet)==-1) { trace_perror_output(in_write,"write"); return 1; } break; default: ignored++; } } if (out_write) trace_destroy_output(out_write); if (in_write) trace_destroy_output(in_write); trace_destroy(input); trace_destroy_packet(packet); if (ignored) fprintf(stderr,"warning: Ignored %" PRIu64 " packets with unknown directions\n", ignored); return 0; }