diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:14:33 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:14:33 +0000 |
commit | 9f153fbfec0fb9c9ce38e749a7c6f4a5e115d4e9 (patch) | |
tree | 2784370cda9bbf2da9114d70f05399c0b229d28c /rawshark.c | |
parent | Adding debian version 4.2.6-1. (diff) | |
download | wireshark-9f153fbfec0fb9c9ce38e749a7c6f4a5e115d4e9.tar.xz wireshark-9f153fbfec0fb9c9ce38e749a7c6f4a5e115d4e9.zip |
Merging upstream version 4.4.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'rawshark.c')
-rw-r--r-- | rawshark.c | 201 |
1 files changed, 90 insertions, 111 deletions
@@ -55,6 +55,7 @@ #ifdef _WIN32 #include <wsutil/unicode-utils.h> +#include <wsutil/win32-utils.h> #endif #include "globals.h" @@ -101,7 +102,7 @@ * This is the template for the decode as option; it is shared between the * various functions that output the usage for this parameter. */ -static const gchar decode_as_arg_template[] = "<layer_type>==<selector>,<decode_as_protocol>"; +static const char decode_as_arg_template[] = "<layer_type>==<selector>,<decode_as_protocol>"; #endif /* Additional exit codes */ @@ -110,7 +111,7 @@ static const gchar decode_as_arg_template[] = "<layer_type>==<selector>,<decode_ capture_file cfile; -static guint32 cum_bytes; +static uint32_t cum_bytes; static frame_data ref_frame; static frame_data prev_dis_frame; static frame_data prev_cap_frame; @@ -124,21 +125,21 @@ typedef enum { /* Add CSV and the like here */ } output_action_e; -static gboolean line_buffered; +static bool line_buffered; static print_format_e print_format = PR_FMT_TEXT; -static gboolean want_pcap_pkthdr; +static bool want_pcap_pkthdr; cf_status_t raw_cf_open(capture_file *cf, const char *fname); -static gboolean load_cap_file(capture_file *cf); -static gboolean process_packet(capture_file *cf, epan_dissect_t *edt, gint64 offset, +static bool load_cap_file(capture_file *cf); +static bool process_packet(capture_file *cf, epan_dissect_t *edt, int64_t offset, wtap_rec *rec, Buffer *buf); static void show_print_file_io_error(int err); static void rawshark_cmdarg_err(const char *fmt, va_list ap); static void rawshark_cmdarg_err_cont(const char *fmt, va_list ap); static void protocolinfo_init(char *field); -static gboolean parse_field_string_format(char *format); +static bool parse_field_string_format(char *format); typedef enum { SF_NONE, /* No format (placeholder) */ @@ -148,7 +149,7 @@ typedef enum { } string_fmt_e; typedef struct string_fmt_s { - gchar *plain; + char *plain; string_fmt_e format; /* Valid if plain is NULL */ } string_fmt_t; @@ -169,7 +170,8 @@ print_usage(FILE *output) fprintf(output, "\n"); fprintf(output, "Input file:\n"); - fprintf(output, " -r <infile> set the pipe or file name to read from\n"); + fprintf(output, " -r <infile>, --read-file <infile>\n"); + fprintf(output," set the pipe or file name to read from\n"); fprintf(output, "\n"); fprintf(output, "Processing:\n"); @@ -184,8 +186,11 @@ print_usage(FILE *output) fprintf(output, " -N <name resolve flags> enable specific name resolution(s): \"mnNtdv\"\n"); fprintf(output, " -p use the system's packet header format\n"); fprintf(output, " (which may have 64-bit timestamps)\n"); - fprintf(output, " -R <read filter> packet filter in Wireshark display filter syntax\n"); + fprintf(output, " -R <read filter>, --read-filter <read filter>\n"); + fprintf(output, " packet filter in Wireshark display filter syntax\n"); fprintf(output, " -s skip PCAP header on input\n"); + fprintf(output, " -Y <display filter>, --display-filter <display filter>\n"); + fprintf(output, " packet filter in Wireshark display filter syntax\n"); fprintf(output, " --enable-protocol <proto_name>\n"); fprintf(output, " enable dissection of proto_name\n"); fprintf(output, " --disable-protocol <proto_name>\n"); @@ -234,7 +239,6 @@ raw_pipe_open(const char *pipe_name) #ifndef _WIN32 ws_statb64 pipe_stat; #else - char *pncopy, *pos = NULL; DWORD err; wchar_t *err_str; HANDLE hPipe = NULL; @@ -282,20 +286,7 @@ raw_pipe_open(const char *pipe_name) return -1; } #else /* _WIN32 */ -#define PIPE_STR "\\pipe\\" - /* Under Windows, named pipes _must_ have the form - * "\\<server>\pipe\<pipe_name>". <server> may be "." for localhost. - */ - pncopy = g_strdup(pipe_name); - if (strstr(pncopy, "\\\\") == pncopy) { - pos = strchr(pncopy + 3, '\\'); - if (pos && g_ascii_strncasecmp(pos, PIPE_STR, strlen(PIPE_STR)) != 0) - pos = NULL; - } - - g_free(pncopy); - - if (!pos) { + if (!win32_is_pipe_name(pipe_name)) { fprintf(stderr, "rawshark: \"%s\" is neither an interface nor a pipe\n", pipe_name); return -1; @@ -349,7 +340,7 @@ raw_pipe_open(const char *pipe_name) * a LINKTYPE_ value supported by Wiretap. "Proto name" must be * a protocol name, e.g. "http". */ -static gboolean +static bool set_link_type(const char *lt_arg) { char *spec_ptr = strchr(lt_arg, ':'); char *p; @@ -360,7 +351,7 @@ set_link_type(const char *lt_arg) { char *errmsg = NULL; if (!spec_ptr) - return FALSE; + return false; spec_ptr++; @@ -370,7 +361,7 @@ set_link_type(const char *lt_arg) { errno = 0; val = strtol(spec_ptr, &p, 10); if (p == spec_ptr || *p != '\0' || errno != 0 || val > INT_MAX) { - return FALSE; + return false; } dlt_val = (int)val; } @@ -386,9 +377,9 @@ set_link_type(const char *lt_arg) { */ encap = wtap_pcap_encap_to_wtap_encap(dlt_val); if (encap == WTAP_ENCAP_UNKNOWN) { - return FALSE; + return false; } - return TRUE; + return true; } else if (strncmp(lt_arg, "proto:", strlen("proto:")) == 0) { dhandle = find_dissector(spec_ptr); if (dhandle) { @@ -401,13 +392,13 @@ set_link_type(const char *lt_arg) { if (prefs_set_pref(pref_str->str, &errmsg) != PREFS_SET_OK) { g_string_free(pref_str, TRUE); g_free(errmsg); - return FALSE; + return false; } g_string_free(pref_str, TRUE); - return TRUE; + return true; } } - return FALSE; + return false; } int @@ -421,21 +412,22 @@ main(int argc, char *argv[]) struct rlimit limit; #endif /* !_WIN32 */ - gchar *pipe_name = NULL; - gchar *rfilters[64]; + char *pipe_name = NULL; + char *rfilters[64]; e_prefs *prefs_p; GPtrArray *disp_fields = g_ptr_array_new(); - guint fc; - gboolean skip_pcap_header = FALSE; + unsigned fc; + bool skip_pcap_header = false; int ret = EXIT_SUCCESS; static const struct ws_option long_options[] = { {"help", ws_no_argument, NULL, 'h'}, {"version", ws_no_argument, NULL, 'v'}, LONGOPT_DISSECT_COMMON + LONGOPT_READ_CAPTURE_COMMON {0, 0, 0, 0 } }; -#define OPTSTRING_INIT OPTSTRING_DISSECT_COMMON "F:hlm:o:pr:R:sS:v" +#define OPTSTRING_INIT OPTSTRING_DISSECT_COMMON OPTSTRING_READ_CAPTURE_COMMON "F:hlm:o:psS:v" static const char optstring[] = OPTSTRING_INIT; static const struct report_message_routines rawshark_report_routines = { @@ -524,13 +516,13 @@ main(int argc, char *argv[]) * file-type-dependent blocks can register using the file * type/subtype value for the file type. */ - wtap_init(FALSE); + wtap_init(false); /* Register all dissectors; we must do this before checking for the "-G" flag, as the "-G" flag dumps information registered by the dissectors, and we must do it before we read the preferences, in case any dissectors register preferences. */ - if (!epan_init(NULL, NULL, TRUE)) { + if (!epan_init(NULL, NULL, true)) { ret = WS_EXIT_INIT_FAILED; goto clean_exit; } @@ -587,7 +579,7 @@ main(int argc, char *argv[]) make the standard output line-buffered (short version: in Windows, "line-buffered" is the same as "fully-buffered", and the output buffer is only flushed when it fills up). */ - line_buffered = TRUE; + line_buffered = true; break; #if !defined(_WIN32) && defined(RLIMIT_AS) case 'm': @@ -634,13 +626,15 @@ main(int argc, char *argv[]) break; } case 'p': /* Expect pcap_pkthdr packet headers, which may have 64-bit timestamps */ - want_pcap_pkthdr = TRUE; + want_pcap_pkthdr = true; break; case 'r': /* Read capture file xxx */ pipe_name = g_strdup(ws_optarg); break; case 'R': /* Read file filter */ - if(n_rfilters < (int) sizeof(rfilters) / (int) sizeof(rfilters[0])) { + case 'Y': /* Read file filter */ + /* Read and display filters are the same for rawshark */ + if(n_rfilters < (int)array_length(rfilters)) { rfilters[n_rfilters++] = ws_optarg; } else { @@ -650,7 +644,7 @@ main(int argc, char *argv[]) } break; case 's': /* Skip PCAP header */ - skip_pcap_header = TRUE; + skip_pcap_header = true; break; case 'S': /* Print string representations */ if (!parse_field_string_format(ws_optarg)) { @@ -755,7 +749,7 @@ main(int argc, char *argv[]) } /* Build the column format array */ - build_column_format_array(&cfile.cinfo, prefs_p->num_cols, TRUE); + build_column_format_array(&cfile.cinfo, prefs_p->num_cols, true); if (n_rfilters != 0) { for (i = 0; i < n_rfilters; i++) { @@ -788,8 +782,8 @@ main(int argc, char *argv[]) /* Do we need to PCAP header and magic? */ if (skip_pcap_header) { - unsigned int bytes_left = (unsigned int) sizeof(struct pcap_hdr) + sizeof(guint32); - gchar buf[sizeof(struct pcap_hdr) + sizeof(guint32)]; + unsigned int bytes_left = (unsigned int) sizeof(struct pcap_hdr) + sizeof(uint32_t); + char buf[sizeof(struct pcap_hdr) + sizeof(uint32_t)]; while (bytes_left != 0) { ssize_t bytes = ws_read(fd, buf, bytes_left); if (bytes <= 0) { @@ -829,21 +823,21 @@ clean_exit: * @param err [OUT] Error indicator. Uses wiretap values. * @param err_info [OUT] Error message. * @param data_offset [OUT] data offset in the pipe. - * @return TRUE on success, FALSE on failure. + * @return true on success, false on failure. */ -static gboolean -raw_pipe_read(wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, gint64 *data_offset) { +static bool +raw_pipe_read(wtap_rec *rec, Buffer *buf, int *err, char **err_info, int64_t *data_offset) { struct pcap_pkthdr mem_hdr; struct pcaprec_hdr disk_hdr; ssize_t bytes_read = 0; unsigned int bytes_needed = (unsigned int) sizeof(disk_hdr); - guchar *ptr = (guchar*) &disk_hdr; + unsigned char *ptr = (unsigned char*) &disk_hdr; *err = 0; if (want_pcap_pkthdr) { bytes_needed = sizeof(mem_hdr); - ptr = (guchar*) &mem_hdr; + ptr = (unsigned char*) &mem_hdr; } /* @@ -859,7 +853,7 @@ raw_pipe_read(wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, gint64 *da if (fd == 0 && GetHandleInformation(GetStdHandle(STD_INPUT_HANDLE), &ghi_flags) == 0) { *err = 0; *err_info = NULL; - return FALSE; + return false; } #endif @@ -869,11 +863,11 @@ raw_pipe_read(wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, gint64 *da if (bytes_read == 0) { *err = 0; *err_info = NULL; - return FALSE; + return false; } else if (bytes_read < 0) { *err = errno; *err_info = NULL; - return FALSE; + return false; } bytes_needed -= (unsigned int)bytes_read; *data_offset += bytes_read; @@ -884,7 +878,7 @@ raw_pipe_read(wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, gint64 *da rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; if (want_pcap_pkthdr) { rec->ts.secs = mem_hdr.ts.tv_sec; - rec->ts.nsecs = (gint32)mem_hdr.ts.tv_usec * 1000; + rec->ts.nsecs = (int32_t)mem_hdr.ts.tv_usec * 1000; rec->rec_header.packet_header.caplen = mem_hdr.caplen; rec->rec_header.packet_header.len = mem_hdr.len; } else { @@ -908,7 +902,7 @@ raw_pipe_read(wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, gint64 *da *err = WTAP_ERR_BAD_FILE; *err_info = ws_strdup_printf("Bad packet length: %lu", (unsigned long) bytes_needed); - return FALSE; + return false; } ws_buffer_assure_space(buf, bytes_needed); @@ -918,25 +912,25 @@ raw_pipe_read(wtap_rec *rec, Buffer *buf, int *err, gchar **err_info, gint64 *da if (bytes_read == 0) { *err = WTAP_ERR_SHORT_READ; *err_info = NULL; - return FALSE; + return false; } else if (bytes_read < 0) { *err = errno; *err_info = NULL; - return FALSE; + return false; } bytes_needed -= (unsigned int)bytes_read; *data_offset += bytes_read; ptr += bytes_read; } - return TRUE; + return true; } -static gboolean +static bool load_cap_file(capture_file *cf) { int err; - gchar *err_info = NULL; - gint64 data_offset = 0; + char *err_info = NULL; + int64_t data_offset = 0; wtap_rec rec; Buffer buf; @@ -945,7 +939,7 @@ load_cap_file(capture_file *cf) wtap_rec_init(&rec); ws_buffer_init(&buf, 1514); - epan_dissect_init(&edt, cf->epan, TRUE, FALSE); + epan_dissect_init(&edt, cf->epan, true, false); while (raw_pipe_read(&rec, &buf, &err, &err_info, &data_offset)) { process_packet(cf, &edt, data_offset, &rec, &buf); @@ -958,18 +952,18 @@ load_cap_file(capture_file *cf) if (err != 0) { /* Print a message noting that the read failed somewhere along the line. */ cfile_read_failure_message(cf->filename, err, err_info); - return FALSE; + return false; } - return TRUE; + return true; } -static gboolean -process_packet(capture_file *cf, epan_dissect_t *edt, gint64 offset, +static bool +process_packet(capture_file *cf, epan_dissect_t *edt, int64_t offset, wtap_rec *rec, Buffer *buf) { frame_data fdata; - gboolean passed; + bool passed; int i; if(rec->rec_header.packet_header.len == 0) @@ -978,11 +972,11 @@ process_packet(capture_file *cf, epan_dissect_t *edt, gint64 offset, packets to process. We spit out a line with the timestamp and the text "void" */ printf("%lu %" PRIu64 " %d void -\n", (unsigned long int)cf->count, - (guint64)rec->ts.secs, rec->ts.nsecs); + (uint64_t)rec->ts.secs, rec->ts.nsecs); fflush(stdout); - return FALSE; + return false; } /* Count this packet. */ @@ -993,7 +987,7 @@ process_packet(capture_file *cf, epan_dissect_t *edt, gint64 offset, do a dissection and do so. */ frame_data_init(&fdata, cf->count, rec, offset, cum_bytes); - passed = TRUE; + passed = true; /* If we're running a read filter, prime the epan_dissect_t with that filter. */ @@ -1032,7 +1026,7 @@ process_packet(capture_file *cf, epan_dissect_t *edt, gint64 offset, if (rfcodes[i]) passed = dfilter_apply_edt(rfcodes[i], edt); else - passed = TRUE; + passed = true; /* Print a one-line summary */ printf(" %d", passed ? 1 : 0); @@ -1119,19 +1113,19 @@ static void field_display_to_string(header_field_info *hfi, char* buf, int size) */ #define FIELD_STR_INIT_LEN 256 #define cVALS(x) (const value_string*)(x) -static gboolean print_field_value(field_info *finfo, int cmd_line_index) +static bool print_field_value(field_info *finfo, int cmd_line_index) { - header_field_info *hfinfo; + const header_field_info *hfinfo; char *fs_buf; char *fs_ptr = NULL; static GString *label_s = NULL; size_t fs_len; - guint i; + unsigned i; string_fmt_t *sf; - guint32 uvalue; - gint32 svalue; - guint64 uvalue64; - gint64 svalue64; + uint32_t uvalue; + int32_t svalue; + uint64_t uvalue64; + int64_t svalue64; hfinfo = finfo->hfinfo; @@ -1235,14 +1229,14 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index) } printf(" %d=\"%s\"", cmd_line_index, label_s->str); wmem_free(NULL, fs_buf); - return TRUE; + return true; } if(fs_buf) { printf(" %d=\"%s\"", cmd_line_index, fs_ptr); wmem_free(NULL, fs_buf); - return TRUE; + return true; } /* @@ -1251,7 +1245,7 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index) * We return n.a. */ printf(" %d=\"n.a.\"", cmd_line_index); - return TRUE; + return true; } static tap_packet_status @@ -1259,7 +1253,7 @@ protocolinfo_packet(void *prs, packet_info *pinfo _U_, epan_dissect_t *edt, cons { pci_t *rs=(pci_t *)prs; GPtrArray *gp; - guint i; + unsigned i; gp=proto_get_finfo_ptr_array(edt->tree, rs->hf_index); if(!gp){ @@ -1277,7 +1271,7 @@ protocolinfo_packet(void *prs, packet_info *pinfo _U_, epan_dissect_t *edt, cons return TAP_PACKET_DONT_REDRAW; } -int g_cmd_line_index = 0; +int g_cmd_line_index; /* * field must be persistent - we don't g_strdup() it below @@ -1328,7 +1322,7 @@ protocolinfo_init(char *field) */ static void -add_string_fmt(string_fmt_e format, gchar *plain) { +add_string_fmt(string_fmt_e format, char *plain) { string_fmt_t *sf = g_new(string_fmt_t, 1); sf->format = format; @@ -1337,13 +1331,13 @@ add_string_fmt(string_fmt_e format, gchar *plain) { g_ptr_array_add(string_fmts, sf); } -static gboolean -parse_field_string_format(gchar *format) { +static bool +parse_field_string_format(char *format) { size_t len; size_t pos = 0; if (!format) { - return FALSE; + return false; } GString *plain_s = g_string_new(""); @@ -1354,7 +1348,7 @@ parse_field_string_format(gchar *format) { while (pos < len) { if (format[pos] == '%') { if (pos >= (len-1)) { /* There should always be a following specifier character */ - return FALSE; + return false; } pos++; if (plain_s->len > 0) { @@ -1375,7 +1369,7 @@ parse_field_string_format(gchar *format) { g_string_append_c(plain_s, '%'); break; default: /* Invalid format */ - return FALSE; + return false; } } else { g_string_append_c(plain_s, format[pos]); @@ -1388,7 +1382,7 @@ parse_field_string_format(gchar *format) { } g_string_free(plain_s, TRUE); - return TRUE; + return true; } /**************************************************************************************** * END OF FIELD EXTRACTION ROUTINES @@ -1418,26 +1412,11 @@ show_print_file_io_error(int err) } } -static const nstime_t * -raw_get_frame_ts(struct packet_provider_data *prov, guint32 frame_num) -{ - const frame_data *ts_fd = NULL; - if (prov->ref && prov->ref->num == frame_num) { - ts_fd = prov->ref; - } else if (prov->prev_dis && prov->prev_dis->num == frame_num) { - ts_fd = prov->prev_dis; - } else if (prov->prev_cap && prov->prev_cap->num == frame_num) { - ts_fd = prov->prev_cap; - } - - return (ts_fd && ts_fd->has_ts) ? &ts_fd->abs_ts : NULL; -} - static epan_t * raw_epan_new(capture_file *cf) { static const struct packet_provider_funcs funcs = { - raw_get_frame_ts, + cap_file_provider_get_frame_ts, cap_file_provider_get_interface_name, cap_file_provider_get_interface_description, NULL, @@ -1467,15 +1446,15 @@ raw_cf_open(capture_file *cf, const char *fname) cf->filename = g_strdup(fname); /* Indicate whether it's a permanent or temporary file. */ - cf->is_tempfile = FALSE; + cf->is_tempfile = false; /* No user changes yet. */ - cf->unsaved_changes = FALSE; + cf->unsaved_changes = false; cf->cd_t = WTAP_FILE_TYPE_SUBTYPE_UNKNOWN; cf->open_type = WTAP_TYPE_AUTO; cf->count = 0; - cf->drops_known = FALSE; + cf->drops_known = false; cf->drops = 0; cf->snap = 0; nstime_set_zero(&cf->elapsed_time); |