Changeset 575


Ignore:
Timestamp:
02/10/06 10:52:41 (7 years ago)
Author:
perry
Message:

Split out legacy from erf
Added config_input, start_input, and start_output hooks for formats

Location:
trunk/lib
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Makefile.am

    r532 r575  
    33 
    44extra_DIST = format_template.c 
    5 libtrace_la_SOURCES = trace.c fifo.c fifo.h common.h  format_erf.c format_pcap.c format_wag.c format_helper.c format_helper.h parse_cmd.c parse_cmd.h libtrace_int.h lt_inttypes.h 
     5libtrace_la_SOURCES = trace.c fifo.c fifo.h common.h \ 
     6                format_erf.c format_pcap.c format_wag.c format_legacy.c \ 
     7                format_helper.c format_helper.h \ 
     8                parse_cmd.c parse_cmd.h libtrace_int.h lt_inttypes.h 
    69if DAG2_4 
    710nodist_libtrace_la_SOURCES = dagopts.c dagapi.c 
  • trunk/lib/format_erf.c

    r574 r575  
    7676static struct libtrace_format_t dag; 
    7777#endif  
    78 static struct libtrace_format_t legacypos; 
    79 static struct libtrace_format_t legacyeth; 
    80 static struct libtrace_format_t legacyatm; 
    8178 
    8279#define CONNINFO libtrace->format_data->conn_info 
     
    203200} 
    204201 
    205 static int legacyeth_get_framing_length(const struct libtrace_packet_t *packet UNUSED)  
    206 { 
    207         return sizeof(legacy_ether_t); 
    208 } 
    209  
    210 static int legacypos_get_framing_length(const struct libtrace_packet_t *packet UNUSED)  
    211 { 
    212         return sizeof(legacy_pos_t); 
    213 } 
    214  
    215 static int legacyatm_get_framing_length(const struct libtrace_packet_t *packet UNUSED)  
    216 { 
    217         return sizeof(legacy_cell_t); 
    218 } 
    219202 
    220203static int erf_init_input(struct libtrace_t *libtrace) { 
     
    490473#endif  
    491474 
    492 static int legacy_read_packet(struct libtrace_t *libtrace, struct libtrace_packet_t *packet) { 
    493         int numbytes; 
    494         void *buffer = packet->buffer; 
    495          
    496         if ((numbytes=LIBTRACE_READ(INPUT.file, 
    497                                         buffer, 
    498                                         64)) == -1) { 
    499                 perror("libtrace_read"); 
    500                 return -1; 
    501         } 
    502         packet->status.type = RT_DATA; 
    503         packet->status.message = 0; 
    504         packet->size = 64; 
    505          
    506         packet->header = packet->buffer; 
    507         packet->payload = packet->buffer +  
    508                 packet->trace->format->get_framing_length(packet); 
    509          
    510         return 64; 
    511          
    512 } 
    513475static int erf_read_packet(struct libtrace_t *libtrace, struct libtrace_packet_t *packet) { 
    514476        int numbytes; 
     
    758720} 
    759721 
    760 static void *legacypos_get_link(const struct libtrace_packet_t *packet) { 
    761         return (void *)packet->payload; 
    762 } 
    763  
    764 static libtrace_linktype_t legacypos_get_link_type(const struct libtrace_packet_t *packet UNUSED) { 
    765         return TRACE_TYPE_LEGACY_POS; 
    766 } 
    767  
    768 static void *legacyatm_get_link(const struct libtrace_packet_t *packet) { 
    769         return (void *)packet->payload; 
    770 } 
    771  
    772 static libtrace_linktype_t legacyatm_get_link_type(const struct libtrace_packet_t *packet UNUSED) { 
    773         return TRACE_TYPE_LEGACY_ATM; 
    774 } 
    775  
    776 static void *legacyeth_get_link(const struct libtrace_packet_t *packet) { 
    777         return (void *)packet->payload; 
    778 } 
    779  
    780 static libtrace_linktype_t legacyeth_get_link_type(const struct libtrace_packet_t *packet UNUSED) { 
    781         return TRACE_TYPE_LEGACY_ETH; 
    782 } 
    783  
    784  
    785  
    786722static void *erf_get_link(const struct libtrace_packet_t *packet) { 
    787723        return (void *)packet->payload; 
     
    821757} 
    822758 
    823 static int legacy_get_capture_length(const struct libtrace_packet_t *packet __attribute__((unused))) { 
    824         return 64; 
    825 } 
    826  
    827 static int legacypos_get_wire_length(const struct libtrace_packet_t *packet) { 
    828         legacy_pos_t *lpos = (legacy_pos_t *)packet->header; 
    829         return ntohs(lpos->wlen); 
    830 } 
    831  
    832 static int legacyatm_get_wire_length(const struct libtrace_packet_t *packet UNUSED) { 
    833         return 53; 
    834 } 
    835  
    836 static int legacyeth_get_wire_length(const struct libtrace_packet_t *packet) { 
    837         legacy_ether_t *leth = (legacy_ether_t *)packet->header; 
    838         return ntohs(leth->wlen); 
    839 } 
    840759static int erf_get_capture_length(const struct libtrace_packet_t *packet) { 
    841760        dag_record_t *erfptr = 0; 
     
    910829#endif 
    911830 
    912 static void legacypos_help() { 
    913         printf("legacypos format module: $Revision$\n"); 
    914         printf("Supported input URIs:\n"); 
    915         printf("\tlegacypos:/path/to/file\t(uncompressed)\n"); 
    916         printf("\tlegacypos:/path/to/file.gz\t(gzip-compressed)\n"); 
    917         printf("\tlegacypos:-\t(stdin, either compressed or not)\n"); 
    918         printf("\n"); 
    919         printf("\te.g.: legacypos:/tmp/trace.gz\n"); 
    920         printf("\n"); 
    921 } 
    922  
    923 static void legacyatm_help() { 
    924         printf("legacyatm format module: $Revision$\n"); 
    925         printf("Supported input URIs:\n"); 
    926         printf("\tlegacyatm:/path/to/file\t(uncompressed)\n"); 
    927         printf("\tlegacyatm:/path/to/file.gz\t(gzip-compressed)\n"); 
    928         printf("\tlegacyatm:-\t(stdin, either compressed or not)\n"); 
    929         printf("\n"); 
    930         printf("\te.g.: legacyatm:/tmp/trace.gz\n"); 
    931         printf("\n"); 
    932 } 
    933  
    934 static void legacyeth_help() { 
    935         printf("legacyeth format module: $Revision$\n"); 
    936         printf("Supported input URIs:\n"); 
    937         printf("\tlegacyeth:/path/to/file\t(uncompressed)\n"); 
    938         printf("\tlegacyeth:/path/to/file.gz\t(gzip-compressed)\n"); 
    939         printf("\tlegacyeth:-\t(stdin, either compressed or not)\n"); 
    940         printf("\n"); 
    941         printf("\te.g.: legacyeth:/tmp/trace.gz\n"); 
    942         printf("\n"); 
    943 } 
    944  
    945831static void erf_help() { 
    946832        printf("erf format module: $Revision$\n"); 
     
    987873} 
    988874 
    989 static struct libtrace_format_t legacyatm = { 
    990         "legacyatm", 
    991         "$Id$", 
    992         "legacyatm", 
    993         erf_init_input,                 /* init_input */         
    994         NULL,                           /* init_output */ 
    995         NULL,                           /* config_output */ 
    996         erf_fin_input,                  /* fin_input */ 
    997         NULL,                           /* fin_output */ 
    998         legacy_read_packet,             /* read_packet */ 
    999         NULL,                           /* write_packet */ 
    1000         legacyatm_get_link,             /* get_link */ 
    1001         legacyatm_get_link_type,        /* get_link_type */ 
    1002         NULL,                           /* get_direction */ 
    1003         NULL,                           /* set_direction */ 
    1004         erf_get_erf_timestamp,          /* get_erf_timestamp */ 
    1005         NULL,                           /* get_timeval */ 
    1006         NULL,                           /* get_seconds */ 
    1007         legacy_get_capture_length,      /* get_capture_length */ 
    1008         legacyatm_get_wire_length,      /* get_wire_length */ 
    1009         legacyatm_get_framing_length,   /* get_framing_length */ 
    1010         NULL,                           /* set_capture_length */ 
    1011         NULL,                           /* get_fd */ 
    1012         trace_event_trace,              /* trace_event */ 
    1013         legacyatm_help                  /* help */ 
    1014 }; 
    1015  
    1016 static struct libtrace_format_t legacyeth = { 
    1017         "legacyeth", 
    1018         "$Id$", 
    1019         "legacyeth", 
    1020         erf_init_input,                 /* init_input */         
    1021         NULL,                           /* init_output */ 
    1022         NULL,                           /* config_output */ 
    1023         erf_fin_input,                  /* fin_input */ 
    1024         NULL,                           /* fin_output */ 
    1025         legacy_read_packet,             /* read_packet */ 
    1026         NULL,                           /* write_packet */ 
    1027         legacyeth_get_link,             /* get_link */ 
    1028         legacyeth_get_link_type,        /* get_link_type */ 
    1029         NULL,                           /* get_direction */ 
    1030         NULL,                           /* set_direction */ 
    1031         erf_get_erf_timestamp,          /* get_erf_timestamp */ 
    1032         NULL,                           /* get_timeval */ 
    1033         NULL,                           /* get_seconds */ 
    1034         legacy_get_capture_length,      /* get_capture_length */ 
    1035         legacyeth_get_wire_length,      /* get_wire_length */ 
    1036         legacyeth_get_framing_length,   /* get_framing_length */ 
    1037         NULL,                           /* set_capture_length */ 
    1038         NULL,                           /* get_fd */ 
    1039         trace_event_trace,              /* trace_event */ 
    1040         legacyeth_help                  /* help */ 
    1041 }; 
    1042  
    1043 static struct libtrace_format_t legacypos = { 
    1044         "legacypos", 
    1045         "$Id$", 
    1046         "legacypos", 
    1047         erf_init_input,                 /* init_input */         
    1048         NULL,                           /* init_output */ 
    1049         NULL,                           /* config_output */ 
    1050         erf_fin_input,                  /* fin_input */ 
    1051         NULL,                           /* fin_output */ 
    1052         legacy_read_packet,             /* read_packet */ 
    1053         NULL,                           /* write_packet */ 
    1054         legacypos_get_link,             /* get_link */ 
    1055         legacypos_get_link_type,        /* get_link_type */ 
    1056         NULL,                           /* get_direction */ 
    1057         NULL,                           /* set_direction */ 
    1058         erf_get_erf_timestamp,          /* get_erf_timestamp */ 
    1059         NULL,                           /* get_timeval */ 
    1060         NULL,                           /* get_seconds */ 
    1061         legacy_get_capture_length,      /* get_capture_length */ 
    1062         legacypos_get_wire_length,      /* get_wire_length */ 
    1063         legacypos_get_framing_length,   /* get_framing_length */ 
    1064         NULL,                           /* set_capture_length */ 
    1065         NULL,                           /* get_fd */ 
    1066         trace_event_trace,              /* trace_event */ 
    1067         legacypos_help                  /* help */ 
    1068 }; 
    1069  
    1070          
    1071875static struct libtrace_format_t erf = { 
    1072876        "erf", 
     
    1074878        "erf", 
    1075879        erf_init_input,                 /* init_input */         
     880        NULL,                           /* config_input */ 
     881        NULL,                           /* start_input */ 
    1076882        erf_init_output,                /* init_output */ 
    1077883        erf_config_output,              /* config_output */ 
     884        NULL,                           /* start_output */ 
    1078885        erf_fin_input,                  /* fin_input */ 
    1079886        erf_fin_output,                 /* fin_output */ 
    1080887        erf_read_packet,                /* read_packet */ 
    1081888        erf_write_packet,               /* write_packet */ 
    1082         erf_get_link,                   /* get_link */ 
    1083889        erf_get_link_type,              /* get_link_type */ 
    1084890        erf_get_direction,              /* get_direction */ 
     
    1102908        "erf", 
    1103909        dag_init_input,                 /* init_input */         
     910        NULL,                           /* config_input */ 
     911        NULL,                           /* start_output */ 
    1104912        NULL,                           /* init_output */ 
    1105913        NULL,                           /* config_output */ 
     914        NULL,                           /* start_output */ 
    1106915        dag_fin_input,                  /* fin_input */ 
    1107916        NULL,                           /* fin_output */ 
    1108917        dag_read_packet,                /* read_packet */ 
    1109918        NULL,                           /* write_packet */ 
    1110         erf_get_link,                   /* get_link */ 
    1111919        erf_get_link_type,              /* get_link_type */ 
    1112920        erf_get_direction,              /* get_direction */ 
     
    1130938        "erf", 
    1131939        rtclient_init_input,            /* init_input */         
     940        NULL,                           /* config_input */ 
     941        NULL,                           /* start_input */ 
    1132942        NULL,                           /* init_output */ 
    1133943        NULL,                           /* config_output */ 
     944        NULL,                           /* start_output */ 
    1134945        rtclient_fin_input,             /* fin_input */ 
    1135946        NULL,                           /* fin_output */ 
    1136947        rtclient_read_packet,           /* read_packet */ 
    1137948        NULL,                           /* write_packet */ 
    1138         erf_get_link,                   /* get_link */ 
    1139949        erf_get_link_type,              /* get_link_type */ 
    1140950        erf_get_direction,              /* get_direction */ 
     
    1157967        register_format(&dag); 
    1158968#endif 
    1159         register_format(&rtclient); 
    1160         register_format(&legacypos); 
    1161         register_format(&legacyeth); 
    1162         register_format(&legacyatm); 
    1163 } 
     969} 
  • trunk/lib/format_pcap.c

    r532 r575  
    425425        "pcap", 
    426426        pcap_init_input,                /* init_input */ 
     427        NULL,                           /* config_input */ 
     428        NULL,                           /* start_input */ 
    427429        pcap_init_output,               /* init_output */ 
    428430        NULL,                           /* config_output */ 
     431        NULL,                           /* start_output */ 
    429432        pcap_fin_input,                 /* fin_input */ 
    430433        pcap_fin_output,                /* fin_output */ 
    431434        pcap_read_packet,               /* read_packet */ 
    432435        pcap_write_packet,              /* write_packet */ 
    433         pcap_get_link,                  /* get_link */ 
    434436        pcap_get_link_type,             /* get_link_type */ 
    435437        pcap_get_direction,             /* get_direction */ 
     
    452454        "pcap", 
    453455        pcapint_init_input,             /* init_input */ 
     456        NULL,                           /* config_input */ 
     457        NULL,                           /* start_input */ 
    454458        pcapint_init_output,            /* init_output */ 
    455459        NULL,                           /* config_output */ 
     460        NULL,                           /* start_output */ 
    456461        pcap_fin_input,                 /* fin_input */ 
    457462        pcapint_fin_output,             /* fin_output */ 
    458463        pcap_read_packet,               /* read_packet */ 
    459464        pcapint_write_packet,           /* write_packet */ 
    460         pcap_get_link,                  /* get_link */ 
    461465        pcap_get_link_type,             /* get_link_type */ 
    462466        pcap_get_direction,             /* get_direction */ 
  • trunk/lib/format_wag.c

    r539 r575  
    495495        "wtf", 
    496496        wag_init_input,                 /* init_input */         
     497        NULL,                           /* config_input */ 
     498        NULL,                           /* start_input */ 
    497499        NULL,                           /* init_output */ 
    498500        NULL,                           /* config_output */ 
     501        NULL,                           /* start_output */ 
    499502        wag_fin_input,                  /* fin_input */ 
    500503        NULL,                           /* fin_output */ 
    501504        wag_read_packet,                /* read_packet */ 
    502505        NULL,                           /* write_packet */ 
    503         wag_get_link,                   /* get_link */ 
    504506        wag_get_link_type,              /* get_link_type */ 
    505507        wag_get_direction,              /* get_direction */ 
     
    524526        "wtf", 
    525527        wtf_init_input,                 /* init_input */ 
     528        NULL,                           /* config input */ 
     529        NULL,                           /* start input */ 
    526530        wtf_init_output,                /* init_output */ 
    527531        wtf_config_output,              /* config_output */ 
     532        NULL,                           /* start output */ 
    528533        wtf_fin_input,                  /* fin_input */ 
    529534        wtf_fin_output,                 /* fin_output */ 
    530535        wtf_read_packet,                /* read_packet */ 
    531536        wtf_write_packet,               /* write_packet */ 
    532         wag_get_link,                   /* get_link */ 
    533537        wag_get_link_type,              /* get_link_type */ 
    534538        wag_get_direction,              /* get_direction */ 
  • trunk/lib/libtrace_int.h

    r506 r575  
    7171#endif 
    7272 
     73#include <stdbool.h> 
     74 
    7375typedef enum {SOCKET, TRACE, STDIN, DEVICE, INTERFACE, RT } source_t; 
    7476 
     
    100102        struct libtrace_format_data_t *format_data; /**<format data pointer */ 
    101103        source_t sourcetype;    /**< The type (device,file, etc */ 
     104        bool started; 
    102105 
    103106        struct libtrace_event_t event; 
     
    150153        char *type; 
    151154        int (*init_input)(struct libtrace_t *libtrace); 
     155        int (*config_input)(struct libtrace_t *libtrace,char *option,void *value); 
     156        int (*start_input)(struct libtrace_t *libtrace); 
    152157        int (*init_output)(struct libtrace_out_t *libtrace); 
    153158        int (*config_output)(struct libtrace_out_t *libtrace, int argc, char *argv[]); 
     159        int (*start_output)(struct libtrace_out_t *libtrace); 
    154160        int (*fin_input)(struct libtrace_t *libtrace); 
    155161        int (*fin_output)(struct libtrace_out_t *libtrace); 
    156162        int (*read_packet)(struct libtrace_t *libtrace, struct libtrace_packet_t *packet); 
    157163        int (*write_packet)(struct libtrace_out_t *libtrace, const struct libtrace_packet_t *packet); 
    158         void* (*get_link)(const struct libtrace_packet_t *packet); 
    159164        libtrace_linktype_t (*get_link_type)(const struct libtrace_packet_t *packet); 
    160165        int8_t (*get_direction)(const struct libtrace_packet_t *packet); 
  • trunk/lib/trace.c

    r570 r575  
    154154 
    155155void register_format(struct libtrace_format_t *f) { 
    156 //      fprintf(stderr,"Registering input format %s\n",f->name); 
    157156        if (format_list == 0) { 
    158157                format_size = 10; 
     
    311310        assert( libtrace->fifo); 
    312311        free(scan); 
     312        libtrace->started=false; 
    313313        return libtrace; 
    314314} 
     
    430430} 
    431431 
     432/* Start a trace 
     433 * @param libtrace      the input trace to start 
     434 * @returns 0 on success 
     435 * 
     436 * This does the work associated with actually starting up 
     437 * the trace.  it may fail. 
     438 */ 
     439int trace_start(struct libtrace_t *libtrace) 
     440{ 
     441        if (libtrace->format->start_input) { 
     442                int ret=libtrace->format->start_input(libtrace); 
     443                if (!ret) { 
     444                        return ret; 
     445                } 
     446        } 
     447 
     448        libtrace->started=true; 
     449        return 0; 
     450} 
     451 
    432452/* Parses an output options string and calls the appropriate function to deal with output options. 
    433453 * 
     
    520540int trace_read_packet(struct libtrace_t *libtrace, struct libtrace_packet_t *packet) { 
    521541 
    522         if (!libtrace) { 
    523                 fprintf(stderr,"You called trace_read_packet() with a NULL libtrace parameter!\n"); 
    524         } 
    525         assert(libtrace); 
    526         assert(packet); 
     542        assert(libtrace && "You called trace_read_packet() with a NULL libtrace parameter!\n"); 
     543        assert(libtrace->started && "BUG: You must call libtrace_start() before trace_read_packet()\n"); 
     544        assert(packet); 
    527545       
    528546        /* Store the trace we are reading from into the packet opaque  
Note: See TracChangeset for help on using the changeset viewer.