*
* $Id$
*
- * Written by Scott Renfro <scott@renfro.org> based on
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Mergecap written by Scott Renfro <scott@renfro.org> based on
* editcap by Richard Sharpe and Guy Harris
*
*/
fprintf(stderr, "Merge two or more capture files into one.\n");
fprintf(stderr, "See http://www.wireshark.org for more information.\n");
fprintf(stderr, "\n");
- fprintf(stderr, "Usage: mergecap [options] -w <outfile>|- <infile> ...\n");
+ fprintf(stderr, "Usage: mergecap [options] -w <outfile>|- <infile> [<infile> ...]\n");
fprintf(stderr, "\n");
fprintf(stderr, "Output:\n");
fprintf(stderr, " -a concatenate rather than merge files.\n");
fprintf(stderr, " default is to merge based on frame timestamps.\n");
fprintf(stderr, " -s <snaplen> truncate packets to <snaplen> bytes of data.\n");
fprintf(stderr, " -w <outfile>|- set the output filename to <outfile> or '-' for stdout.\n");
- fprintf(stderr, " -F <capture type> set the output file type; default is libpcap.\n");
+ fprintf(stderr, " -F <capture type> set the output file type; default is pcapng.\n");
fprintf(stderr, " an empty \"-F\" option will list the file types.\n");
fprintf(stderr, " -T <encap type> set the output file encapsulation type;\n");
fprintf(stderr, " default is the same as the first input file.\n");
fprintf(stderr, " -v verbose output.\n");
}
-static void list_capture_types(void) {
- int i;
+struct string_elem {
+ const char *sstr; /* The short string */
+ const char *lstr; /* The long string */
+};
+
+static gint
+string_compare(gconstpointer a, gconstpointer b)
+{
+ return strcmp(((const struct string_elem *)a)->sstr,
+ ((const struct string_elem *)b)->sstr);
+}
- fprintf(stderr, "mergecap: The available capture file types for \"F\":\n");
- for (i = 0; i < WTAP_NUM_FILE_TYPES; i++) {
- if (wtap_dump_can_open(i))
- fprintf(stderr, " %s - %s\n",
- wtap_file_type_short_string(i), wtap_file_type_string(i));
+static void
+string_elem_print(gpointer data, gpointer not_used _U_)
+{
+ fprintf(stderr, " %s - %s\n",
+ ((struct string_elem *)data)->sstr,
+ ((struct string_elem *)data)->lstr);
+}
+
+static void
+list_capture_types(void) {
+ int i;
+ struct string_elem *captypes;
+ GSList *list = NULL;
+
+ captypes = g_malloc(sizeof(struct string_elem) * WTAP_NUM_FILE_TYPES);
+
+ fprintf(stderr, "mergecap: The available capture file types for the \"-F\" flag are:\n");
+ for (i = 0; i < WTAP_NUM_FILE_TYPES; i++) {
+ if (wtap_dump_can_open(i)) {
+ captypes[i].sstr = wtap_file_type_short_string(i);
+ captypes[i].lstr = wtap_file_type_string(i);
+ list = g_slist_insert_sorted(list, &captypes[i], string_compare);
}
+ }
+ g_slist_foreach(list, string_elem_print, NULL);
+ g_slist_free(list);
+ g_free(captypes);
}
-static void list_encap_types(void) {
+static void
+list_encap_types(void) {
int i;
- const char *string;
+ struct string_elem *encaps;
+ GSList *list = NULL;
- fprintf(stderr, "mergecap: The available encapsulation types for \"T\":\n");
+ encaps = g_malloc(sizeof(struct string_elem) * WTAP_NUM_ENCAP_TYPES);
+ fprintf(stderr, "mergecap: The available encapsulation types for the \"-T\" flag are:\n");
for (i = 0; i < WTAP_NUM_ENCAP_TYPES; i++) {
- string = wtap_encap_short_string(i);
- if (string != NULL)
- fprintf(stderr, " %s - %s\n",
- string, wtap_encap_string(i));
+ encaps[i].sstr = wtap_encap_short_string(i);
+ if (encaps[i].sstr != NULL) {
+ encaps[i].lstr = wtap_encap_string(i);
+ list = g_slist_insert_sorted(list, &encaps[i], string_compare);
+ }
}
+ g_slist_foreach(list, string_elem_print, NULL);
+ g_slist_free(list);
+ g_free(encaps);
}
int
case WTAP_ERR_UNSUPPORTED:
case WTAP_ERR_UNSUPPORTED_ENCAP:
- case WTAP_ERR_BAD_RECORD:
+ case WTAP_ERR_BAD_FILE:
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
break;
case WTAP_ERR_UNSUPPORTED:
case WTAP_ERR_UNSUPPORTED_ENCAP:
- case WTAP_ERR_BAD_RECORD:
+ case WTAP_ERR_BAD_FILE:
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
break;