Changeset ab4cb04 for lib/format_pcap.c


Ignore:
Timestamp:
02/27/06 14:31:09 (16 years ago)
Author:
Perry Lorier <perry@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
d5879cc
Parents:
afd0b73
Message:

Cleanup struct libtrace_Format_data_t

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_pcap.c

    rafd0b73 rab4cb04  
    6969static struct libtrace_format_t pcapint;
    7070
    71 #define DATA(x) ((struct libtrace_format_data_t*)((x)->format_data))
    72 
    73 #define INPUT libtrace->format_data->input
    74 #define OUTPUT libtrace->format_data->output
    75 struct libtrace_format_data_t {
     71#define DATA(x) ((struct pcap_format_data_t*)((x)->format_data))
     72#define DATAOUT(x) ((struct pcap_format_data_out_t*)((x)->format_data))
     73
     74#define INPUT DATA(libtrace)->input
     75#define OUTPUT DATAOUT(libtrace)->output
     76struct pcap_format_data_t {
    7677        union {
    7778                char *path;             /**< information for local sockets */
     
    8889};
    8990
    90 struct libtrace_format_data_out_t {
     91struct pcap_format_data_out_t {
    9192        union {
    9293                char *path;
     
    103104
    104105static int pcap_init_input(struct libtrace_t *libtrace) {
    105         libtrace->format_data = (struct libtrace_format_data_t *)
    106                 malloc(sizeof(struct libtrace_format_data_t));
     106        libtrace->format_data = malloc(sizeof(struct pcap_format_data_t));
    107107
    108108        INPUT.pcap = NULL;
     
    163163
    164164static int pcap_init_output(struct libtrace_out_t *libtrace) {
    165         libtrace->format_data = (struct libtrace_format_data_out_t *)
    166                 malloc(sizeof(struct libtrace_format_data_out_t));
     165        libtrace->format_data = malloc(sizeof(struct pcap_format_data_out_t));
    167166        OUTPUT.trace.pcap = NULL;
    168167        OUTPUT.trace.dump = NULL;
     
    171170
    172171static int pcapint_init_input(struct libtrace_t *libtrace) {
    173         libtrace->format_data = (struct libtrace_format_data_t *)
    174                 malloc(sizeof(struct libtrace_format_data_t));
     172        libtrace->format_data = malloc(sizeof(struct pcap_format_data_t));
    175173        DATA(libtrace)->filter = NULL;
    176174        DATA(libtrace)->snaplen = LIBTRACE_PACKET_BUFSIZE;
     
    225223}
    226224
    227 static int pcapint_init_output(struct libtrace_out_t *libtrace) {
    228         trace_set_err_out(libtrace,TRACE_ERR_NO_INIT_OUT,
    229                         "Writing to a pcap interface not implemented yet");
    230         return -1;
    231 }
    232 
    233225static int pcap_fin_input(struct libtrace_t *libtrace) {
    234         pcap_close(INPUT.pcap);
     226        /* we don't need to close the pcap object since libtrace will have
     227         * paused the trace for us.
     228         */
    235229        free(libtrace->format_data);
    236230        return 0;
    237231}
    238232
    239 static int pcap_fin_output(struct libtrace_out_t *libtrace) {
     233static int pcap_fin_output(libtrace_out_t *libtrace) {
    240234        pcap_dump_flush(OUTPUT.trace.dump);
    241235        pcap_dump_close(OUTPUT.trace.dump);
     
    243237        free(libtrace->format_data);
    244238        return 0;
    245 }
    246 
    247 static int pcapint_fin_output(struct libtrace_out_t *libtrace __attribute__((unused))) {
    248         return -1;
    249239}
    250240
     
    288278}
    289279
    290 static int pcap_write_packet(struct libtrace_out_t *libtrace, const struct libtrace_packet_t *packet) {
     280static int pcap_start_output(libtrace_out_t *libtrace)
     281{
     282        assert(!OUTPUT.trace.dump);
     283        OUTPUT.trace.dump = pcap_dump_open(OUTPUT.trace.pcap,
     284                        libtrace->uridata);
     285        fflush((FILE *)OUTPUT.trace.dump);
     286}
     287
     288static int pcap_write_packet(libtrace_out_t *libtrace, const libtrace_packet_t *packet) {
    291289        struct pcap_pkthdr pcap_pkt_hdr;
    292290
     
    295293                        libtrace_to_pcap_dlt(trace_get_link_type(packet)),
    296294                        65536);
    297                 OUTPUT.trace.dump = pcap_dump_open(OUTPUT.trace.pcap,
    298                                 libtrace->uridata);
    299                 fflush((FILE *)OUTPUT.trace.dump);
    300295        }
    301296        if (libtrace->format == &pcap ||
     
    318313}
    319314
    320 static int pcapint_write_packet(struct libtrace_out_t *libtrace __attribute__((unused)), const struct libtrace_packet_t *packet __attribute__((unused))) {
    321 
    322         assert(0);
    323         return 0;
    324 }
    325 
    326315static libtrace_linktype_t pcap_get_link_type(const struct libtrace_packet_t *packet) {
    327316        struct pcap_pkthdr *pcapptr = 0;
    328317        int linktype = 0;
    329318        pcapptr = (struct pcap_pkthdr *)packet->header;
    330         linktype = pcap_datalink(packet->trace->format_data->input.pcap);
     319        linktype = pcap_datalink(DATA(packet->trace)->input.pcap);
    331320        return pcap_dlt_to_libtrace(linktype);
    332321}
     
    430419
    431420static int pcap_get_fd(const libtrace_t *trace) {
    432         return pcap_fileno(trace->format_data->input.pcap);
     421        return pcap_fileno(DATA(trace)->input.pcap);
    433422}
    434423
     
    463452        TRACE_FORMAT_PCAP,
    464453        pcap_init_input,                /* init_input */
    465         NULL,                           /* config_input */
     454        pcap_config_input,              /* config_input */
    466455        pcap_start_input,               /* start_input */
    467456        pcap_pause_input,               /* pause_input */
    468457        pcap_init_output,               /* init_output */
    469458        NULL,                           /* config_output */
    470         NULL,                           /* start_output */
     459        pcap_start_output,              /* start_output */
    471460        pcap_fin_input,                 /* fin_input */
    472461        pcap_fin_output,                /* fin_output */
     
    499488        pcapint_start_input,            /* start_input */
    500489        pcap_pause_input,               /* pause_input */
    501         pcapint_init_output,            /* init_output */
     490        NULL,                           /* init_output */
    502491        NULL,                           /* config_output */
    503492        NULL,                           /* start_output */
    504493        pcap_fin_input,                 /* fin_input */
    505         pcapint_fin_output,             /* fin_output */
     494        NULL,                           /* fin_output */
    506495        pcap_read_packet,               /* read_packet */
    507         pcapint_write_packet,           /* write_packet */
     496        NULL,                           /* write_packet */
    508497        pcap_get_link_type,             /* get_link_type */
    509498        pcap_get_direction,             /* get_direction */
Note: See TracChangeset for help on using the changeset viewer.