Make the frame_data_sequence structure opaque, and move some other
[obnox/wireshark/wip.git] / randpkt.c
index 2d92d95ea688b3700f9a8957e91b6b8b8a018017..a9d157ac52d10a993240d008bd674a394ca274eb 100644 (file)
--- a/randpkt.c
+++ b/randpkt.c
 #include "config.h"
 #endif
 
-#ifdef NEED_GETOPT_H
-#include "getopt.h"
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+#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 */
@@ -500,8 +507,12 @@ main(int argc, char **argv)
        guint8                  buffer[65536];
 
        int                     opt;
-       extern char             *optarg;
-       extern int              optind;
+
+#ifdef _WIN32
+       LPWSTR              *wc_argv;
+       int                  wc_argc;
+#endif  /* _WIN32 */
+       
 
        int                     produce_count = 1000; /* number of pkts to produce */
        int                     produce_type = PKT_ETHERNET;
@@ -509,6 +520,16 @@ main(int argc, char **argv)
        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 */
@@ -689,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);
                }
@@ -709,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);
        }