aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2005-04-03 11:00:49 +0000
committerGuy Harris <guy@alum.mit.edu>2005-04-03 11:00:49 +0000
commit466c3e9c8d23fe1f1ebceaf516e9869bcf74a478 (patch)
tree5e20e152c62b60e48114f43a53f6eb9d8dba78cf
parent951b7c9aaa9c99875b99eba36a18f65597732a14 (diff)
Make editcap use wtap_read(); that eliminates the last user of
wtap_loop(), so eliminate wtap_loop(). svn path=/trunk/; revision=14006
-rw-r--r--editcap.c176
-rw-r--r--wiretap/ascend.c2
-rw-r--r--wiretap/cosine.c2
-rw-r--r--wiretap/csids.c2
-rw-r--r--wiretap/dbs-etherwatch.c2
-rw-r--r--wiretap/eyesdn.c2
-rw-r--r--wiretap/pppdump.c2
-rw-r--r--wiretap/toshiba.c2
-rw-r--r--wiretap/vms.c2
-rw-r--r--wiretap/wtap.c23
-rw-r--r--wiretap/wtap.def1
-rw-r--r--wiretap/wtap.h8
12 files changed, 87 insertions, 137 deletions
diff --git a/editcap.c b/editcap.c
index 0708489c53..aa90528490 100644
--- a/editcap.c
+++ b/editcap.c
@@ -51,12 +51,10 @@ struct time_adjustment {
static struct select_item selectfrm[100];
static int max_selected = -1;
-static int count = 1;
static int keep_em = 0;
static int out_file_type = WTAP_FILE_PCAP; /* default to "libpcap" */
static int out_frame_type = -2; /* Leave frame type alone */
static int verbose = 0; /* Not so verbose */
-static unsigned int snaplen = 0; /* No limit */
static struct time_adjustment time_adj = {{0, 0}, 0}; /* no adjustment */
/* Add a selection item, a simple parser for now */
@@ -121,87 +119,6 @@ static int selected(int recno)
}
-/* An argument to the callback routine */
-
-typedef struct {
- char *filename;
- wtap_dumper *pdh;
-} callback_arg;
-
-/*
- *The callback routine that is called for each frame in the input file
- */
-
-static void
-edit_callback(guchar *user, const struct wtap_pkthdr *phdr, long offset _U_,
- union wtap_pseudo_header *pseudo_header, const guchar *buf)
-{
- callback_arg *argp = (callback_arg *)user;
- int err;
- struct wtap_pkthdr snap_phdr;
-
- if ((!selected(count) && !keep_em) ||
- (selected(count) && keep_em)) {
-
- if (verbose)
- printf("Record: %u\n", count);
-
- /* We simply write it, perhaps after truncating it; we could do other
- things, like modify it. */
-
- if (snaplen != 0 && phdr->caplen > snaplen) {
- snap_phdr = *phdr;
- snap_phdr.caplen = snaplen;
- phdr = &snap_phdr;
- }
-
- /* assume that if the frame's tv_sec is 0, then
- * the timestamp isn't supported */
- if (phdr->ts.tv_sec > 0 && time_adj.tv.tv_sec != 0) {
- snap_phdr = *phdr;
- if (time_adj.is_negative)
- snap_phdr.ts.tv_sec -= time_adj.tv.tv_sec;
- else
- snap_phdr.ts.tv_sec += time_adj.tv.tv_sec;
- phdr = &snap_phdr;
- }
-
- /* assume that if the frame's tv_sec is 0, then
- * the timestamp isn't supported */
- if (phdr->ts.tv_sec > 0 && time_adj.tv.tv_usec != 0) {
- snap_phdr = *phdr;
- if (time_adj.is_negative) { /* subtract */
- if (snap_phdr.ts.tv_usec < time_adj.tv.tv_usec) { /* borrow */
- snap_phdr.ts.tv_sec--;
- snap_phdr.ts.tv_usec += ONE_MILLION;
- }
- snap_phdr.ts.tv_usec -= time_adj.tv.tv_usec;
- } else { /* add */
- if (snap_phdr.ts.tv_usec + time_adj.tv.tv_usec > ONE_MILLION) {
- /* carry */
- snap_phdr.ts.tv_sec++;
- snap_phdr.ts.tv_usec += time_adj.tv.tv_usec - ONE_MILLION;
- } else {
- snap_phdr.ts.tv_usec += time_adj.tv.tv_usec;
- }
- }
- phdr = &snap_phdr;
- }
-
- if (!wtap_dump(argp->pdh, phdr, pseudo_header, buf, &err)) {
-
- fprintf(stderr, "editcap: Error writing to %s: %s\n", argp->filename,
- wtap_strerror(err));
- exit(1);
-
- }
-
- }
-
- count++;
-
-}
-
static void
set_time_adjustment(char *optarg)
{
@@ -308,12 +225,16 @@ int main(int argc, char *argv[])
wtap *wth;
int i, err;
gchar *err_info;
- callback_arg args;
extern char *optarg;
extern int optind;
int opt;
char *p;
- int snapshot_length;
+ unsigned int snaplen = 0; /* No limit */
+ wtap_dumper *pdh;
+ int count = 1;
+ long data_offset;
+ struct wtap_pkthdr snap_phdr;
+ const struct wtap_pkthdr *phdr;
/* Process the options first */
@@ -417,18 +338,12 @@ int main(int argc, char *argv[])
if ((argc - optind) >= 2) {
- args.filename = argv[optind + 1];
if (out_frame_type == -2)
out_frame_type = wtap_file_encap(wth);
- snapshot_length = wtap_snapshot_length(wth);
- if (snapshot_length == 0) {
- /* Snapshot length of input file not known. */
- snapshot_length = WTAP_MAX_PACKET_SIZE;
- }
- args.pdh = wtap_dump_open(argv[optind + 1], out_file_type,
- out_frame_type, wtap_snapshot_length(wth), &err);
- if (args.pdh == NULL) {
+ pdh = wtap_dump_open(argv[optind + 1], out_file_type,
+ out_frame_type, wtap_snapshot_length(wth), &err);
+ if (pdh == NULL) {
fprintf(stderr, "editcap: Can't open or create %s: %s\n", argv[optind+1],
wtap_strerror(err));
@@ -439,7 +354,74 @@ int main(int argc, char *argv[])
for (i = optind + 2; i < argc; i++)
add_selection(argv[i]);
- if (!wtap_loop(wth, 0, edit_callback, (char *)&args, &err, &err_info)) {
+ while (wtap_read(wth, &err, &err_info, &data_offset)) {
+
+ if ((!selected(count) && !keep_em) ||
+ (selected(count) && keep_em)) {
+
+ if (verbose)
+ printf("Record: %u\n", count);
+
+ /* We simply write it, perhaps after truncating it; we could do other
+ things, like modify it. */
+
+ phdr = wtap_phdr(wth);
+
+ if (snaplen != 0 && phdr->caplen > snaplen) {
+ snap_phdr = *phdr;
+ snap_phdr.caplen = snaplen;
+ phdr = &snap_phdr;
+ }
+
+ /* assume that if the frame's tv_sec is 0, then
+ * the timestamp isn't supported */
+ if (phdr->ts.tv_sec > 0 && time_adj.tv.tv_sec != 0) {
+ snap_phdr = *phdr;
+ if (time_adj.is_negative)
+ snap_phdr.ts.tv_sec -= time_adj.tv.tv_sec;
+ else
+ snap_phdr.ts.tv_sec += time_adj.tv.tv_sec;
+ phdr = &snap_phdr;
+ }
+
+ /* assume that if the frame's tv_sec is 0, then
+ * the timestamp isn't supported */
+ if (phdr->ts.tv_sec > 0 && time_adj.tv.tv_usec != 0) {
+ snap_phdr = *phdr;
+ if (time_adj.is_negative) { /* subtract */
+ if (snap_phdr.ts.tv_usec < time_adj.tv.tv_usec) { /* borrow */
+ snap_phdr.ts.tv_sec--;
+ snap_phdr.ts.tv_usec += ONE_MILLION;
+ }
+ snap_phdr.ts.tv_usec -= time_adj.tv.tv_usec;
+ } else { /* add */
+ if (snap_phdr.ts.tv_usec + time_adj.tv.tv_usec > ONE_MILLION) {
+ /* carry */
+ snap_phdr.ts.tv_sec++;
+ snap_phdr.ts.tv_usec += time_adj.tv.tv_usec - ONE_MILLION;
+ } else {
+ snap_phdr.ts.tv_usec += time_adj.tv.tv_usec;
+ }
+ }
+ phdr = &snap_phdr;
+ }
+
+ if (!wtap_dump(pdh, phdr, wtap_pseudoheader(wth), wtap_buf_ptr(wth),
+ &err)) {
+
+ fprintf(stderr, "editcap: Error writing to %s: %s\n",
+ argv[optind + 1], wtap_strerror(err));
+ exit(1);
+
+ }
+
+ }
+
+ count++;
+
+ }
+
+ if (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",
@@ -454,9 +436,9 @@ int main(int argc, char *argv[])
}
}
- if (!wtap_dump_close(args.pdh, &err)) {
+ if (!wtap_dump_close(pdh, &err)) {
- fprintf(stderr, "editcap: Error writing to %s: %s\n", argv[2],
+ fprintf(stderr, "editcap: Error writing to %s: %s\n", argv[optind + 1],
wtap_strerror(err));
exit(1);
diff --git a/wiretap/ascend.c b/wiretap/ascend.c
index 95ad5cd3c9..a411d78d60 100644
--- a/wiretap/ascend.c
+++ b/wiretap/ascend.c
@@ -250,7 +250,7 @@ static void config_pseudo_header(union wtap_pseudo_header *pseudo_head)
}
}
-/* Read the next packet; called from wtap_loop(). */
+/* Read the next packet; called from wtap_read(). */
static gboolean ascend_read(wtap *wth, int *err, gchar **err_info,
long *data_offset)
{
diff --git a/wiretap/cosine.c b/wiretap/cosine.c
index c17171ea69..2b8138910c 100644
--- a/wiretap/cosine.c
+++ b/wiretap/cosine.c
@@ -303,7 +303,7 @@ int cosine_open(wtap *wth, int *err, gchar **err_info _U_)
return 1;
}
-/* Find the next packet and parse it; called from wtap_loop(). */
+/* Find the next packet and parse it; called from wtap_read(). */
static gboolean cosine_read(wtap *wth, int *err, gchar **err_info,
long *data_offset)
{
diff --git a/wiretap/csids.c b/wiretap/csids.c
index cfe1ce7a65..4312c3a4fa 100644
--- a/wiretap/csids.c
+++ b/wiretap/csids.c
@@ -142,7 +142,7 @@ int csids_open(wtap *wth, int *err, gchar **err_info _U_)
return 1;
}
-/* Find the next packet and parse it; called from wtap_loop(). */
+/* Find the next packet and parse it; called from wtap_read(). */
static gboolean csids_read(wtap *wth, int *err, gchar **err_info _U_,
long *data_offset)
{
diff --git a/wiretap/dbs-etherwatch.c b/wiretap/dbs-etherwatch.c
index 8b1a8e834d..7cd7ebc8e3 100644
--- a/wiretap/dbs-etherwatch.c
+++ b/wiretap/dbs-etherwatch.c
@@ -203,7 +203,7 @@ int dbs_etherwatch_open(wtap *wth, int *err, gchar **err_info _U_)
return 1;
}
-/* Find the next packet and parse it; called from wtap_loop(). */
+/* Find the next packet and parse it; called from wtap_read(). */
static gboolean dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info,
long *data_offset)
{
diff --git a/wiretap/eyesdn.c b/wiretap/eyesdn.c
index 90a2ad39b6..73a964d374 100644
--- a/wiretap/eyesdn.c
+++ b/wiretap/eyesdn.c
@@ -159,7 +159,7 @@ int eyesdn_open(wtap *wth, int *err, gchar **err_info _U_)
return 1;
}
-/* Find the next packet and parse it; called from wtap_loop() and wtap_read(). */
+/* Find the next packet and parse it; called from wtap_read(). */
static gboolean eyesdn_read(wtap *wth, int *err, gchar **err_info,
long *data_offset)
{
diff --git a/wiretap/pppdump.c b/wiretap/pppdump.c
index 006828d92d..72061bdcd9 100644
--- a/wiretap/pppdump.c
+++ b/wiretap/pppdump.c
@@ -310,7 +310,7 @@ pppdump_open(wtap *wth, int *err, gchar **err_info _U_)
return 1;
}
-/* Find the next packet and parse it; called from wtap_loop(). */
+/* Find the next packet and parse it; called from wtap_read(). */
static gboolean
pppdump_read(wtap *wth, int *err, gchar **err_info, long *data_offset)
{
diff --git a/wiretap/toshiba.c b/wiretap/toshiba.c
index 1c4121aab4..086ed50be8 100644
--- a/wiretap/toshiba.c
+++ b/wiretap/toshiba.c
@@ -230,7 +230,7 @@ int toshiba_open(wtap *wth, int *err, gchar **err_info _U_)
return 1;
}
-/* Find the next packet and parse it; called from wtap_loop(). */
+/* Find the next packet and parse it; called from wtap_read(). */
static gboolean toshiba_read(wtap *wth, int *err, gchar **err_info,
long *data_offset)
{
diff --git a/wiretap/vms.c b/wiretap/vms.c
index 96262d3efe..fccd4b1c13 100644
--- a/wiretap/vms.c
+++ b/wiretap/vms.c
@@ -275,7 +275,7 @@ int vms_open(wtap *wth, int *err, gchar **err_info _U_)
return 1;
}
-/* Find the next packet and parse it; called from wtap_loop(). */
+/* Find the next packet and parse it; called from wtap_read(). */
static gboolean vms_read(wtap *wth, int *err, gchar **err_info,
long *data_offset)
{
diff --git a/wiretap/wtap.c b/wiretap/wtap.c
index e5a1c0dcb5..78b629a4fa 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -447,29 +447,6 @@ wtap_buf_ptr(wtap *wth)
}
gboolean
-wtap_loop(wtap *wth, int count, wtap_handler callback, guchar* user, int *err,
- gchar **err_info)
-{
- long data_offset;
- int loop = 0;
-
- /* Start by clearing error flag */
- *err = 0;
-
- while ( (wtap_read(wth, err, err_info, &data_offset)) ) {
- callback(user, &wth->phdr, data_offset,
- &wth->pseudo_header, buffer_start_ptr(wth->frame_buffer));
- if (count > 0 && ++loop >= count)
- break;
- }
-
- if (*err == 0)
- return TRUE; /* success */
- else
- return FALSE; /* failure */
-}
-
-gboolean
wtap_seek_read(wtap *wth, long seek_off,
union wtap_pseudo_header *pseudo_header, guint8 *pd, int len,
int *err, gchar **err_info)
diff --git a/wiretap/wtap.def b/wiretap/wtap.def
index 3e847a3bba..1554ebefc4 100644
--- a/wiretap/wtap.def
+++ b/wiretap/wtap.def
@@ -17,7 +17,6 @@ wtap_file_type_short_string
wtap_file_type_string
wtap_get_bytes_dumped
wtap_set_bytes_dumped
-wtap_loop
wtap_open_offline
wtap_pcap_encap_to_wtap_encap
wtap_phdr
diff --git a/wiretap/wtap.h b/wiretap/wtap.h
index 730ce7909e..85b3030a14 100644
--- a/wiretap/wtap.h
+++ b/wiretap/wtap.h
@@ -457,9 +457,6 @@ struct wtap_pkthdr {
int pkt_encap;
};
-typedef void (*wtap_handler)(guchar*, const struct wtap_pkthdr*,
- long, union wtap_pseudo_header *pseudo_header, const guchar *);
-
struct wtap;
struct Buffer;
struct wtap_dumper;
@@ -478,11 +475,6 @@ typedef struct wtap_dumper wtap_dumper;
struct wtap* wtap_open_offline(const char *filename, int *err,
gchar **err_info, gboolean do_random);
-/* Returns TRUE if entire loop-reading was successful. If read failure
- * happened, FALSE is returned and err is set. */
-gboolean wtap_loop(wtap *wth, int, wtap_handler, guchar*, int *err,
- gchar **err_info);
-
/* Returns TRUE if read was successful. FALSE if failure. data_offset is
* set the the offset in the file where the data for the read packet is
* located. */