aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap
diff options
context:
space:
mode:
authorMartin Mathieson <martin.r.mathieson@googlemail.com>2009-10-26 12:17:11 +0000
committerMartin Mathieson <martin.r.mathieson@googlemail.com>2009-10-26 12:17:11 +0000
commitbb78c911110cf0c33c5726f42a1e38441922f788 (patch)
treebcb54dd9919622223e662b72d45ae2538f6e5470 /wiretap
parent524d9c2b8b0f64386de99f6c82b793038d810600 (diff)
Get rid of capture.catapult_dct2000, move start time of capture into file_externals instead.
Thanks Guy for helping to simplify this file! svn path=/trunk/; revision=30708
Diffstat (limited to 'wiretap')
-rw-r--r--wiretap/catapult_dct2000.c65
-rw-r--r--wiretap/wtap-int.h6
2 files changed, 31 insertions, 40 deletions
diff --git a/wiretap/catapult_dct2000.c b/wiretap/catapult_dct2000.c
index 33ab05c5d6..f9208ec44d 100644
--- a/wiretap/catapult_dct2000.c
+++ b/wiretap/catapult_dct2000.c
@@ -84,6 +84,10 @@ typedef struct dct2000_file_externals
gchar secondline[MAX_TIMESTAMP_LINE_LENGTH];
gint secondline_length;
+ /* Remember the time at the start of capture */
+ time_t start_secs;
+ guint32 start_usecs;
+
/* Hash table to store text prefix data part of displayed packets.
Records (file offset -> line_prefix_info_t)
N.B. This is only needed for dumping
@@ -202,7 +206,7 @@ int catapult_dct2000_open(wtap *wth, int *err, gchar **err_info _U_)
/***********************************************************/
/* Second line contains file timestamp */
- /* Store this offset in in wth->capture->catapult_dct2000 */
+ /* Store this offset in in file_externals */
read_new_line(wth->fh, &offset, &(file_externals->secondline_length),
linebuff, sizeof linebuff);
@@ -214,10 +218,9 @@ int catapult_dct2000_open(wtap *wth, int *err, gchar **err_info _U_)
return 0;
}
- /* Allocate struct and fill in timestamp */
- wth->capture.catapult_dct2000 = g_malloc(sizeof(catapult_dct2000_t));
- wth->capture.catapult_dct2000->start_secs = timestamp;
- wth->capture.catapult_dct2000->start_usecs = usecs;
+ /* Fill in timestamp */
+ file_externals->start_secs = timestamp;
+ file_externals->start_usecs = usecs;
/* Copy this second line into buffer so could write out later */
g_strlcpy(file_externals->secondline, linebuff, file_externals->secondline_length+1);
@@ -320,7 +323,7 @@ gboolean catapult_dct2000_read(wtap *wth, int *err, gchar **err_info _U_,
char timestamp_string[MAX_TIMESTAMP_LEN+1];
gint64 *pkey = NULL;
- g_snprintf(timestamp_string, 32, "%d.%04d", seconds, useconds/100);
+ g_snprintf(timestamp_string, MAX_TIMESTAMP_LEN, "%d.%04d", seconds, useconds/100);
/* All packets go to Catapult DCT2000 stub dissector */
wth->phdr.pkt_encap = WTAP_ENCAP_CATAPULT_DCT2000;
@@ -334,12 +337,12 @@ gboolean catapult_dct2000_read(wtap *wth, int *err, gchar **err_info _U_,
wth->data_offset = this_offset + line_length + 1;
/* Fill in timestamp (capture base + packet offset) */
- wth->phdr.ts.secs = wth->capture.catapult_dct2000->start_secs + seconds;
- if ((wth->capture.catapult_dct2000->start_usecs + useconds) >= 1000000) {
+ wth->phdr.ts.secs = file_externals->start_secs + seconds;
+ if ((file_externals->start_usecs + useconds) >= 1000000) {
wth->phdr.ts.secs++;
}
wth->phdr.ts.nsecs =
- ((wth->capture.catapult_dct2000->start_usecs + useconds) % 1000000) *1000;
+ ((file_externals->start_usecs + useconds) % 1000000) *1000;
/* Get buffer pointer ready */
buffer_assure_space(wth->frame_buffer,
@@ -476,8 +479,8 @@ catapult_dct2000_seek_read(wtap *wth, gint64 seek_off,
protocol_name, variant_name, outhdr_name)) {
int n;
int stub_offset = 0;
- char timestamp_string[32];
- g_snprintf(timestamp_string, 32, "%d.%04d", seconds, useconds/100);
+ char timestamp_string[MAX_TIMESTAMP_LEN+1];
+ g_snprintf(timestamp_string, MAX_TIMESTAMP_LEN, "%d.%04d", seconds, useconds/100);
/* Make sure all packets go to catapult dct2000 dissector */
wth->phdr.pkt_encap = WTAP_ENCAP_CATAPULT_DCT2000;
@@ -545,11 +548,8 @@ void catapult_dct2000_close(wtap *wth)
/* Free up its line prefix table */
g_hash_table_destroy(file_externals->packet_prefix_table);
- /* And free up file_externals itself */
+ /* Can now free this too */
g_free(file_externals);
-
- /* Also free this capture info */
- g_free(wth->capture.catapult_dct2000);
}
@@ -628,35 +628,32 @@ gboolean catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
(dct2000_file_externals_t*)pseudo_header->dct2000.wth->capture.generic;
if (wdh->dump.dct2000 == NULL) {
- /* Allocate the dct2000-specific dump structure */
- wdh->dump.dct2000 = g_malloc(sizeof(catapult_dct2000_t));
/* Write out saved first line */
- if (! do_fwrite(file_externals->firstline, 1, file_externals->firstline_length, wdh->fh, err)) {
+ if (!do_fwrite(file_externals->firstline, 1, file_externals->firstline_length, wdh->fh, err)) {
return FALSE;
}
- if (! do_fwrite("\n", 1, 1, wdh->fh, err)) {
+ if (!do_fwrite("\n", 1, 1, wdh->fh, err)) {
return FALSE;
}
/* Also write out saved second line with timestamp corresponding to the
opening time of the log.
*/
- if (! do_fwrite(file_externals->secondline, 1, file_externals->secondline_length, wdh->fh, err)) {
+ if (!do_fwrite(file_externals->secondline, 1, file_externals->secondline_length, wdh->fh, err)) {
return FALSE;
}
- if (! do_fwrite("\n", 1, 1, wdh->fh, err)) {
+ if (!do_fwrite("\n", 1, 1, wdh->fh, err)) {
return FALSE;
}
/* Allocate the dct2000-specific dump structure */
- wdh->dump.dct2000 = g_malloc(sizeof(catapult_dct2000_t));
+ wdh->dump.dct2000 = g_malloc(sizeof(dct2000_dump_t));
/* Copy time of beginning of file */
- wdh->dump.dct2000->start_time.secs =
- pseudo_header->dct2000.wth->capture.catapult_dct2000->start_secs;
+ wdh->dump.dct2000->start_time.secs = file_externals->start_secs;
wdh->dump.dct2000->start_time.nsecs =
- (pseudo_header->dct2000.wth->capture.catapult_dct2000->start_usecs * 1000);
+ (file_externals->start_usecs * 1000);
/* Set flag do don't write header out again */
wdh->dump.dct2000->first_packet_written = TRUE;
@@ -671,7 +668,7 @@ gboolean catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
(const void*)&(pseudo_header->dct2000.seek_off));
/* Write out text before timestamp */
- if (! do_fwrite(prefix->before_time, 1, strlen(prefix->before_time), wdh->fh, err)) {
+ if (!do_fwrite(prefix->before_time, 1, strlen(prefix->before_time), wdh->fh, err)) {
return FALSE;
}
@@ -681,17 +678,17 @@ gboolean catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
/* Calculate time of this packet to write, relative to start of dump */
if (phdr->ts.nsecs >= wdh->dump.dct2000->start_time.nsecs) {
g_snprintf(time_string, 16, "%ld.%04d",
- (long)(phdr->ts.secs - wdh->dump.dct2000->start_time.secs),
- (phdr->ts.nsecs - wdh->dump.dct2000->start_time.nsecs) / 100000);
+ (long)(phdr->ts.secs - wdh->dump.dct2000->start_time.secs),
+ (phdr->ts.nsecs - wdh->dump.dct2000->start_time.nsecs) / 100000);
}
else {
g_snprintf(time_string, 16, "%ld.%04u",
- (long)(phdr->ts.secs - wdh->dump.dct2000->start_time.secs-1),
- ((1000000000 + (phdr->ts.nsecs / 100000)) - (wdh->dump.dct2000->start_time.nsecs / 100000)) % 10000);
+ (long)(phdr->ts.secs - wdh->dump.dct2000->start_time.secs-1),
+ ((1000000000 + (phdr->ts.nsecs / 100000)) - (wdh->dump.dct2000->start_time.nsecs / 100000)) % 10000);
}
/* Write out the calculated timestamp */
- if (! do_fwrite(time_string, 1, strlen(time_string), wdh->fh, err)) {
+ if (!do_fwrite(time_string, 1, strlen(time_string), wdh->fh, err)) {
return FALSE;
}
@@ -740,7 +737,7 @@ gboolean catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
/**************************************/
/* Remainder is encapsulated protocol */
- if (! do_fwrite("$", 1, 1, wdh->fh, err)) {
+ if (!do_fwrite("$", 1, 1, wdh->fh, err)) {
return FALSE;
}
@@ -752,7 +749,7 @@ gboolean catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
c[1] = char_from_hex((guchar)(pd[n] & 0x0f));
/* Write both hex chars of byte together */
- if (! do_fwrite(c, 1, 2, wdh->fh, err)) {
+ if (!do_fwrite(c, 1, 2, wdh->fh, err)) {
return FALSE;
}
}
@@ -770,7 +767,7 @@ gboolean catapult_dct2000_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
}
/* End the line */
- if (! do_fwrite("\n", 1, 1, wdh->fh, err)) {
+ if (!do_fwrite("\n", 1, 1, wdh->fh, err)) {
return FALSE;
}
diff --git a/wiretap/wtap-int.h b/wiretap/wtap-int.h
index 6086aa86be..ecfd39477f 100644
--- a/wiretap/wtap-int.h
+++ b/wiretap/wtap-int.h
@@ -149,11 +149,6 @@ typedef struct {
typedef struct _k12_t k12_t;
typedef struct {
- time_t start_secs;
- guint32 start_usecs;
-} catapult_dct2000_t;
-
-typedef struct {
struct wtap_nstime now;
time_t t0;
} mpeg_t;
@@ -200,7 +195,6 @@ struct wtap {
etherpeek_t *etherpeek;
airopeek9_t *airopeek9;
k12_t *k12;
- catapult_dct2000_t *catapult_dct2000;
mpeg_t *mpeg;
nstrace_t *nstrace;
void *generic;