#include <wsutil/report_message.h>
#include <wsutil/strnatcmp.h>
#include <wsutil/str_util.h>
-#include <ws_version_info.h>
+#include <version_info.h>
#include <wsutil/pint.h>
#include <wsutil/strtoi.h>
#include <wiretap/wtap_opttypes.h>
fprintf(output, " If -v is used with any of the 'Duplicate Packet\n");
fprintf(output, " Removal' options (-d, -D or -w) then Packet lengths\n");
fprintf(output, " and MD5 hashes are printed to standard-error.\n");
- fprintf(output, "\n");
}
struct string_elem {
}
static void
-string_elem_print(gpointer data, gpointer not_used _U_)
+string_elem_print(gpointer data, gpointer stream_ptr)
{
- fprintf(stderr, " %s - %s\n",
+ fprintf((FILE *) stream_ptr, " %s - %s\n",
((struct string_elem *)data)->sstr,
((struct string_elem *)data)->lstr);
}
static void
-list_capture_types(void) {
+list_capture_types(FILE *stream) {
int i;
struct string_elem *captypes;
GSList *list = NULL;
captypes = g_new(struct string_elem,WTAP_NUM_FILE_TYPES_SUBTYPES);
- fprintf(stderr, "editcap: The available capture file types for the \"-F\" flag are:\n");
+ fprintf(stream, "editcap: The available capture file types for the \"-F\" flag are:\n");
for (i = 0; i < WTAP_NUM_FILE_TYPES_SUBTYPES; i++) {
if (wtap_dump_can_open(i)) {
captypes[i].sstr = wtap_file_type_subtype_short_string(i);
list = g_slist_insert_sorted(list, &captypes[i], string_compare);
}
}
- g_slist_foreach(list, string_elem_print, NULL);
+ g_slist_foreach(list, string_elem_print, stream);
g_slist_free(list);
g_free(captypes);
}
static void
-list_encap_types(void) {
+list_encap_types(FILE *stream) {
int i;
struct string_elem *encaps;
GSList *list = NULL;
encaps = (struct string_elem *)g_malloc(sizeof(struct string_elem) * WTAP_NUM_ENCAP_TYPES);
- fprintf(stderr, "editcap: The available encapsulation types for the \"-T\" flag are:\n");
+ fprintf(stream, "editcap: The available encapsulation types for the \"-T\" flag are:\n");
for (i = 0; i < WTAP_NUM_ENCAP_TYPES; i++) {
encaps[i].sstr = wtap_encap_short_string(i);
if (encaps[i].sstr != NULL) {
list = g_slist_insert_sorted(list, &encaps[i], string_nat_compare);
}
}
- g_slist_foreach(list, string_elem_print, NULL);
+ g_slist_foreach(list, string_elem_print, stream);
g_slist_free(list);
g_free(encaps);
}
static void
failure_message_cont(const char *msg_format, va_list ap)
{
- vfprintf(stderr, msg_format, ap);
- fprintf(stderr, "\n");
+ vfprintf(stderr, msg_format, ap);
+ fprintf(stderr, "\n");
}
static wtap_dumper *
if (out_file_type_subtype < 0) {
fprintf(stderr, "editcap: \"%s\" isn't a valid capture file type\n\n",
optarg);
- list_capture_types();
+ list_capture_types(stderr);
ret = INVALID_OPTION;
goto clean_exit;
}
if (out_frame_type < 0) {
fprintf(stderr, "editcap: \"%s\" isn't a valid encapsulation type\n\n",
optarg);
- list_encap_types();
+ list_encap_types(stderr);
ret = INVALID_OPTION;
goto clean_exit;
}
case '?': /* Bad options if GNU getopt */
switch(optopt) {
case'F':
- list_capture_types();
+ list_capture_types(stdout);
break;
case'T':
- list_encap_types();
+ list_encap_types(stdout);
break;
default:
print_usage(stderr);
+ ret = INVALID_OPTION;
break;
}
- ret = INVALID_OPTION;
goto clean_exit;
break;
}
wth = wtap_open_offline(argv[optind], WTAP_TYPE_AUTO, &read_err, &read_err_info, FALSE);
if (!wth) {
- cfile_open_failure_message("editap", argv[optind], read_err,
- read_err_info, FALSE, WTAP_TYPE_AUTO);
+ cfile_open_failure_message("editcap", argv[optind], read_err,
+ read_err_info);
ret = INVALID_FILE;
goto clean_exit;
}
shb_hdrs, idb_inf, nrb_hdrs, &write_err);
if (pdh == NULL) {
- fprintf(stderr, "editcap: Can't open or create %s: %s\n",
- filename, wtap_strerror(write_err));
+ cfile_dump_open_failure_message("editcap", filename,
+ write_err,
+ out_file_type_subtype);
ret = INVALID_FILE;
goto clean_exit;
}
&& phdr->ts.nsecs >= block_start.nsecs )) { /* time for the next file */
if (!wtap_dump_close(pdh, &write_err)) {
- fprintf(stderr, "editcap: Error writing to %s: %s\n",
- filename, wtap_strerror(write_err));
+ cfile_close_failure_message(filename, write_err);
ret = WRITE_ERROR;
goto clean_exit;
}
shb_hdrs, idb_inf, nrb_hdrs, &write_err);
if (pdh == NULL) {
- fprintf(stderr, "editcap: Can't open or create %s: %s\n",
- filename, wtap_strerror(write_err));
+ cfile_dump_open_failure_message("editcap", filename,
+ write_err,
+ out_file_type_subtype);
ret = INVALID_FILE;
goto clean_exit;
}
/* time for the next file? */
if (written_count > 0 && (written_count % split_packet_count) == 0) {
if (!wtap_dump_close(pdh, &write_err)) {
- fprintf(stderr, "editcap: Error writing to %s: %s\n",
- filename, wtap_strerror(write_err));
+ cfile_close_failure_message(filename, write_err);
ret = WRITE_ERROR;
goto clean_exit;
}
snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_snapshot_length(wth),
shb_hdrs, idb_inf, nrb_hdrs, &write_err);
if (pdh == NULL) {
- fprintf(stderr, "editcap: Can't open or create %s: %s\n",
- filename, wtap_strerror(write_err));
+ cfile_dump_open_failure_message("editcap", filename,
+ write_err,
+ out_file_type_subtype);
ret = INVALID_FILE;
goto clean_exit;
}
if (frames_user_comments) {
const char *comment =
(const char*)g_tree_lookup(frames_user_comments, GUINT_TO_POINTER(read_count));
+ /* XXX: What about comment changed to no comment? */
if (comment != NULL) {
/* Copy and change rather than modify returned phdr */
temp_phdr = *phdr;
temp_phdr.opt_comment = g_strdup(comment);
+ temp_phdr.has_comment_changed = TRUE;
+ phdr = &temp_phdr;
+ } else {
+ temp_phdr = *phdr;
+ temp_phdr.has_comment_changed = FALSE;
phdr = &temp_phdr;
}
}
/* Attempt to dump out current frame to the output file */
if (!wtap_dump(pdh, phdr, buf, &write_err, &write_err_info)) {
- cfile_write_failure_message(argv[optind], filename,
+ cfile_write_failure_message("editcap", argv[optind],
+ filename,
write_err, write_err_info,
read_count,
out_file_type_subtype);
if (read_err != 0) {
/* Print a message noting that the read failed somewhere along the
* line. */
- fprintf(stderr,
- "editcap: An error occurred while reading \"%s\": %s.\n",
- argv[optind], wtap_strerror(read_err));
- if (read_err_info != NULL) {
- fprintf(stderr, "(%s)\n", read_err_info);
- g_free(read_err_info);
- }
+ cfile_read_failure_message("editcap", argv[optind], read_err,
+ read_err_info);
}
if (!pdh) {
snaplen ? MIN(snaplen, wtap_snapshot_length(wth)): wtap_snapshot_length(wth),
shb_hdrs, idb_inf, nrb_hdrs, &write_err);
if (pdh == NULL) {
- fprintf(stderr, "editcap: Can't open or create %s: %s\n",
- filename, wtap_strerror(write_err));
+ cfile_dump_open_failure_message("editcap", filename,
+ write_err,
+ out_file_type_subtype);
ret = INVALID_FILE;
goto clean_exit;
}
}
if (!wtap_dump_close(pdh, &write_err)) {
- fprintf(stderr, "editcap: Error writing to %s: %s\n", filename,
- wtap_strerror(write_err));
+ cfile_close_failure_message(filename, write_err);
ret = WRITE_ERROR;
goto clean_exit;
}