* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "config.h"
+#include <config.h>
#include <stdio.h>
#include <stdlib.h> /* for exit() */
#include <errno.h>
#ifdef HAVE_LIBZ
-#include <zlib.h> /* to get the libz version number */
+#include <zlib.h> /* to get the libz version number */
#endif
#include <wsutil/cmdarg_err.h>
#include "ringbuffer.h"
#include "version_info.h"
-#include "capture-pcap-util.h"
+#include "caputils/capture_ifinfo.h"
+#include "caputils/capture-pcap-util.h"
+#include "caputils/capture-pcap-util-int.h"
#ifdef _WIN32
-#include "capture-wpcap.h"
+#include "caputils/capture-wpcap.h"
#endif /* _WIN32 */
#include "pcapio.h"
#ifdef _WIN32
-#include "capture-wpcap.h"
+#include "caputils/capture-wpcap.h"
#include <wsutil/unicode-utils.h>
#endif
#include "sync_pipe.h"
#include "capture_opts.h"
-#include "capture_session.h"
-#include <capchild/capture_ifinfo.h>
+#include <capchild/capture_session.h>
#include <capchild/capture_sync.h>
#include "conditions.h"
#include "wsutil/file_util.h"
#include "wsutil/os_version_info.h"
-#include "ws80211_utils.h"
+#include "caputils/ws80211_utils.h"
/*
* Get information about libpcap format from "wiretap/libpcap.h".
ssize_t written _U_;
static const char file[] = "/proc/sys/net/core/bpf_jit_enable";
- fd = open(file, O_WRONLY);
+ fd = ws_open(file, O_WRONLY);
if (fd < 0)
return;
}
static void
-print_usage(gboolean print_ver)
+print_usage(FILE *output)
{
- FILE *output;
-
- if (print_ver) {
- output = stdout;
- fprintf(output,
- "Dumpcap %s\n"
- "Capture network packets and dump them into a pcapng file.\n"
- "See http://www.wireshark.org for more information.\n",
- get_ws_vcs_version_info());
- } else {
- output = stderr;
- }
fprintf(output, "\nUsage: dumpcap [options] ...\n");
fprintf(output, "\n");
fprintf(output, "Capture interface:\n");
static void
show_version(GString *comp_info_str, GString *runtime_info_str)
{
- printf(
- "Dumpcap %s\n"
- "\n"
- "%s\n"
- "%s\n"
- "%s\n"
- "See http://www.wireshark.org for more information.\n",
- get_ws_vcs_version_info(), get_copyright_info(), comp_info_str->str, runtime_info_str->str);
+ printf("Dumpcap (Wireshark) %s\n"
+ "\n"
+ "%s"
+ "\n"
+ "%s"
+ "\n"
+ "%s",
+ get_ws_vcs_version_info(), get_copyright_info(), comp_info_str->str, runtime_info_str->str);
}
/*
printf("\tloopback");
else
printf("\tnetwork");
-
+#ifdef HAVE_EXTCAP
+ printf("\t%s", if_info->extcap);
+#endif
printf("\n");
}
}
if_list = get_interface_list(&err, &err_str);
if (if_list == NULL) {
- switch (err) {
- case CANT_GET_INTERFACE_LIST:
- case DONT_HAVE_PCAP:
+ if (err == 0)
+ cmdarg_err("There are no interfaces on which a capture can be done");
+ else {
cmdarg_err("%s", err_str);
g_free(err_str);
- break;
-
- case NO_INTERFACES_FOUND:
- cmdarg_err("There are no interfaces on which a capture can be done");
- break;
}
return err;
}
goto fail_invalid;
}
- strncpy(buf, sockname, len);
+ g_snprintf ( buf,(gulong)len + 1, "%s", sockname );
buf[len] = '\0';
if (inet_pton(AF_INET, buf, &sa.sin_addr) <= 0) {
goto fail_invalid;
}
sa.sin_family = AF_INET;
- sa.sin_port = htons((u_short)port);
+ sa.sin_port = g_htons((u_short)port);
if (((fd = (int)socket(AF_INET, SOCK_STREAM, 0)) < 0) ||
(connect(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0)) {
if (errorText)
LocalFree(errorText);
#else
- " %d: %s", errno, strerror(errno));
+ " %d: %s", errno, g_strerror(errno));
#endif
pcap_opts->cap_pipe_err = PIPERR;
#else /* _WIN32 */
char *pncopy, *pos;
wchar_t *err_str;
+ interface_options interface_opts;
#endif
ssize_t b;
int fd = -1, sel_ret;
size_t bytes_read;
guint32 magic = 0;
-
pcap_opts->cap_pipe_fd = -1;
#ifdef _WIN32
pcap_opts->cap_pipe_h = INVALID_HANDLE_VALUE;
return;
}
+ interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
+
/* Wait for the pipe to appear */
while (1) {
- pcap_opts->cap_pipe_h = CreateFile(utf_8to16(pipename), GENERIC_READ, 0, NULL,
- OPEN_EXISTING, 0, NULL);
+
+ if(strncmp(interface_opts.name,"\\\\.\\pipe\\",9)== 0)
+ pcap_opts->cap_pipe_h = GetStdHandle(STD_INPUT_HANDLE);
+ else
+ pcap_opts->cap_pipe_h = CreateFile(utf_8to16(pipename), GENERIC_READ, 0, NULL,
+ OPEN_EXISTING, 0, NULL);
if (pcap_opts->cap_pipe_h != INVALID_HANDLE_VALUE)
break;
if (!WaitNamedPipe(utf_8to16(pipename), 30 * 1000)) {
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, GetLastError(), 0, (LPTSTR) &err_str, 0, NULL);
+ NULL, GetLastError(), 0, (LPTSTR) &err_str, 0, NULL);
g_snprintf(errmsg, errmsgl,
"The capture session on \"%s\" timed out during "
"pipe open: %s (error %d)",
os_info_str = g_string_new("");
get_os_version_info(os_info_str);
- g_snprintf(appname, sizeof(appname), "Dumpcap %s", get_ws_vcs_version_info());
+ g_snprintf(appname, sizeof(appname), "Dumpcap (Wireshark) %s", get_ws_vcs_version_info());
successful = pcapng_write_session_header_block(ld->pdh,
(const char *)capture_opts->capture_comment, /* Comment*/
NULL, /* HW*/
os_info_str = g_string_new("");
get_os_version_info(os_info_str);
- g_snprintf(appname, sizeof(appname), "Dumpcap %s", get_ws_vcs_version_info());
+ g_snprintf(appname, sizeof(appname), "Dumpcap (Wireshark) %s", get_ws_vcs_version_info());
successful = pcapng_write_session_header_block(global_ld.pdh,
NULL, /* Comment */
NULL, /* HW */
return ret;
}
+static void
+get_dumpcap_compiled_info(GString *str)
+{
+ /* Capture libraries */
+ g_string_append(str, ", ");
+ get_compiled_caplibs_version(str);
+
+ /* LIBZ */
+ g_string_append(str, ", ");
+#ifdef HAVE_LIBZ
+ g_string_append(str, "with libz ");
+#ifdef ZLIB_VERSION
+ g_string_append(str, ZLIB_VERSION);
+#else /* ZLIB_VERSION */
+ g_string_append(str, "(version unknown)");
+#endif /* ZLIB_VERSION */
+#else /* HAVE_LIBZ */
+ g_string_append(str, "without libz");
+#endif /* HAVE_LIBZ */
+}
+
static void
get_dumpcap_runtime_info(GString *str)
{
- /* Libpcap */
+ /* Capture libraries */
g_string_append(str, ", ");
- get_runtime_pcap_version(str);
+ get_runtime_caplibs_version(str);
/* zlib */
#if defined(HAVE_LIBZ) && !defined(_WIN32)
/* Assemble the compile-time version information string */
comp_info_str = g_string_new("Compiled ");
- get_compiled_version_info(comp_info_str, NULL, NULL);
+ get_compiled_version_info(comp_info_str, NULL, get_dumpcap_compiled_info);
/* Assemble the run-time version information string */
runtime_info_str = g_string_new("Running ");
get_runtime_version_info(runtime_info_str, get_dumpcap_runtime_info);
/* Add it to the information to be reported on a crash. */
- ws_add_crash_info("Dumpcap %s\n"
+ ws_add_crash_info("Dumpcap (Wireshark) %s\n"
"\n"
"%s"
"\n"
/* Set the initial values in the capture options. This might be overwritten
by the command line parameters. */
capture_opts_init(&global_capture_opts);
-
/* We always save to a file - if no file was specified, we save to a
temporary file. */
global_capture_opts.saving_to_file = TRUE;
while ((opt = getopt_long(argc, argv, OPTSTRING, long_options, NULL)) != -1) {
switch (opt) {
case 'h': /* Print help and exit */
- print_usage(TRUE);
+ printf("Dumpcap (Wireshark) %s\n"
+ "Capture network packets and dump them into a pcapng or pcap file.\n"
+ "See http://www.wireshark.org for more information.\n",
+ get_ws_vcs_version_info());
+ print_usage(stdout);
exit_main(0);
break;
case 'v': /* Show version and exit */
pcap_queue_packet_limit = 1000;
}
if (arg_error) {
- print_usage(FALSE);
+ print_usage(stderr);
exit_main(1);
}
if_list = capture_interface_list(&err, &err_str,NULL);
if (if_list == NULL) {
- switch (err) {
- case CANT_GET_INTERFACE_LIST:
- case DONT_HAVE_PCAP:
- cmdarg_err("%s", err_str);
- g_free(err_str);
- exit_main(2);
- break;
-
- case NO_INTERFACES_FOUND:
+ if (err == 0) {
/*
* If we're being run by another program, just give them
* an empty list of interfaces, don't report this as
cmdarg_err("There are no interfaces on which a capture can be done");
exit_main(2);
}
- break;
+ } else {
+ cmdarg_err("%s", err_str);
+ g_free(err_str);
+ exit_main(2);
}
}
interface_options interface_opts;
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, ii);
+
caps = get_if_capabilities(interface_opts.name,
interface_opts.monitor_mode, &err_str);
if (caps == NULL) {
fflush(stderr);
/* Now start the capture. */
-
if (capture_loop_start(&global_capture_opts, &stats_known, &stats) == TRUE) {
/* capture ok */
exit_main(0);