#include <unistd.h>
#endif
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#endif
+
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#include "conditions.h"
#include "capture_stop_conditions.h"
-#include "tempfile.h"
+#include "wsutil/tempfile.h"
#include "log.h"
#include "wsutil/file_util.h"
STATE_EXPECT_DATA,
STATE_READ_DATA
} cap_pipe_state_t;
-typedef enum {
- PIPOK,
- PIPEOF,
- PIPERR,
- PIPNEXIST
+
+typedef enum {
+ PIPOK,
+ PIPEOF,
+ PIPERR,
+ PIPNEXIST
} cap_pipe_err_t;
+
typedef struct _pcap_options {
guint32 received;
guint32 dropped;
*/
static const char please_report[] =
"Please report this to the Wireshark developers.\n"
+ "http://bugs.wireshark.org/\n"
"(This is not a crash; please do not report it as such.)";
/*
fprintf(output, " files:NUM - ringbuffer: replace after NUM files\n");
fprintf(output, " -n use pcapng format instead of pcap (default)\n");
fprintf(output, " -P use libpcap format instead of pcapng\n");
+ fprintf(output, " --capture-comment <comment>\n");
+ fprintf(output, " add a capture comment to the output file\n");
+ fprintf(output, " (only for pcapng)\n");
fprintf(output, "\n");
fprintf(output, "Miscellaneous:\n");
fprintf(output, " -N <packet_limit> maximum number of packets buffered within dumpcap\n");
- fprintf(output, " -C <byte_limit> maximum number of bytes used for buffering packets within dumpcap\n");
+ fprintf(output, " -C <byte_limit> maximum number of bytes used for buffering packets\n");
+ fprintf(output, " within dumpcap\n");
fprintf(output, " -t use a separate thread per interface\n");
fprintf(output, " -q don't report packet capture counts\n");
fprintf(output, " -v print version information and exit\n");
* just call get_interface_list().
*/
GList *
-capture_interface_list(int *err, char **err_str)
+capture_interface_list(int *err, char **err_str, void(*update_cb)(void) _U_)
{
return get_interface_list(err, err_str);
}
strncpy(buf, sockname, len);
buf[len] = '\0';
- if (!inet_pton(AF_INET, buf, &sa.sin_addr)) {
+ if (inet_pton(AF_INET, buf, &sa.sin_addr) <= 0) {
goto fail_invalid;
}
g_snprintf(appname, sizeof(appname), "Dumpcap " VERSION "%s", wireshark_svnversion);
successful = libpcap_write_session_header_block(libpcap_write_to_file, ld->pdh,
- NULL, /* Comment*/
+ (const char *)capture_opts->capture_comment, /* Comment*/
NULL, /* HW*/
os_info_str->str, /* OS*/
appname,
if (global_capture_opts.use_pcapng) {
successful = libpcap_write_enhanced_packet_block(libpcap_write_to_file, global_ld.pdh,
NULL,
- phdr->ts.tv_sec, phdr->ts.tv_usec,
+ phdr->ts.tv_sec, (gint32)phdr->ts.tv_usec,
phdr->caplen, phdr->len,
pcap_opts->interface_id,
ts_mul,
&global_ld.bytes_written, &err);
} else {
successful = libpcap_write_packet(libpcap_write_to_file, global_ld.pdh,
- phdr->ts.tv_sec, phdr->ts.tv_usec,
+ phdr->ts.tv_sec, (gint32)phdr->ts.tv_usec,
phdr->caplen, phdr->len,
pd,
&global_ld.bytes_written, &err);
GString *comp_info_str;
GString *runtime_info_str;
int opt;
+ struct option long_options[] = {
+ {(char *)"capture-comment", required_argument, NULL, LONGOPT_NUM_CAP_COMMENT },
+ {0, 0, 0, 0 }
+ };
+
gboolean arg_error = FALSE;
#ifdef _WIN32
global_capture_opts.saving_to_file = TRUE;
global_capture_opts.has_ring_num_files = TRUE;
+ /* Pass on capture_child mode for capture_opts */
+ global_capture_opts.capture_child = capture_child;
+
/* Now get our args */
- while ((opt = getopt(argc, argv, OPTSTRING)) != -1) {
+ while ((opt = getopt_long(argc, argv, OPTSTRING, long_options, NULL)) != -1) {
switch (opt) {
case 'h': /* Print help and exit */
print_usage(TRUE);
case 's': /* Set the snapshot (capture) length */
case 'w': /* Write to capture file x */
case 'y': /* Set the pcap data link type */
+ case LONGOPT_NUM_CAP_COMMENT: /* add a capture comment */
#ifdef HAVE_PCAP_REMOTE
case 'u': /* Use UDP for data transfer */
case 'r': /* Capture own RPCAP traffic too */
}
} else {
/* We're supposed to capture traffic; */
+
/* Are we capturing on multiple interface? If so, use threads and pcapng. */
if (global_capture_opts.ifaces->len > 1) {
use_threads = TRUE;
global_capture_opts.use_pcapng = TRUE;
}
+
+ if (global_capture_opts.capture_comment &&
+ (!global_capture_opts.use_pcapng || global_capture_opts.multi_files_on)) {
+ /* XXX - for ringbuffer, should we apply the comment to each file? */
+ cmdarg_err("A capture comment can only be set if we capture into a single pcapng file.");
+ exit_main(1);
+ }
+
/* Was the ring buffer option specified and, if so, does it make sense? */
if (global_capture_opts.multi_files_on) {
/* Ring buffer works only under certain conditions:
int err;
gchar *err_str;
- if_list = capture_interface_list(&err, &err_str);
+ if_list = capture_interface_list(&err, &err_str,NULL);
if (if_list == NULL) {
switch (err) {
case CANT_GET_INTERFACE_LIST:
}
#endif
+
+
+
+
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*