static void filter_cleanup (struct pipe_filter_gi *filter, bool finish_reading) { if (finish_reading) /* A select loop, with done_writing = true. */ filter_loop (filter, NULL, 0); if (sigaction (SIGPIPE, &filter->orig_sigpipe_action, NULL) < 0) abort (); }
/* * Set up the pcap plumbing and call the main filter loop. */ static void do_filter(void) { char errbuf[PCAP_ERRBUF_SIZE]; /* Error buffer for pcap */ struct pcap_plumbing plumbing = { NULL, NULL }; if (opt_infile) { plumbing.source = pcap_open_offline(opt_infile, errbuf); } else { /* A NULL opt_device is safe; pcap takes it to mean "any". */ plumbing.source = pcap_open_live(opt_device, PCAP_MAX_PKT_SZ, PCAP_PROMISC, PCAP_TIMEOUT, errbuf); } if (!plumbing.source) { die(STATUS_IO, "error opening file '%s' or device '%s'%s", opt_infile, opt_device, errbuf); } if (opt_outfile) { plumbing.sink = pcap_dump_open(plumbing.source, opt_outfile); if (!plumbing.sink) { die(STATUS_IO, "error opening output file %s", opt_outfile); } } if (opt_filter) { struct bpf_program bpf; if (pcap_compile(plumbing.source, &bpf, opt_filter, 0, 0)) { char *pcap_error = pcap_geterr(plumbing.source); die(STATUS_PCAP, "bpf compile error %s", pcap_error); } if (pcap_setfilter(plumbing.source, &bpf)) { char *pcap_error = pcap_geterr(plumbing.source); die(STATUS_PCAP, "bpf filter error %s", pcap_error); } pcap_freecode(&bpf); } filter_loop(&plumbing); pcap_dump_flush(plumbing.sink); pcap_dump_close(plumbing.sink); pcap_close(plumbing.source); }
int main(int argc, char *argv[]) { void *mystuff; /* * this MUST be the first think your filter does. * do not do anything before that call: NOTHING. */ filter_init(); /* * NOW you can allocate your structures, read a configuration * file or do anything required to prepare your filter before * it starts handling requests. */ mystuff = malloc(42); /* * we only need to register for callbacks we're interested in */ filter_register_helo_callback(helo_cb, mystuff); filter_register_mail_callback(mail_cb, mystuff); filter_register_rcpt_callback(rcpt_cb, mystuff); /* * filter_register_ehlo_callback(helo_cb, mystuff); * filter_register_rcpt_callback(rcpt_cb, mystuff); * filter_register_dataline_callback(dataline_cb, mystuff); * filter_register_quit_callback(quit_cb, mystuff); */ /* * finally, enter the filter_loop(). * it will not return unless a critical failure happens. * do not call exit() from a callback. */ filter_loop(); return 0; }
int pipe_filter_gi_write (struct pipe_filter_gi *filter, const void *buf, size_t size) { if (buf == NULL) /* Invalid argument. */ abort (); if (filter->exited) return filter_retcode (filter); if (size > 0) { filter_loop (filter, buf, size); if (filter->writer_terminated || filter->reader_terminated) { filter_terminate (filter); return filter_retcode (filter); } } return 0; }
void TIMER0_IRQHandler () { if (TIM_GetIntStatus(LPC_TIM0, TIM_MR0_INT) == SET) { NVIC_DisableIRQ(TIMER0_IRQn); //disable interrupt, to prevent it from overlapping if it takes too long to process TIM_ClearIntPending(LPC_TIM0,TIM_MR0_INT); TIM_ResetCounter(LPC_TIM0); #if DEBUG==1 && TRACE==1 tty_writeln("Timer trigger"); #endif if (scramble_mode) { scramble_timer_handler(); } else { filter_loop(); } cycle++; //used for sine wave generation if(cycle > frequency) cycle = 0; NVIC_EnableIRQ(TIMER0_IRQn); } }