Avoid adding -pie on older cmake versions
[metze/wireshark/wip.git] / randpkt.c
index 5393fa9ee19d51477822712da5261e7e47e1b5cd..bf391be2bbe1843d2fbd95fbcea32ec7aaae63a5 100644 (file)
--- a/randpkt.c
+++ b/randpkt.c
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "config.h"
+#include <config.h>
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
-#ifndef HAVE_GETOPT
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#endif
+
+#ifndef HAVE_GETOPT_LONG
 #include "wsutil/wsgetopt.h"
 #endif
 
@@ -44,6 +48,7 @@
 #include <glib.h>
 #include "wiretap/wtap.h"
 #include "wsutil/file_util.h"
+#include <wsutil/ws_diag_control.h>
 
 #ifdef _WIN32
 #include <wsutil/unicode-utils.h>
@@ -498,6 +503,7 @@ main(int argc, char **argv)
        struct wtap_pkthdr      pkthdr;
        union wtap_pseudo_header *ps_header = &pkthdr.pseudo_header;
        int                     i, j, len_this_pkt, len_random, err;
+       gchar                   *err_info;
        guint8                  buffer[65536];
 
        int                     opt;
@@ -507,13 +513,19 @@ main(int argc, char **argv)
        char                    *produce_filename = NULL;
        int                     produce_max_bytes = 5000;
        pkt_example             *example;
+DIAG_OFF(cast-qual)
+       static const struct option long_options[] = {
+               {(char *)"help", no_argument, NULL, 'h'},
+               {0, 0, 0, 0 }
+       };
+DIAG_ON(cast-qual)
 
 #ifdef _WIN32
        arg_list_utf_16to8(argc, argv);
        create_app_running_mutex();
 #endif /* _WIN32 */
 
-       while ((opt = getopt(argc, argv, "b:c:ht:")) != -1) {
+       while ((opt = getopt_long(argc, argv, "b:c:ht:", long_options, NULL)) != -1) {
                switch (opt) {
                        case 'b':       /* max bytes */
                                produce_max_bytes = atoi(optarg);
@@ -619,7 +631,11 @@ main(int argc, char **argv)
                        }
                }
 
-               wtap_dump(dump, &pkthdr, &buffer[0], &err);
+               /* XXX - report errors! */
+               if (!wtap_dump(dump, &pkthdr, &buffer[0], &err, &err_info)) {
+                       if (err_info != NULL)
+                               g_free(err_info);
+               }
        }
 
        wtap_dump_close(dump, &err);