Fix a couple (value) mistakes in value_strings. Found by Martin's patch on the ...
[obnox/wireshark/wip.git] / randpkt.c
index a018265112fb07fd37cef50a3fa09e9d38ff1146..a9d157ac52d10a993240d008bd674a394ca274eb 100644 (file)
--- a/randpkt.c
+++ b/randpkt.c
@@ -30,7 +30,7 @@
 #ifdef HAVE_GETOPT_H
 #include <getopt.h>
 #else
-#include "wsgetopt.h"
+#include "wsutil/wsgetopt.h"
 #endif
 
 #ifdef HAVE_UNISTD_H
 #include <glib.h>
 #include "wiretap/wtap.h"
 
+#ifdef _WIN32
+#include <windows.h>
+#include <shellapi.h>
+#endif /* _WIN32 */
+
 #define array_length(x)        (sizeof x / sizeof x[0])
 
 /* Types of produceable packets */
@@ -502,12 +507,29 @@ main(int argc, char **argv)
        guint8                  buffer[65536];
 
        int                     opt;
+
+#ifdef _WIN32
+       LPWSTR              *wc_argv;
+       int                  wc_argc;
+#endif  /* _WIN32 */
+       
+
        int                     produce_count = 1000; /* number of pkts to produce */
        int                     produce_type = PKT_ETHERNET;
        char                    *produce_filename = NULL;
        int                     produce_max_bytes = 5000;
        pkt_example             *example;
 
+#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? */
+#endif /* _WIN32 */
+
        while ((opt = getopt(argc, argv, "b:c:ht:")) != -1) {
                switch (opt) {
                        case 'b':       /* max bytes */
@@ -688,17 +710,19 @@ seed(void)
        int             fd;
        ssize_t         ret;
 
+#define RANDOM_DEV "/dev/urandom"
+
        /*
-        * Assume it's at least worth trying /dev/random on UN*X.
+        * Assume it's at least worth trying /dev/urandom on UN*X.
         * If it doesn't exist, fall back on time().
         *
-        * XXX - does Windows have a system source of entropy?
+        * XXX - Use CryptGenRandom on Windows?
         */
-       fd = open("/dev/random", O_RDONLY);
+       fd = open(RANDOM_DEV, O_RDONLY);
        if (fd == -1) {
                if (errno != ENOENT) {
                        fprintf(stderr,
-                           "randpkt: Could not open /dev/random for reading: %s\n",
+                           "randpkt: Could not open " RANDOM_DEV " for reading: %s\n",
                            strerror(errno));
                        exit(2);
                }
@@ -708,13 +732,13 @@ seed(void)
        ret = read(fd, &randomness, sizeof randomness);
        if (ret == -1) {
                fprintf(stderr,
-                   "randpkt: Could not read from /dev/random: %s\n",
+                   "randpkt: Could not read from " RANDOM_DEV ": %s\n",
                    strerror(errno));
                exit(2);
        }
        if ((size_t)ret != sizeof randomness) {
                fprintf(stderr,
-                   "randpkt: Tried to read %lu bytes from /dev/random, got %ld\n",
+                   "randpkt: Tried to read %lu bytes from " RANDOM_DEV ", got %ld\n",
                    (unsigned long)sizeof randomness, (long)ret);
                exit(2);
        }