From Evan Huus:
[metze/wireshark/wip.git] / rawshark.c
index 58c31ff172be9074060d1c3ee0fe1887ba63b0f5..cad08a9afec2c4fdfa4af52cc92f615162a31935 100644 (file)
 # include <sys/stat.h>
 #endif
 
-#ifdef NEED_STRERROR_H
-#include "wsutil/strerror.h"
-#endif
-
-#ifdef HAVE_GETOPT_H
-#include <getopt.h>
-#else
+#ifndef HAVE_GETOPT
 #include "wsutil/wsgetopt.h"
 #endif
 
@@ -85,7 +79,7 @@
 #include <epan/column.h>
 #include "print.h"
 #include <epan/addr_resolv.h>
-#include "util.h"
+#include "ui/util.h"
 #include "clopts_common.h"
 #include "cmdarg_err.h"
 #include "version_info.h"
 #include "pcapio.h"
 #ifdef _WIN32
 #include "capture-wpcap.h"
-#include "capture_errs.h"
 #endif /* _WIN32 */
 #endif /* HAVE_LIBPCAP */
 #include "log.h"
 
 #ifdef _WIN32
-#include <shellapi.h>
+#include <wsutil/unicode-utils.h>
 #endif /* _WIN32 */
 
 /*
@@ -213,14 +206,16 @@ print_usage(gboolean print_ver)
     fprintf(output, "  -F <field>               field to display\n");
     fprintf(output, "  -n                       disable all name resolution (def: all enabled)\n");
     fprintf(output, "  -N <name resolve flags>  enable specific name resolution(s): \"mntC\"\n");
-    fprintf(output, "  -p                       use the system's packet header format (which may have 64-bit timestamps)\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, "  -s                       skip PCAP header on input\n");
 
-    /*fprintf(output, "\n");*/
+    fprintf(output, "\n");
     fprintf(output, "Output:\n");
     fprintf(output, "  -l                       flush output after each packet\n");
-    fprintf(output, "  -S                       format string for fields (%%D - name, %%S - stringval, %%N numval)\n");
+    fprintf(output, "  -S                       format string for fields\n");
+    fprintf(output, "                           (%%D - name, %%S - stringval, %%N numval)\n");
     fprintf(output, "  -t ad|a|r|d|dd|e         output format of time stamps (def: r: rel. to first)\n");
 
     fprintf(output, "\n");
@@ -274,7 +269,7 @@ raw_pipe_open(const char *pipe_name)
 #ifndef _WIN32
         if (ws_stat64(pipe_name, &pipe_stat) < 0) {
             fprintf(stderr, "rawshark: The pipe %s could not be checked: %s\n",
-                    pipe_name, strerror(errno));
+                    pipe_name, g_strerror(errno));
             return -1;
         }
         if (! S_ISFIFO(pipe_stat.st_mode)) {
@@ -293,7 +288,7 @@ raw_pipe_open(const char *pipe_name)
         rfd = ws_open(pipe_name, O_RDONLY | O_NONBLOCK, 0000 /* no creation so don't matter */);
         if (rfd == -1) {
             fprintf(stderr, "rawshark: \"%s\" could not be opened: %s\n",
-                    pipe_name, strerror(errno));
+                    pipe_name, g_strerror(errno));
             return -1;
         }
 #else /* _WIN32 */
@@ -348,7 +343,7 @@ raw_pipe_open(const char *pipe_name)
         rfd = _open_osfhandle((long) hPipe, _O_RDONLY);
         if (rfd == -1) {
             fprintf(stderr, "rawshark: \"%s\" could not be opened: %s\n",
-                    pipe_name, strerror(errno));
+                    pipe_name, g_strerror(errno));
             return -1;
         }
 #endif /* _WIN32 */
@@ -435,8 +430,6 @@ main(int argc, char *argv[])
 
 #ifdef _WIN32
     WSADATA              wsaData;
-    LPWSTR              *wc_argv;
-    int                  wc_argc;
 #endif  /* _WIN32 */
 
     char                *gpf_path, *pf_path;
@@ -460,13 +453,7 @@ main(int argc, char *argv[])
     static const char    optstring[] = OPTSTRING_INIT;
 
 #ifdef _WIN32
-    /* Convert our arg list to UTF-8. */
-    wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
-    if (wc_argv && wc_argc == argc) {
-        for (i = 0; i < argc; i++) {
-            argv[i] = g_utf16_to_utf8(wc_argv[i], -1, NULL, NULL, NULL);
-        }
-    } /* XXX else bail because something is horribly, horribly wrong? */
+    arg_list_utf_16to8(argc, argv);
 #endif /* _WIN32 */
 
     /*
@@ -539,21 +526,21 @@ main(int argc, char *argv[])
     if (gpf_path != NULL) {
         if (gpf_open_errno != 0) {
             cmdarg_err("Can't open global preferences file \"%s\": %s.",
-                       pf_path, strerror(gpf_open_errno));
+                       pf_path, g_strerror(gpf_open_errno));
         }
         if (gpf_read_errno != 0) {
             cmdarg_err("I/O error reading global preferences file \"%s\": %s.",
-                       pf_path, strerror(gpf_read_errno));
+                       pf_path, g_strerror(gpf_read_errno));
         }
     }
     if (pf_path != NULL) {
         if (pf_open_errno != 0) {
             cmdarg_err("Can't open your preferences file \"%s\": %s.", pf_path,
-                       strerror(pf_open_errno));
+                       g_strerror(pf_open_errno));
         }
         if (pf_read_errno != 0) {
             cmdarg_err("I/O error reading your preferences file \"%s\": %s.",
-                       pf_path, strerror(pf_read_errno));
+                       pf_path, g_strerror(pf_read_errno));
         }
         g_free(pf_path);
         pf_path = NULL;
@@ -568,11 +555,11 @@ main(int argc, char *argv[])
     if (gdp_path != NULL) {
         if (gdp_open_errno != 0) {
             cmdarg_err("Could not open global disabled protocols file\n\"%s\": %s.",
-                       gdp_path, strerror(gdp_open_errno));
+                       gdp_path, g_strerror(gdp_open_errno));
         }
         if (gdp_read_errno != 0) {
             cmdarg_err("I/O error reading global disabled protocols file\n\"%s\": %s.",
-                       gdp_path, strerror(gdp_read_errno));
+                       gdp_path, g_strerror(gdp_read_errno));
         }
         g_free(gdp_path);
     }
@@ -580,12 +567,12 @@ main(int argc, char *argv[])
         if (dp_open_errno != 0) {
             cmdarg_err(
                 "Could not open your disabled protocols file\n\"%s\": %s.", dp_path,
-                strerror(dp_open_errno));
+                g_strerror(dp_open_errno));
         }
         if (dp_read_errno != 0) {
             cmdarg_err(
                 "I/O error reading your disabled protocols file\n\"%s\": %s.", dp_path,
-                strerror(dp_read_errno));
+                g_strerror(dp_read_errno));
         }
         g_free(dp_path);
     }
@@ -703,6 +690,10 @@ main(int argc, char *argv[])
                     timestamp_set_type(TS_DELTA_DIS);
                 else if (strcmp(optarg, "e") == 0)
                     timestamp_set_type(TS_EPOCH);
+                else if (strcmp(optarg, "u") == 0)
+                    timestamp_set_type(TS_UTC);
+                else if (strcmp(optarg, "ud") == 0)
+                    timestamp_set_type(TS_UTC_WITH_DATE);
                 else {
                     cmdarg_err("Invalid time stamp type \"%s\"",
                                optarg);
@@ -947,7 +938,7 @@ raw_pipe_read(struct wtap_pkthdr *phdr, guchar * pd, int *err, const gchar **err
     printf("len: %d (%04x)\n", hdr.len, hdr.len);
 #endif
     if (bytes_needed > WTAP_MAX_PACKET_SIZE) {
-        *err = WTAP_ERR_BAD_RECORD;
+        *err = WTAP_ERR_BAD_FILE;
         g_snprintf(err_str, 100, "Bad packet length: %d (%04x)", bytes_needed, bytes_needed);
         *err_info = err_str;
         return FALSE;
@@ -1004,7 +995,7 @@ load_cap_file(capture_file *cf)
                            cf->filename);
                 break;
 
-            case WTAP_ERR_BAD_RECORD:
+            case WTAP_ERR_BAD_FILE:
                 cmdarg_err("The file \"%s\" appears to be damaged or corrupt.\n(%s)",
                            cf->filename, err_info);
                 break;
@@ -1339,7 +1330,7 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index)
                                 if (hfinfo->display & BASE_RANGE_STRING) {
                                     g_string_append(label_s, rval_to_str(svalue, RVALS(hfinfo->strings), "Unknown"));
                                 } else if (hfinfo->display & BASE_EXT_STRING) {
-                                    g_string_append(label_s, val_to_str_ext(svalue, (value_string_ext *) hfinfo->strings, "Unknown"));
+                                    g_string_append(label_s, val_to_str_ext(svalue, (const value_string_ext *) hfinfo->strings, "Unknown"));
                                 } else {
                                     g_string_append(label_s, val_to_str(svalue, cVALS(hfinfo->strings), "Unknown"));
                                 }
@@ -1352,7 +1343,7 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index)
                                 if (!hfinfo->bitmask && hfinfo->display & BASE_RANGE_STRING) {
                                     g_string_append(label_s, rval_to_str(uvalue, RVALS(hfinfo->strings), "Unknown"));
                                 } else if (hfinfo->display & BASE_EXT_STRING) {
-                                    g_string_append(label_s, val_to_str_ext(uvalue, (value_string_ext *) hfinfo->strings, "Unknown"));
+                                    g_string_append(label_s, val_to_str_ext(uvalue, (const value_string_ext *) hfinfo->strings, "Unknown"));
                                 } else {
                                     g_string_append(label_s, val_to_str(uvalue, cVALS(hfinfo->strings), "Unknown"));
                                 }
@@ -1434,7 +1425,6 @@ protocolinfo_init(char *field)
                    ftenum_to_string(hfi),
                    absolute_time_display_e_to_string(hfi->display));
             break;
-            break;
 
         default:
             printf("%u %s %s - ",
@@ -1554,7 +1544,7 @@ show_print_file_io_error(int err)
 
         default:
             cmdarg_err("An error occurred while printing packets: %s.",
-                       strerror(err));
+                       g_strerror(err));
             break;
     }
 }
@@ -1630,7 +1620,7 @@ static void
 read_failure_message(const char *filename, int err)
 {
     cmdarg_err("An error occurred while reading from the file \"%s\": %s.",
-               filename, strerror(err));
+               filename, g_strerror(err));
 }
 
 /*
@@ -1640,7 +1630,7 @@ static void
 write_failure_message(const char *filename, int err)
 {
     cmdarg_err("An error occurred while writing to the file \"%s\": %s.",
-               filename, strerror(err));
+               filename, g_strerror(err));
 }
 
 /*
@@ -1682,6 +1672,6 @@ cmdarg_err_cont(const char *fmt, ...)
  * indent-tabs-mode: nil
  * End:
  *
- * ex: set shiftwidth=4 tabstop=8 expandtab
+ * ex: set shiftwidth=4 tabstop=8 expandtab:
  * :indentSize=4:tabSize=8:noTabs=true:
  */