Changeset 1349

Show
Ignore:
Timestamp:
05/05/08 10:13:17 (8 months ago)
Author:
perry
Message:

* Create a .gz extension only if we're compressing files
* Add extensions if we build up the uri ourselves

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tools/tracesplit/tracesplit.c

    r1310 r1349  
    4040        "-S --snaplen           Snap packets at the specified length\n" 
    4141        "-v --verbose           Output statistics\n" 
     42        "-z --compress          Set compression level\n" 
    4243        ,argv0); 
    4344        exit(1); 
     
    7273        uint16_t snaplen = 0; 
    7374        int verbose=0; 
     75        int compress_level=-1; 
    7476         
    7577        if (argc<2) { 
     
    9294                        { "snaplen",       1, 0, 'S' }, 
    9395                        { "verbose",       0, 0, 'v' }, 
     96                        { "compress",      1, 0, 'z' }, 
    9497                        { NULL,            0, 0, 0   }, 
    9598                }; 
    9699 
    97                 int c=getopt_long(argc, argv, "f:c:b:s:e:i:m:S:Hv", 
     100                int c=getopt_long(argc, argv, "f:c:b:s:e:i:m:S:Hvz:", 
    98101                                long_options, &option_index); 
    99102 
     
    124127                        case 'v': 
    125128                                  verbose++; 
     129                                  break; 
     130                        case 'z': 
     131                                  compress_level=atoi(optarg); 
     132                                  if (compress_level<0 || compress_level>9) { 
     133                                        usage(argv[0]); 
     134                                        exit(1); 
     135                                  } 
    126136                                  break; 
    127137                        default: 
     
    204214                if (!output) { 
    205215                        char *buffer; 
     216                        bool need_ext=false; 
    206217                        if (maxfiles <= filescreated) { 
    207218                                break; 
     
    211222                                buffer=strdupcat(buffer,"-"); 
    212223                                buffer=strdupcati(buffer,(uint64_t)firsttime); 
     224                                need_ext=true; 
    213225                        } 
    214226                        if (count!=UINT64_MAX && maxfiles>1) { 
    215227                                buffer=strdupcat(buffer,"-"); 
    216228                                buffer=strdupcati(buffer,(uint64_t)pktcount); 
     229                                need_ext=true; 
    217230                        } 
    218231                        if (bytes!=UINT64_MAX && maxfiles>1) { 
     
    220233                                buffer=strdupcat(buffer,"-"); 
    221234                                buffer=strdupcati(buffer,(uint64_t)++filenum); 
     235                                need_ext=true; 
     236                        } 
     237                        if (need_ext) { 
     238                                if (compress_level!=0) 
     239                                        buffer=strdupcat(buffer,".gz"); 
    222240                        } 
    223241                        output=trace_create_output(buffer); 
     
    227245                                break; 
    228246                        } 
     247                        if (compress_level!=-1) { 
     248                                if (trace_config_output(output, 
     249                                        TRACE_OPTION_OUTPUT_COMPRESS, 
     250                                        &compress_level)==-1) { 
     251                                        trace_perror_output(output,"Unable to set compression"); 
     252                                } 
     253                        } 
    229254                        trace_start_output(output); 
    230255                        if (trace_is_err_output(output)) { 
     
    232257                                free(buffer); 
    233258                                break; 
     259                        } 
     260                        if (verbose) { 
     261                                fprintf(stderr,"%s\n",buffer); 
    234262                        } 
    235263                        free(buffer);