Rename radcom_process_rec_header() to radcom_process_rec_header() and

move the code to file in a struct wtap_pkthdr there.

svn path=/trunk/; revision=49942
This commit is contained in:
Guy Harris 2013-06-14 23:59:04 +00:00
parent f42e5bc9c0
commit 25d9d55cef
1 changed files with 77 additions and 102 deletions

View File

@ -89,10 +89,10 @@ struct radcomrec_hdr {
static gboolean radcom_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean radcom_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *pkhdr, guint8 *pd, int length,
int *err, gchar **err_info);
static int radcom_read_rec_header(FILE_T fh, struct radcomrec_hdr *hdr,
struct wtap_pkthdr *phdr, guint8 *pd, int length,
int *err, gchar **err_info);
static int radcom_process_rec_header(wtap *wth, FILE_T fh,
struct wtap_pkthdr *phdr, int *err, gchar **err_info);
static gboolean radcom_read_rec_data(FILE_T fh, guint8 *pd, int length,
int *err, gchar **err_info);
@ -259,87 +259,24 @@ static gboolean radcom_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
int ret;
struct radcomrec_hdr hdr;
guint16 data_length, real_length, length;
guint32 sec;
int bytes_read;
struct tm tm;
guint8 phdr[8];
char fcs[2];
/* Read record header. */
*data_offset = file_tell(wth->fh);
ret = radcom_read_rec_header(wth->fh, &hdr, err, err_info);
ret = radcom_process_rec_header(wth, wth->fh, &wth->phdr, err,
err_info);
if (ret <= 0) {
/* Read error or EOF */
return FALSE;
}
data_length = pletohs(&hdr.data_length);
if (data_length == 0) {
/*
* The last record appears to have 0 in its "data_length"
* field, but non-zero values in other fields, so we
* check for that and treat it as an EOF indication.
*/
*err = 0;
return FALSE;
}
length = pletohs(&hdr.length);
real_length = pletohs(&hdr.real_length);
if (wth->file_encap == WTAP_ENCAP_LAPB) {
length -= 2; /* FCS */
real_length -= 2;
}
wth->phdr.presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
wth->phdr.len = real_length;
wth->phdr.caplen = length;
tm.tm_year = pletohs(&hdr.date.year)-1900;
tm.tm_mon = (hdr.date.month&0x0f)-1;
tm.tm_mday = hdr.date.day;
sec = pletohl(&hdr.date.sec);
tm.tm_hour = sec/3600;
tm.tm_min = (sec%3600)/60;
tm.tm_sec = sec%60;
tm.tm_isdst = -1;
wth->phdr.ts.secs = mktime(&tm);
wth->phdr.ts.nsecs = pletohl(&hdr.date.usec) * 1000;
switch (wth->file_encap) {
case WTAP_ENCAP_ETHERNET:
/* XXX - is there an FCS? */
wth->phdr.pseudo_header.eth.fcs_len = -1;
break;
case WTAP_ENCAP_LAPB:
wth->phdr.pseudo_header.x25.flags = (hdr.dce & 0x1) ?
0x00 : FROM_DCE;
break;
case WTAP_ENCAP_ATM_RFC1483:
/*
* XXX - is this stuff a pseudo-header?
* The direction appears to be in the "hdr.dce" field.
*/
if (!radcom_read_rec_data(wth->fh, phdr, sizeof phdr, err,
err_info))
return FALSE; /* Read error */
length -= 8;
wth->phdr.len -= 8;
wth->phdr.caplen -= 8;
break;
}
/*
* Read the packet data.
*/
buffer_assure_space(wth->frame_buffer, length);
if (!radcom_read_rec_data(wth->fh,
buffer_start_ptr(wth->frame_buffer), length, err, err_info))
buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
if (!radcom_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer),
wth->phdr.caplen, err, err_info))
return FALSE; /* Read error */
if (wth->file_encap == WTAP_ENCAP_LAPB) {
@ -362,19 +299,17 @@ static gboolean radcom_read(wtap *wth, int *err, gchar **err_info,
static gboolean
radcom_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *pkhdr, guint8 *pd, int length,
struct wtap_pkthdr *phdr, guint8 *pd, int length,
int *err, gchar **err_info)
{
union wtap_pseudo_header *pseudo_header = &pkhdr->pseudo_header;
int ret;
struct radcomrec_hdr hdr;
guint8 phdr[8];
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
/* Read record header. */
ret = radcom_read_rec_header(wth->random_fh, &hdr, err, err_info);
ret = radcom_process_rec_header(wth, wth->random_fh, phdr, err,
err_info);
if (ret <= 0) {
/* Read error or EOF */
if (ret == 0) {
@ -384,28 +319,6 @@ radcom_seek_read(wtap *wth, gint64 seek_off,
return FALSE;
}
switch (wth->file_encap) {
case WTAP_ENCAP_ETHERNET:
/* XXX - is there an FCS? */
pseudo_header->eth.fcs_len = -1;
break;
case WTAP_ENCAP_LAPB:
pseudo_header->x25.flags = (hdr.dce & 0x1) ? 0x00 : FROM_DCE;
break;
case WTAP_ENCAP_ATM_RFC1483:
/*
* XXX - is this stuff a pseudo-header?
* The direction appears to be in the "hdr.dce" field.
*/
if (!radcom_read_rec_data(wth->random_fh, phdr, sizeof phdr,
err, err_info))
return FALSE; /* Read error */
break;
}
/*
* Read the packet data.
*/
@ -413,14 +326,19 @@ radcom_seek_read(wtap *wth, gint64 seek_off,
}
static int
radcom_read_rec_header(FILE_T fh, struct radcomrec_hdr *hdr, int *err,
gchar **err_info)
radcom_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
int *err, gchar **err_info)
{
struct radcomrec_hdr hdr;
int bytes_read;
guint16 data_length, real_length, length;
guint32 sec;
struct tm tm;
guint8 atmhdr[8];
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(hdr, sizeof *hdr, fh);
if (bytes_read != sizeof *hdr) {
bytes_read = file_read(&hdr, sizeof hdr, fh);
if (bytes_read != sizeof hdr) {
*err = file_error(fh, err_info);
if (*err != 0)
return -1;
@ -430,6 +348,63 @@ radcom_read_rec_header(FILE_T fh, struct radcomrec_hdr *hdr, int *err,
}
return 0;
}
data_length = pletohs(&hdr.data_length);
if (data_length == 0) {
/*
* The last record appears to have 0 in its "data_length"
* field, but non-zero values in other fields, so we
* check for that and treat it as an EOF indication.
*/
*err = 0;
return 0;
}
length = pletohs(&hdr.length);
real_length = pletohs(&hdr.real_length);
phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
tm.tm_year = pletohs(&hdr.date.year)-1900;
tm.tm_mon = (hdr.date.month&0x0f)-1;
tm.tm_mday = hdr.date.day;
sec = pletohl(&hdr.date.sec);
tm.tm_hour = sec/3600;
tm.tm_min = (sec%3600)/60;
tm.tm_sec = sec%60;
tm.tm_isdst = -1;
phdr->ts.secs = mktime(&tm);
phdr->ts.nsecs = pletohl(&hdr.date.usec) * 1000;
switch (wth->file_encap) {
case WTAP_ENCAP_ETHERNET:
/* XXX - is there an FCS? */
phdr->pseudo_header.eth.fcs_len = -1;
break;
case WTAP_ENCAP_LAPB:
phdr->pseudo_header.x25.flags = (hdr.dce & 0x1) ?
0x00 : FROM_DCE;
length -= 2; /* FCS */
real_length -= 2;
break;
case WTAP_ENCAP_ATM_RFC1483:
/*
* XXX - is this stuff a pseudo-header?
* The direction appears to be in the "hdr.dce" field.
*/
if (!radcom_read_rec_data(wth->fh, atmhdr, sizeof atmhdr, err,
err_info))
return -1; /* Read error */
length -= 8;
real_length -= 8;
break;
}
phdr->len = real_length;
phdr->caplen = length;
return 1;
}