Xcode 4 isn't available on DVD, but is available for download from
[obnox/wireshark/wip.git] / randpkt.c
index a9d157ac52d10a993240d008bd674a394ca274eb..b6a8c86a54d35affad6b7ce9c2e2ceb6a30b7976 100644 (file)
--- a/randpkt.c
+++ b/randpkt.c
 #include "config.h"
 #endif
 
-#ifdef HAVE_GETOPT_H
-#include <getopt.h>
-#else
-#include "wsutil/wsgetopt.h"
-#endif
-
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
+#ifndef HAVE_GETOPT
+#include "wsutil/wsgetopt.h"
+#endif
+
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
 #include <string.h>
 #include <glib.h>
 #include "wiretap/wtap.h"
+#include "wsutil/file_util.h"
 
 #ifdef _WIN32
-#include <windows.h>
-#include <shellapi.h>
+#include <wsutil/unicode-utils.h>
 #endif /* _WIN32 */
 
 #define array_length(x)        (sizeof x / sizeof x[0])
@@ -508,12 +506,6 @@ main(int argc, char **argv)
 
        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;
@@ -521,13 +513,7 @@ main(int argc, char **argv)
        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? */
+       arg_list_utf_16to8(argc, argv);
 #endif /* _WIN32 */
 
        while ((opt = getopt(argc, argv, "b:c:ht:")) != -1) {
@@ -718,22 +704,22 @@ seed(void)
         *
         * XXX - Use CryptGenRandom on Windows?
         */
-       fd = open(RANDOM_DEV, O_RDONLY);
+       fd = ws_open(RANDOM_DEV, O_RDONLY);
        if (fd == -1) {
                if (errno != ENOENT) {
                        fprintf(stderr,
                            "randpkt: Could not open " RANDOM_DEV " for reading: %s\n",
-                           strerror(errno));
+                           g_strerror(errno));
                        exit(2);
                }
                goto fallback;
        }
 
-       ret = read(fd, &randomness, sizeof randomness);
+       ret = ws_read(fd, &randomness, sizeof randomness);
        if (ret == -1) {
                fprintf(stderr,
                    "randpkt: Could not read from " RANDOM_DEV ": %s\n",
-                   strerror(errno));
+                   g_strerror(errno));
                exit(2);
        }
        if ((size_t)ret != sizeof randomness) {
@@ -743,6 +729,7 @@ seed(void)
                exit(2);
        }
        srand(randomness);
+       ws_close(fd);
        return;
 
 fallback: