static gboolean cosine_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, guint8 *pd,
int len, int *err, gchar **err_info);
-static int parse_cosine_rec_hdr(wtap *wth, const char *line,
- union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info);
+static int parse_cosine_rec_hdr(struct wtap_pkthdr *phdr, const char *line,
+ int *err, gchar **err_info);
static int parse_cosine_hex_dump(FILE_T fh, int pkt_len, guint8* buf,
int *err, gchar **err_info);
static int parse_single_hex_dump_line(char* rec, guint8 *buf,
/* Seeks to the beginning of the next packet, and returns the
byte offset. Copy the header line to hdr. Returns -1 on failure,
- and sets "*err" to the error, sets "*err_info" to null or an
- additional error string, and sets hdr to NULL. */
+ and sets "*err" to the error and sets "*err_info" to null or an
+ additional error string. */
static gint64 cosine_seek_next_packet(wtap *wth, int *err, gchar **err_info,
char *hdr)
{
if (cur_off == -1) {
/* Error */
*err = file_error(wth->fh, err_info);
- hdr = NULL;
return -1;
}
- if (file_gets(buf, sizeof(buf), wth->fh) != NULL) {
- if (strstr(buf, COSINE_REC_MAGIC_STR1) ||
- strstr(buf, COSINE_REC_MAGIC_STR2)) {
- g_strlcpy(hdr, buf, COSINE_LINE_LENGTH);
- return cur_off;
- }
- } else {
- if (file_eof(wth->fh)) {
- /* We got an EOF. */
- *err = 0;
- } else {
- /* We got an error. */
- *err = file_error(wth->fh, err_info);
- }
- break;
+ if (file_gets(buf, sizeof(buf), wth->fh) == NULL) {
+ *err = file_error(wth->fh, err_info);
+ return -1;
+ }
+ if (strstr(buf, COSINE_REC_MAGIC_STR1) ||
+ strstr(buf, COSINE_REC_MAGIC_STR2)) {
+ g_strlcpy(hdr, buf, COSINE_LINE_LENGTH);
+ return cur_off;
}
}
- hdr = NULL;
return -1;
}
buf[COSINE_LINE_LENGTH-1] = '\0';
for (line = 0; line < COSINE_HEADER_LINES_TO_CHECK; line++) {
- if (file_gets(buf, COSINE_LINE_LENGTH, wth->fh) != NULL) {
-
- reclen = strlen(buf);
- if (reclen < strlen(COSINE_HDR_MAGIC_STR1) ||
- reclen < strlen(COSINE_HDR_MAGIC_STR2)) {
- continue;
- }
-
- if (strstr(buf, COSINE_HDR_MAGIC_STR1) ||
- strstr(buf, COSINE_HDR_MAGIC_STR2)) {
- return TRUE;
- }
- } else {
+ if (file_gets(buf, COSINE_LINE_LENGTH, wth->fh) == NULL) {
/* EOF or error. */
- if (file_eof(wth->fh))
- *err = 0;
- else
- *err = file_error(wth->fh, err_info);
+ *err = file_error(wth->fh, err_info);
return FALSE;
}
+
+ reclen = strlen(buf);
+ if (reclen < strlen(COSINE_HDR_MAGIC_STR1) ||
+ reclen < strlen(COSINE_HDR_MAGIC_STR2)) {
+ continue;
+ }
+
+ if (strstr(buf, COSINE_HDR_MAGIC_STR1) ||
+ strstr(buf, COSINE_HDR_MAGIC_STR2)) {
+ return TRUE;
+ }
}
*err = 0;
return FALSE;
{
/* Look for CoSine header */
if (!cosine_check_file_type(wth, err, err_info)) {
- if (*err == 0)
- return 0;
- else
+ if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
return -1;
+ return 0;
}
if (file_seek(wth->fh, 0L, SEEK_SET, err) == -1) /* rewind */
return FALSE;
/* Parse the header */
- pkt_len = parse_cosine_rec_hdr(wth, line, &wth->phdr.pseudo_header, err,
- err_info);
+ pkt_len = parse_cosine_rec_hdr(&wth->phdr, line, err, err_info);
if (pkt_len == -1)
return FALSE;
struct wtap_pkthdr *phdr, guint8 *pd, int len,
int *err, gchar **err_info)
{
- union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
char line[COSINE_LINE_LENGTH];
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
}
- if (parse_cosine_rec_hdr(NULL, line, pseudo_header, err, err_info) == -1)
+ if (parse_cosine_rec_hdr(phdr, line, err, err_info) == -1)
return FALSE;
return parse_cosine_hex_dump(wth->random_fh, len, pd, err, err_info);
2) output to PE without date and time
l2-tx (FR:3/7/1:1), Length:18, Pro:0, Off:0, Pri:0, RM:0, Err:0 [0x4000, 0x0] */
static int
-parse_cosine_rec_hdr(wtap *wth, const char *line,
- union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
+parse_cosine_rec_hdr(struct wtap_pkthdr *phdr, const char *line,
+ int *err, gchar **err_info)
{
+ union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
int num_items_scanned;
int yy, mm, dd, hr, min, sec, csec, pkt_len;
int pro, off, pri, rm, error;
yy = mm = dd = hr = min = sec = csec = 0;
}
- if (wth) {
+ {
tm.tm_year = yy - 1900;
tm.tm_mon = mm - 1;
tm.tm_mday = dd;
tm.tm_min = min;
tm.tm_sec = sec;
tm.tm_isdst = -1;
- wth->phdr.ts.secs = mktime(&tm);
- wth->phdr.ts.nsecs = csec * 10000000;
- wth->phdr.len = pkt_len;
+ phdr->ts.secs = mktime(&tm);
+ phdr->ts.nsecs = csec * 10000000;
+ phdr->len = pkt_len;
}
/* XXX need to handle other encapsulations like Cisco HDLC,
Frame Relay and ATM */