diff options
author | Jakub Zawadzki <darkjames-ws@darkjames.pl> | 2012-10-17 20:28:22 +0000 |
---|---|---|
committer | Jakub Zawadzki <darkjames-ws@darkjames.pl> | 2012-10-17 20:28:22 +0000 |
commit | 6b5045dd7b15c2b405e125bba24afae1410dcde2 (patch) | |
tree | 1abfe076c33148ad44fab0144357c8b36969d583 /wiretap | |
parent | 016a518728a09941d15b3cc930ea7a0cff969881 (diff) |
Fill some phdr values also when doing random read
svn path=/trunk/; revision=45619
Diffstat (limited to 'wiretap')
-rw-r--r-- | wiretap/commview.c | 86 | ||||
-rw-r--r-- | wiretap/cosine.c | 23 | ||||
-rw-r--r-- | wiretap/erf.c | 14 | ||||
-rw-r--r-- | wiretap/eyesdn.c | 69 | ||||
-rw-r--r-- | wiretap/netscreen.c | 37 | ||||
-rw-r--r-- | wiretap/nettl.c | 11 | ||||
-rw-r--r-- | wiretap/toshiba.c | 37 | ||||
-rw-r--r-- | wiretap/wtap.c | 15 |
8 files changed, 133 insertions, 159 deletions
diff --git a/wiretap/commview.c b/wiretap/commview.c index 1a95056f08..f84153791b 100644 --- a/wiretap/commview.c +++ b/wiretap/commview.c @@ -128,36 +128,58 @@ int commview_open(wtap *wth, int *err, gchar **err_info) return 1; /* Our kind of file */ } -static void -commview_set_pseudo_header(commview_header_t *cv_hdrp, union wtap_pseudo_header - *pseudo_header) +static gboolean +commview_set_packet_header(const commview_header_t *cv_hdrp, struct wtap_pkthdr *phdr) { + union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; + struct tm tm; + + phdr->len = cv_hdrp->data_len; + phdr->caplen = cv_hdrp->data_len; + + tm.tm_year = cv_hdrp->year - 1900; + tm.tm_mon = cv_hdrp->month - 1; + tm.tm_mday = cv_hdrp->day; + tm.tm_hour = cv_hdrp->hours; + tm.tm_min = cv_hdrp->minutes; + tm.tm_sec = cv_hdrp->seconds; + tm.tm_isdst = -1; + + phdr->ts.secs = mktime(&tm); + phdr->ts.nsecs = cv_hdrp->usecs * 1000; + phdr->presence_flags = WTAP_HAS_TS; + switch(cv_hdrp->flags & FLAGS_MEDIUM) { case MEDIUM_ETHERNET : + phdr->pkt_encap = WTAP_ENCAP_ETHERNET; pseudo_header->eth.fcs_len = -1; /* Unknown */ - break; + return TRUE; case MEDIUM_WIFI : + phdr->pkt_encap = WTAP_ENCAP_IEEE_802_11_WITH_RADIO; pseudo_header->ieee_802_11.fcs_len = -1; /* Unknown */ pseudo_header->ieee_802_11.decrypted = FALSE; pseudo_header->ieee_802_11.channel = cv_hdrp->channel; pseudo_header->ieee_802_11.data_rate = cv_hdrp->rate | (cv_hdrp->direction << 8); pseudo_header->ieee_802_11.signal_level = cv_hdrp->signal_level_percent; - break; + return TRUE; - default : - /* Token Ring or unknown - no pseudo-header for that */ - break; + case MEDIUM_TOKEN_RING : + phdr->pkt_encap = WTAP_ENCAP_TOKEN_RING; + /* Token Ring - no pseudo-header for that */ + return TRUE; } + + /* unknown - not handled */ + return FALSE; } static gboolean commview_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { commview_header_t cv_hdr; - struct tm tm; int bytes_read; *data_offset = file_tell(wth->fh); @@ -165,29 +187,13 @@ commview_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) if(!commview_read_header(&cv_hdr, wth->fh, err, err_info)) return FALSE; - switch(cv_hdr.flags & FLAGS_MEDIUM) { - - case MEDIUM_ETHERNET : - wth->phdr.pkt_encap = WTAP_ENCAP_ETHERNET; - break; - - case MEDIUM_WIFI : - wth->phdr.pkt_encap = WTAP_ENCAP_IEEE_802_11_WITH_RADIO; - break; - - case MEDIUM_TOKEN_RING : - wth->phdr.pkt_encap = WTAP_ENCAP_TOKEN_RING; - break; - - default : + if(!commview_set_packet_header(&cv_hdr, &wth->phdr)) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("commview: unsupported encap: %u", cv_hdr.flags & FLAGS_MEDIUM); return FALSE; } - commview_set_pseudo_header(&cv_hdr, &wth->phdr.pseudo_header); - buffer_assure_space(wth->frame_buffer, cv_hdr.data_len); bytes_read = file_read(buffer_start_ptr(wth->frame_buffer), cv_hdr.data_len, wth->fh); @@ -198,22 +204,6 @@ commview_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) return FALSE; } - tm.tm_year = cv_hdr.year - 1900; - tm.tm_mon = cv_hdr.month - 1; - tm.tm_mday = cv_hdr.day; - tm.tm_hour = cv_hdr.hours; - tm.tm_min = cv_hdr.minutes; - tm.tm_sec = cv_hdr.seconds; - tm.tm_isdst = -1; - - wth->phdr.presence_flags = WTAP_HAS_TS; - - wth->phdr.len = cv_hdr.data_len; - wth->phdr.caplen = cv_hdr.data_len; - - wth->phdr.ts.secs = mktime(&tm); - wth->phdr.ts.nsecs = cv_hdr.usecs * 1000; - return TRUE; } @@ -222,7 +212,6 @@ commview_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, guint8 *pd, int length, int *err, gchar **err_info) { - union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; commview_header_t cv_hdr; int bytes_read; @@ -236,13 +225,18 @@ commview_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, return FALSE; } - if(length != cv_hdr.data_len) { + if(!commview_set_packet_header(&cv_hdr, phdr)) { *err = WTAP_ERR_BAD_FILE; - *err_info = g_strdup_printf("commview: record length %u doesn't match requested length %d", cv_hdr.data_len, length); + *err_info = g_strdup_printf("commview: unsupported encap: %u", + cv_hdr.flags & FLAGS_MEDIUM); return FALSE; } - commview_set_pseudo_header(&cv_hdr, pseudo_header); + if(length != (int)phdr->caplen) { + *err = WTAP_ERR_BAD_FILE; + *err_info = g_strdup_printf("commview: record length %u doesn't match requested length %d", phdr->caplen, length); + return FALSE; + } bytes_read = file_read(pd, cv_hdr.data_len, wth->random_fh); if(bytes_read != cv_hdr.data_len) { diff --git a/wiretap/cosine.c b/wiretap/cosine.c index 73f305fd91..b2ad78daf4 100644 --- a/wiretap/cosine.c +++ b/wiretap/cosine.c @@ -173,8 +173,8 @@ static gboolean cosine_read(wtap *wth, int *err, gchar **err_info, 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, @@ -317,8 +317,7 @@ static gboolean cosine_read(wtap *wth, int *err, gchar **err_info, 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; @@ -343,7 +342,6 @@ cosine_seek_read (wtap *wth, gint64 seek_off, 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) @@ -357,7 +355,7 @@ cosine_seek_read (wtap *wth, gint64 seek_off, 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); @@ -369,9 +367,10 @@ cosine_seek_read (wtap *wth, gint64 seek_off, 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; @@ -410,7 +409,7 @@ parse_cosine_rec_hdr(wtap *wth, const char *line, yy = mm = dd = hr = min = sec = csec = 0; } - if (wth) { + { tm.tm_year = yy - 1900; tm.tm_mon = mm - 1; tm.tm_mday = dd; @@ -418,9 +417,9 @@ parse_cosine_rec_hdr(wtap *wth, const char *line, 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 */ diff --git a/wiretap/erf.c b/wiretap/erf.c index 54f8c945f7..3bf9df54de 100644 --- a/wiretap/erf.c +++ b/wiretap/erf.c @@ -60,7 +60,6 @@ static int erf_read_header(FILE_T fh, struct wtap_pkthdr *phdr, - union wtap_pseudo_header *pseudo_header, erf_header_t *erf_header, int *err, gchar **err_info, @@ -290,7 +289,7 @@ static gboolean erf_read(wtap *wth, int *err, gchar **err_info, do { if (!erf_read_header(wth->fh, - &wth->phdr, &wth->phdr.pseudo_header, &erf_header, + &wth->phdr, &erf_header, err, err_info, &bytes_read, &packet_size)) { return FALSE; } @@ -309,7 +308,6 @@ static gboolean erf_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, guint8 *pd, int length _U_, int *err, gchar **err_info) { - union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; erf_header_t erf_header; guint32 packet_size; @@ -317,7 +315,7 @@ static gboolean erf_seek_read(wtap *wth, gint64 seek_off, return FALSE; do { - if (!erf_read_header(wth->random_fh, NULL, pseudo_header, &erf_header, + if (!erf_read_header(wth->random_fh, phdr, &erf_header, err, err_info, NULL, &packet_size)) return FALSE; } while ( erf_header.type == ERF_TYPE_PAD ); @@ -330,13 +328,13 @@ static gboolean erf_seek_read(wtap *wth, gint64 seek_off, static int erf_read_header(FILE_T fh, struct wtap_pkthdr *phdr, - union wtap_pseudo_header *pseudo_header, erf_header_t *erf_header, int *err, gchar **err_info, guint32 *bytes_read, guint32 *packet_size) { + union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; guint32 mc_hdr; guint8 erf_exhdr[8]; guint64 erf_exhdr_sw; @@ -375,7 +373,7 @@ static int erf_read_header(FILE_T fh, } } - if (phdr != NULL) { + { guint64 ts = pletohll(&erf_header->ts); phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID; @@ -422,7 +420,7 @@ static int erf_read_header(FILE_T fh, case ERF_TYPE_INFINIBAND: case ERF_TYPE_INFINIBAND_LINK: #if 0 - if (phdr != NULL) { + { phdr->len = g_htons(erf_header->wlen); phdr->caplen = g_htons(erf_header->wlen); } @@ -476,7 +474,7 @@ static int erf_read_header(FILE_T fh, return FALSE; } - if (phdr != NULL) { + { phdr->len = g_htons(erf_header->wlen); phdr->caplen = MIN( g_htons(erf_header->wlen), g_htons(erf_header->rlen) - (guint32)sizeof(*erf_header) - skiplen ); diff --git a/wiretap/eyesdn.c b/wiretap/eyesdn.c index 841a58d2f7..6f8c835f15 100644 --- a/wiretap/eyesdn.c +++ b/wiretap/eyesdn.c @@ -99,8 +99,8 @@ static gboolean eyesdn_seek_read(wtap *wth, gint64 seek_off, int *err, gchar **err_info); static gboolean parse_eyesdn_packet_data(FILE_T fh, int pkt_len, guint8* buf, int *err, gchar **err_info); -static int parse_eyesdn_rec_hdr(wtap *wth, FILE_T fh, - union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info); +static int parse_eyesdn_rec_hdr(FILE_T fh, + struct wtap_pkthdr *phdr, int *err, gchar **err_info); /* Seeks to the beginning of the next packet, and returns the byte offset. Returns -1 on failure, and sets "*err" to the error @@ -172,8 +172,7 @@ static gboolean eyesdn_read(wtap *wth, int *err, gchar **err_info, return FALSE; /* Parse the header */ - pkt_len = parse_eyesdn_rec_hdr(wth, wth->fh, &wth->phdr.pseudo_header, err, - err_info); + pkt_len = parse_eyesdn_rec_hdr(wth->fh, &wth->phdr, err, err_info); if (pkt_len == -1) return FALSE; @@ -195,14 +194,12 @@ eyesdn_seek_read (wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, guint8 *pd, int len, int *err, gchar **err_info) { - union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; int pkt_len; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; - pkt_len = parse_eyesdn_rec_hdr(NULL, wth->random_fh, pseudo_header, - err, err_info); + pkt_len = parse_eyesdn_rec_hdr(wth->random_fh, phdr, err, err_info); if (pkt_len != len) { if (pkt_len != -1) { @@ -219,9 +216,10 @@ eyesdn_seek_read (wtap *wth, gint64 seek_off, /* Parses a packet record header. */ static int -parse_eyesdn_rec_hdr(wtap *wth, FILE_T fh, - union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info) +parse_eyesdn_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr, + int *err, gchar **err_info) { + union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; guint8 hdr[EYESDN_HDR_LENGTH]; time_t secs; int usecs; @@ -262,28 +260,23 @@ parse_eyesdn_rec_hdr(wtap *wth, FILE_T fh, pseudo_header->isdn.uton = direction & 1; pseudo_header->isdn.channel = channel; if(channel) { /* bearer channels */ - if(wth) { - wth->phdr.pkt_encap = WTAP_ENCAP_ISDN; /* recognises PPP */ + { + phdr->pkt_encap = WTAP_ENCAP_ISDN; /* recognises PPP */ pseudo_header->isdn.uton=!pseudo_header->isdn.uton; /* bug */ } + } else { /* D channel */ - if(wth) { - wth->phdr.pkt_encap = WTAP_ENCAP_ISDN; - } + phdr->pkt_encap = WTAP_ENCAP_ISDN; } break; case EYESDN_ENCAP_MSG: /* Layer 1 message */ - if(wth) { - wth->phdr.pkt_encap = WTAP_ENCAP_LAYER1_EVENT; - } + phdr->pkt_encap = WTAP_ENCAP_LAYER1_EVENT; pseudo_header->l1event.uton = (direction & 1); break; case EYESDN_ENCAP_LAPB: /* X.25 via LAPB */ - if(wth) { - wth->phdr.pkt_encap = WTAP_ENCAP_LAPB; - } + phdr->pkt_encap = WTAP_ENCAP_LAPB; pseudo_header->x25.flags = (direction & 1) ? 0 : 0x80; break; @@ -309,9 +302,7 @@ parse_eyesdn_rec_hdr(wtap *wth, FILE_T fh, } if (file_seek(fh, cur_off, SEEK_SET, err) == -1) return -1; - if(wth) { - wth->phdr.pkt_encap = WTAP_ENCAP_ATM_PDUS_UNTRUNCATED; - } + phdr->pkt_encap = WTAP_ENCAP_ATM_PDUS_UNTRUNCATED; pseudo_header->atm.flags=ATM_RAW_CELL; pseudo_header->atm.aal=AAL_UNKNOWN; pseudo_header->atm.type=TRAF_UMTS_FP; @@ -326,41 +317,31 @@ parse_eyesdn_rec_hdr(wtap *wth, FILE_T fh, pseudo_header->mtp2.sent = direction & 1; pseudo_header->mtp2.annex_a_used = MTP2_ANNEX_A_USED_UNKNOWN; pseudo_header->mtp2.link_number = channel; - if(wth) { - wth->phdr.pkt_encap = WTAP_ENCAP_MTP2_WITH_PHDR; - } + phdr->pkt_encap = WTAP_ENCAP_MTP2_WITH_PHDR; break; case EYESDN_ENCAP_DPNSS: /* DPNSS */ pseudo_header->isdn.uton = direction & 1; pseudo_header->isdn.channel = channel; - if(wth) { - wth->phdr.pkt_encap = WTAP_ENCAP_DPNSS; - } + phdr->pkt_encap = WTAP_ENCAP_DPNSS; break; case EYESDN_ENCAP_DASS2: /* DASS2 frames */ pseudo_header->isdn.uton = direction & 1; pseudo_header->isdn.channel = channel; - if(wth) { - wth->phdr.pkt_encap = WTAP_ENCAP_DPNSS; - } + phdr->pkt_encap = WTAP_ENCAP_DPNSS; break; case EYESDN_ENCAP_BACNET: /* BACNET async over HDLC frames */ pseudo_header->isdn.uton = direction & 1; pseudo_header->isdn.channel = channel; - if(wth) { - wth->phdr.pkt_encap = WTAP_ENCAP_BACNET_MS_TP_WITH_PHDR; - } + phdr->pkt_encap = WTAP_ENCAP_BACNET_MS_TP_WITH_PHDR; break; case EYESDN_ENCAP_V5_EF: /* V5EF */ pseudo_header->isdn.uton = direction & 1; pseudo_header->isdn.channel = channel; - if(wth) { - wth->phdr.pkt_encap = WTAP_ENCAP_V5_EF; - } + phdr->pkt_encap = WTAP_ENCAP_V5_EF; break; } @@ -371,12 +352,12 @@ parse_eyesdn_rec_hdr(wtap *wth, FILE_T fh, return -1; } - if (wth) { - wth->phdr.presence_flags = WTAP_HAS_TS; - wth->phdr.ts.secs = secs; - wth->phdr.ts.nsecs = usecs * 1000; - wth->phdr.caplen = pkt_len; - wth->phdr.len = pkt_len; + { + phdr->presence_flags = WTAP_HAS_TS; + phdr->ts.secs = secs; + phdr->ts.nsecs = usecs * 1000; + phdr->caplen = pkt_len; + phdr->len = pkt_len; } return pkt_len; diff --git a/wiretap/netscreen.c b/wiretap/netscreen.c index 15242777c8..a83d90f787 100644 --- a/wiretap/netscreen.c +++ b/wiretap/netscreen.c @@ -65,9 +65,9 @@ static gboolean netscreen_read(wtap *wth, int *err, gchar **err_info, static gboolean netscreen_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, guint8 *pd, int len, int *err, gchar **err_info); -static int parse_netscreen_rec_hdr(wtap *wth, const char *line, +static int parse_netscreen_rec_hdr(struct wtap_pkthdr *phdr, const char *line, char *cap_int, gboolean *cap_dir, char *cap_dst, - union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info); + int *err, gchar **err_info); static int parse_netscreen_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, @@ -230,11 +230,9 @@ static gboolean netscreen_read(wtap *wth, int *err, gchar **err_info, if (offset < 0) return FALSE; - wth->phdr.presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; - /* Parse the header */ - pkt_len = parse_netscreen_rec_hdr(wth, line, cap_int, &cap_dir, cap_dst, - &wth->phdr.pseudo_header, err, err_info); + pkt_len = parse_netscreen_rec_hdr(&wth->phdr, line, cap_int, &cap_dir, cap_dst, + err, err_info); if (pkt_len == -1) return FALSE; @@ -300,11 +298,11 @@ netscreen_seek_read (wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, guint8 *pd, int len, int *err, gchar **err_info) { - union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; char line[NETSCREEN_LINE_LENGTH]; char cap_int[NETSCREEN_MAX_INT_NAME_LENGTH]; gboolean cap_dir; char cap_dst[13]; + int caplen; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) { return FALSE; @@ -318,15 +316,15 @@ netscreen_seek_read (wtap *wth, gint64 seek_off, return FALSE; } - if (parse_netscreen_rec_hdr(NULL, line, cap_int, &cap_dir, cap_dst, - pseudo_header, err, err_info) == -1) { + if (parse_netscreen_rec_hdr(phdr, line, cap_int, &cap_dir, cap_dst, + err, err_info) == -1) { return FALSE; } - if (parse_netscreen_hex_dump(wth->random_fh, len, pd, err, err_info) - == -1) { + caplen = parse_netscreen_hex_dump(wth->random_fh, len, pd, err, err_info); + if (caplen == -1) return FALSE; - } + phdr->caplen = caplen; return TRUE; } @@ -348,15 +346,16 @@ netscreen_seek_read (wtap *wth, gint64 seek_off, */ static int -parse_netscreen_rec_hdr(wtap *wth, const char *line, char *cap_int, - gboolean *cap_dir, char *cap_dst, union wtap_pseudo_header *pseudo_header _U_, - int *err, gchar **err_info) +parse_netscreen_rec_hdr(struct wtap_pkthdr *phdr, const char *line, char *cap_int, + gboolean *cap_dir, char *cap_dst, int *err, gchar **err_info) { int sec; int dsec, pkt_len; char direction[2]; char cap_src[13]; + phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + if (sscanf(line, "%9d.%9d: %15[a-z0-9/:.-](%1[io]) len=%9d:%12s->%12s/", &sec, &dsec, cap_int, direction, &pkt_len, cap_src, cap_dst) < 5) { *err = WTAP_ERR_BAD_FILE; @@ -366,11 +365,9 @@ parse_netscreen_rec_hdr(wtap *wth, const char *line, char *cap_int, *cap_dir = (direction[0] == 'o' ? NETSCREEN_EGRESS : NETSCREEN_INGRESS); - if (wth) { - wth->phdr.ts.secs = sec; - wth->phdr.ts.nsecs = dsec * 100000000; - wth->phdr.len = pkt_len; - } + phdr->ts.secs = sec; + phdr->ts.nsecs = dsec * 100000000; + phdr->len = pkt_len; return pkt_len; } diff --git a/wiretap/nettl.c b/wiretap/nettl.c index 266383062e..2d24815f8f 100644 --- a/wiretap/nettl.c +++ b/wiretap/nettl.c @@ -183,7 +183,7 @@ static gboolean nettl_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, guint8 *pd, int length, int *err, gchar **err_info); static int nettl_read_rec_header(wtap *wth, FILE_T fh, - struct wtap_pkthdr *phdr, union wtap_pseudo_header *pseudo_header, + struct wtap_pkthdr *phdr, int *err, gchar **err_info, gboolean *fddihack); static gboolean nettl_read_rec_data(FILE_T fh, guint8 *pd, int length, int *err, gchar **err_info, gboolean fddihack); @@ -307,7 +307,7 @@ static gboolean nettl_read(wtap *wth, int *err, gchar **err_info, /* Read record header. */ *data_offset = file_tell(wth->fh); - ret = nettl_read_rec_header(wth, wth->fh, &wth->phdr, &wth->phdr.pseudo_header, + ret = nettl_read_rec_header(wth, wth->fh, &wth->phdr, err, err_info, &fddihack); if (ret <= 0) { /* Read error or EOF */ @@ -355,7 +355,6 @@ nettl_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, guint8 *pd, int length, int *err, gchar **err_info) { - union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; int ret; gboolean fddihack=FALSE; @@ -363,7 +362,7 @@ nettl_seek_read(wtap *wth, gint64 seek_off, return FALSE; /* Read record header. */ - ret = nettl_read_rec_header(wth, wth->random_fh, phdr, pseudo_header, + ret = nettl_read_rec_header(wth, wth->random_fh, phdr, err, err_info, &fddihack); if (ret <= 0) { /* Read error or EOF */ @@ -383,9 +382,9 @@ nettl_seek_read(wtap *wth, gint64 seek_off, static int nettl_read_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, - union wtap_pseudo_header *pseudo_header, int *err, - gchar **err_info, gboolean *fddihack) + int *err, gchar **err_info, gboolean *fddihack) { + union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; nettl_t *nettl = (nettl_t *)wth->priv; int bytes_read; struct nettlrec_hdr rec_hdr; diff --git a/wiretap/toshiba.c b/wiretap/toshiba.c index d09f76130c..3b79a07576 100644 --- a/wiretap/toshiba.c +++ b/wiretap/toshiba.c @@ -116,8 +116,8 @@ static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf, guint byte_offset); static gboolean parse_toshiba_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err, gchar **err_info); -static int parse_toshiba_rec_hdr(wtap *wth, FILE_T fh, - union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info); +static int parse_toshiba_rec_hdr(struct wtap_pkthdr *phdr, FILE_T fh, + int *err, gchar **err_info); /* Seeks to the beginning of the next packet, and returns the byte offset. Returns -1 on failure, and sets "*err" to the error @@ -243,8 +243,7 @@ static gboolean toshiba_read(wtap *wth, int *err, gchar **err_info, return FALSE; /* Parse the header */ - pkt_len = parse_toshiba_rec_hdr(wth, wth->fh, &wth->phdr.pseudo_header, - err, err_info); + pkt_len = parse_toshiba_rec_hdr(&wth->phdr, wth->fh, err, err_info); if (pkt_len == -1) return FALSE; @@ -266,14 +265,12 @@ toshiba_seek_read (wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, guint8 *pd, int len, int *err, gchar **err_info) { - union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; int pkt_len; if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET, err) == -1) return FALSE; - pkt_len = parse_toshiba_rec_hdr(NULL, wth->random_fh, pseudo_header, - err, err_info); + pkt_len = parse_toshiba_rec_hdr(phdr, wth->random_fh, err, err_info); if (pkt_len != len) { if (pkt_len != -1) { @@ -289,9 +286,10 @@ toshiba_seek_read (wtap *wth, gint64 seek_off, /* Parses a packet record header. */ static int -parse_toshiba_rec_hdr(wtap *wth, FILE_T fh, - union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info) +parse_toshiba_rec_hdr(struct wtap_pkthdr *phdr, FILE_T fh, + int *err, gchar **err_info) { + union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; char line[TOSHIBA_LINE_LENGTH]; int num_items_scanned; int pkt_len, pktnum, hr, min, sec, csec; @@ -351,32 +349,29 @@ parse_toshiba_rec_hdr(wtap *wth, FILE_T fh, return -1; } - if (wth) { - wth->phdr.presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; - wth->phdr.ts.secs = hr * 3600 + min * 60 + sec; - wth->phdr.ts.nsecs = csec * 10000000; - wth->phdr.caplen = pkt_len; - wth->phdr.len = pkt_len; + { + phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; + phdr->ts.secs = hr * 3600 + min * 60 + sec; + phdr->ts.nsecs = csec * 10000000; + phdr->caplen = pkt_len; + phdr->len = pkt_len; } switch (channel[0]) { case 'B': - if (wth) - wth->phdr.pkt_encap = WTAP_ENCAP_ISDN; + phdr->pkt_encap = WTAP_ENCAP_ISDN; pseudo_header->isdn.uton = (direction[0] == 'T'); pseudo_header->isdn.channel = (guint8) strtol(&channel[1], NULL, 10); break; case 'D': - if (wth) - wth->phdr.pkt_encap = WTAP_ENCAP_ISDN; + phdr->pkt_encap = WTAP_ENCAP_ISDN; pseudo_header->isdn.uton = (direction[0] == 'T'); pseudo_header->isdn.channel = 0; break; default: - if (wth) - wth->phdr.pkt_encap = WTAP_ENCAP_ETHERNET; + phdr->pkt_encap = WTAP_ENCAP_ETHERNET; /* XXX - is there an FCS in the frame? */ pseudo_header->eth.fcs_len = -1; break; diff --git a/wiretap/wtap.c b/wiretap/wtap.c index b5bd6ce2bf..d028f637e5 100644 --- a/wiretap/wtap.c +++ b/wiretap/wtap.c @@ -911,6 +911,17 @@ wtap_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, guint8 *pd, int len, int *err, gchar **err_info) { - return wth->subtype_seek_read(wth, seek_off, phdr, pd, len, - err, err_info); + phdr->presence_flags = 0; + phdr->pkt_encap = wth->file_encap; + phdr->len = phdr->caplen = len; + + if (!wth->subtype_seek_read(wth, seek_off, phdr, pd, len, err, err_info)) + return FALSE; + + if (phdr->caplen > phdr->len) + phdr->caplen = phdr->len; + + /* g_assert(phdr->pkt_encap != WTAP_ENCAP_PER_PACKET); */ + + return TRUE; } |