Ethereal-dev: [ethereal-dev] Patch to remove pseudo-header from "frame_data" structure
Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.
From: Guy Harris <gharris@xxxxxxxxxxxx>
Date: Sun, 30 Apr 2000 23:26:59 -0700
This patch removes the pseudo-header from the "frame_data" structure, to reduce the memory use for those structures (which is probably significant for very large capture files). It requires a fair bit of change, though, as it means that the code to do random access to a capture file must, at least for capture files with data that gets put into a pseudo-header, seek not to the beginning of the frame data, but to a point in the file at or after which the data that gets put into the pseudo-header appears. (That's why it touches a lot of Wiretap.) In addition, it requires that the "seek and read" routine be passed a "wtap *", as, to interpret the pseudo-header for at least some file types, the information in the "wtap *" is needed. This means we have to keep the "wtap *" open even after reading through the file sequentially. Pushing more of the "seek and read" function into Wiretap might also make it easier to add support for new forms of compression (e.g., for reading compressed Sniffer files, or reading bzip2'ed files as per Doug Nazar's comment a while ago). I've tested it on most capture file types; I have no nettl files on which to test it, so I was unable to test that.
? errs ? ethereal.core Index: capture.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/capture.c,v retrieving revision 1.99 diff -c -r1.99 capture.c *** capture.c 2000/03/21 06:51:58 1.99 --- capture.c 2000/05/01 06:21:12 *************** *** 910,916 **** whdr.pkt_encap = ld->linktype; /* XXX - do something if this fails */ ! wtap_dump(ld->pdh, &whdr, pd, &err); } /* Set the initial payload to the packet length, and the initial --- 910,916 ---- whdr.pkt_encap = ld->linktype; /* XXX - do something if this fails */ ! wtap_dump(ld->pdh, &whdr, NULL, pd, &err); } /* Set the initial payload to the packet length, and the initial Index: editcap.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/editcap.c,v retrieving revision 1.9 diff -c -r1.9 editcap.c *** editcap.c 2000/04/27 00:31:23 1.9 --- editcap.c 2000/05/01 06:21:13 *************** *** 130,136 **** static void edit_callback(u_char *user, const struct wtap_pkthdr *phdr, int offset, ! const u_char *buf) { callback_arg *argp = (callback_arg *)user; int err; --- 130,136 ---- static void edit_callback(u_char *user, const struct wtap_pkthdr *phdr, int offset, ! union pseudo_header *pseudo_header, const u_char *buf) { callback_arg *argp = (callback_arg *)user; int err; *************** *** 151,157 **** phdr = &snap_phdr; } ! if (!wtap_dump(argp->pdh, phdr, buf, &err)) { fprintf(stderr, "editcap: Error writing to %s: %s\n", argp->filename, wtap_strerror(err)); --- 151,157 ---- 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)); *************** *** 271,277 **** } ! wth = wtap_open_offline(argv[optind], &err); if (!wth) { --- 271,277 ---- } ! wth = wtap_open_offline(argv[optind], &err, FALSE); if (!wth) { Index: file.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/file.c,v retrieving revision 1.183 diff -c -r1.183 file.c *** file.c 2000/04/14 05:39:39 1.183 --- file.c 2000/05/01 06:21:17 *************** *** 94,100 **** static guint32 prevsec, prevusec; static void wtap_dispatch_cb(u_char *, const struct wtap_pkthdr *, int, ! const u_char *); static void freeze_clist(capture_file *cf); static void thaw_clist(capture_file *cf); --- 94,100 ---- static guint32 prevsec, prevusec; static void wtap_dispatch_cb(u_char *, const struct wtap_pkthdr *, int, ! union pseudo_header *, const u_char *); static void freeze_clist(capture_file *cf); static void thaw_clist(capture_file *cf); *************** *** 118,124 **** int fd; struct stat cf_stat; ! wth = wtap_open_offline(fname, &err); if (wth == NULL) goto fail; --- 118,124 ---- int fd; struct stat cf_stat; ! wth = wtap_open_offline(fname, &err, TRUE); if (wth == NULL) goto fail; *************** *** 142,148 **** init_all_protocols(); cf->wth = wth; - cf->fh = fh; cf->filed = fd; cf->f_len = cf_stat.st_size; --- 142,147 ---- *************** *** 190,199 **** capture file we're closing. */ destroy_packet_wins(); - if (cf->fh) { - file_close(cf->fh); - cf->fh = NULL; - } if (cf->wth) { wtap_close(cf->wth); cf->wth = NULL; --- 189,194 ---- *************** *** 316,326 **** we've looked at all the packets, as we don't know until then whether there's more than one type (and thus whether it's WTAP_ENCAP_PER_PACKET). */ cf->lnk_t = wtap_file_encap(cf->wth); - wtap_close(cf->wth); - cf->wth = NULL; - cf->filed = open(cf->filename, O_RDONLY|O_BINARY); - cf->fh = filed_open(cf->filed, "rb"); cf->current_frame = cf->first_displayed; thaw_clist(cf); --- 311,322 ---- we've looked at all the packets, as we don't know until then whether there's more than one type (and thus whether it's WTAP_ENCAP_PER_PACKET). */ + + /* We're done reading sequentially through the file; close the + sequential I/O side, to free up memory it requires. */ + wtap_sequential_close(cf->wth); + cf->lnk_t = wtap_file_encap(cf->wth); cf->current_frame = cf->first_displayed; thaw_clist(cf); *************** *** 408,419 **** } } - /* Yes, "open_cap_file()" set this - but it set it to a file handle - from Wiretap, which will be closed when we close the file; we - want it to remain open even after that, so that we can read - packet data from it. */ - cf->fh = file_open(fname, "rb"); - gtk_statusbar_push(GTK_STATUSBAR(info_bar), file_ctx, " <live capture in progress>"); } --- 404,409 ---- *************** *** 455,470 **** gtk_clist_moveto(GTK_CLIST(packet_list), GTK_CLIST(packet_list)->rows - 1, -1, 1.0, 1.0); /* Set the file encapsulation type now; we don't know what it is until we've looked at all the packets, as we don't know until then whether there's more than one type (and thus whether it's WTAP_ENCAP_PER_PACKET). */ cf->lnk_t = wtap_file_encap(cf->wth); - /* There's nothing more to read from the capture file - close it. */ - wtap_close(cf->wth); - cf->wth = NULL; - /* Pop the "<live capture in progress>" message off the status bar. */ gtk_statusbar_pop(GTK_STATUSBAR(info_bar), file_ctx); --- 445,460 ---- gtk_clist_moveto(GTK_CLIST(packet_list), GTK_CLIST(packet_list)->rows - 1, -1, 1.0, 1.0); + /* We're done reading sequentially through the file; close the + sequential I/O side, to free up memory it requires. */ + wtap_sequential_close(cf->wth); + /* Set the file encapsulation type now; we don't know what it is until we've looked at all the packets, as we don't know until then whether there's more than one type (and thus whether it's WTAP_ENCAP_PER_PACKET). */ cf->lnk_t = wtap_file_encap(cf->wth); /* Pop the "<live capture in progress>" message off the status bar. */ gtk_statusbar_pop(GTK_STATUSBAR(info_bar), file_ctx); *************** *** 508,514 **** } static void ! add_packet_to_packet_list(frame_data *fdata, capture_file *cf, const u_char *buf) { apply_color_filter_args args; gint i, row; --- 498,505 ---- } static void ! add_packet_to_packet_list(frame_data *fdata, capture_file *cf, ! union pseudo_header *pseudo_header, const u_char *buf) { apply_color_filter_args args; gint i, row; *************** *** 542,548 **** /* Apply the filters */ if (cf->dfcode != NULL || filter_list != NULL) { protocol_tree = proto_tree_create_root(); ! dissect_packet(buf, fdata, protocol_tree); if (cf->dfcode != NULL) fdata->flags.passed_dfilter = dfilter_apply(cf->dfcode, protocol_tree, buf, fdata->cap_len) ? 1 : 0; else --- 533,539 ---- /* Apply the filters */ if (cf->dfcode != NULL || filter_list != NULL) { protocol_tree = proto_tree_create_root(); ! dissect_packet(pseudo_header, buf, fdata, protocol_tree); if (cf->dfcode != NULL) fdata->flags.passed_dfilter = dfilter_apply(cf->dfcode, protocol_tree, buf, fdata->cap_len) ? 1 : 0; else *************** *** 562,568 **** if (enabled_plugins_number > 0) protocol_tree = proto_tree_create_root(); #endif ! dissect_packet(buf, fdata, protocol_tree); fdata->flags.passed_dfilter = 1; #ifdef HAVE_PLUGINS if (protocol_tree) --- 553,559 ---- if (enabled_plugins_number > 0) protocol_tree = proto_tree_create_root(); #endif ! dissect_packet(pseudo_header, buf, fdata, protocol_tree); fdata->flags.passed_dfilter = 1; #ifdef HAVE_PLUGINS if (protocol_tree) *************** *** 640,646 **** static void wtap_dispatch_cb(u_char *user, const struct wtap_pkthdr *phdr, int offset, ! const u_char *buf) { frame_data *fdata; capture_file *cf = (capture_file *) user; int passed; --- 631,637 ---- static void wtap_dispatch_cb(u_char *user, const struct wtap_pkthdr *phdr, int offset, ! union pseudo_header *pseudo_header, const u_char *buf) { frame_data *fdata; capture_file *cf = (capture_file *) user; int passed; *************** *** 683,695 **** fdata->abs_usecs = phdr->ts.tv_usec; fdata->flags.encoding = CHAR_ASCII; fdata->flags.visited = 0; - fdata->pseudo_header = phdr->pseudo_header; fdata->cinfo = NULL; passed = TRUE; if (cf->rfcode) { protocol_tree = proto_tree_create_root(); ! dissect_packet(buf, fdata, protocol_tree); passed = dfilter_apply(cf->rfcode, protocol_tree, buf, fdata->cap_len); proto_tree_free(protocol_tree); } --- 674,685 ---- fdata->abs_usecs = phdr->ts.tv_usec; fdata->flags.encoding = CHAR_ASCII; fdata->flags.visited = 0; fdata->cinfo = NULL; passed = TRUE; if (cf->rfcode) { protocol_tree = proto_tree_create_root(); ! dissect_packet(pseudo_header, buf, fdata, protocol_tree); passed = dfilter_apply(cf->rfcode, protocol_tree, buf, fdata->cap_len); proto_tree_free(protocol_tree); } *************** *** 704,710 **** cf->count++; fdata->num = cf->count; ! add_packet_to_packet_list(fdata, cf, buf); } else { /* XXX - if we didn't have read filters, or if we could avoid allocating the "frame_data" structure until we knew whether --- 694,700 ---- cf->count++; fdata->num = cf->count; ! add_packet_to_packet_list(fdata, cf, pseudo_header, buf); } else { /* XXX - if we didn't have read filters, or if we could avoid allocating the "frame_data" structure until we knew whether *************** *** 837,845 **** count++; ! wtap_seek_read (cf->cd_t, cf->fh, fd->file_off, cf->pd, fd->cap_len); ! add_packet_to_packet_list(fd, cf, cf->pd); } gtk_progress_bar_update(GTK_PROGRESS_BAR(prog_bar), 0); --- 827,836 ---- count++; ! wtap_seek_read (cf->wth, fd->file_off, &cf->pseudo_header, ! cf->pd, fd->cap_len); ! add_packet_to_packet_list(fd, cf, &cf->pseudo_header, cf->pd); } gtk_progress_bar_update(GTK_PROGRESS_BAR(prog_bar), 0); *************** *** 974,980 **** count++; if (fd->flags.passed_dfilter) { ! wtap_seek_read (cf->cd_t, cf->fh, fd->file_off, cf->pd, fd->cap_len); if (print_args->print_summary) { /* Fill in the column information, but don't bother creating the logical protocol tree. */ --- 965,972 ---- count++; if (fd->flags.passed_dfilter) { ! wtap_seek_read (cf->wth, fd->file_off, &cf->pseudo_header, ! cf->pd, fd->cap_len); if (print_args->print_summary) { /* Fill in the column information, but don't bother creating the logical protocol tree. */ *************** *** 982,988 **** for (i = 0; i < fd->cinfo->num_cols; i++) { fd->cinfo->col_data[i][0] = '\0'; } ! dissect_packet(cf->pd, fd, NULL); fill_in_columns(fd); cp = &line_buf[0]; line_len = 0; --- 974,980 ---- for (i = 0; i < fd->cinfo->num_cols; i++) { fd->cinfo->col_data[i][0] = '\0'; } ! dissect_packet(&cf->pseudo_header, cf->pd, fd, NULL); fill_in_columns(fd); cp = &line_buf[0]; line_len = 0; *************** *** 1019,1025 **** /* Create the logical protocol tree. */ protocol_tree = proto_tree_create_root(); ! dissect_packet(cf->pd, fd, protocol_tree); /* Print the information in that tree. */ proto_tree_print(FALSE, print_args, (GNode *)protocol_tree, --- 1011,1017 ---- /* Create the logical protocol tree. */ protocol_tree = proto_tree_create_root(); ! dissect_packet(&cf->pseudo_header, cf->pd, fd, protocol_tree); /* Print the information in that tree. */ proto_tree_print(FALSE, print_args, (GNode *)protocol_tree, *************** *** 1203,1210 **** if (fd->flags.passed_dfilter) { /* Yes. Does it match the search filter? */ protocol_tree = proto_tree_create_root(); ! wtap_seek_read(cf->cd_t, cf->fh, fd->file_off, cf->pd, fd->cap_len); ! dissect_packet(cf->pd, fd, protocol_tree); frame_matched = dfilter_apply(sfcode, protocol_tree, cf->pd, fd->cap_len); proto_tree_free(protocol_tree); if (frame_matched) { --- 1195,1203 ---- if (fd->flags.passed_dfilter) { /* Yes. Does it match the search filter? */ protocol_tree = proto_tree_create_root(); ! wtap_seek_read(cf->wth, fd->file_off, &cf->pseudo_header, ! cf->pd, fd->cap_len); ! dissect_packet(&cf->pseudo_header, cf->pd, fd, protocol_tree); frame_matched = dfilter_apply(sfcode, protocol_tree, cf->pd, fd->cap_len); proto_tree_free(protocol_tree); if (frame_matched) { *************** *** 1321,1334 **** cf->current_frame_is_selected = TRUE; /* Get the data in that frame. */ ! wtap_seek_read (cf->cd_t, cf->fh, fd->file_off, cf->pd, fd->cap_len); /* Create the logical protocol tree. */ if (cf->protocol_tree) proto_tree_free(cf->protocol_tree); cf->protocol_tree = proto_tree_create_root(); proto_tree_is_visible = TRUE; ! dissect_packet(cf->pd, cf->current_frame, cf->protocol_tree); /* Display the GUI protocol tree and hex dump. */ clear_tree_and_hex_views(); --- 1314,1329 ---- cf->current_frame_is_selected = TRUE; /* Get the data in that frame. */ ! wtap_seek_read (cf->wth, fd->file_off, &cf->pseudo_header, ! cf->pd, fd->cap_len); /* Create the logical protocol tree. */ if (cf->protocol_tree) proto_tree_free(cf->protocol_tree); cf->protocol_tree = proto_tree_create_root(); proto_tree_is_visible = TRUE; ! dissect_packet(&cf->pseudo_header, cf->pd, cf->current_frame, ! cf->protocol_tree); /* Display the GUI protocol tree and hex dump. */ clear_tree_and_hex_views(); *************** *** 1412,1417 **** --- 1407,1413 ---- wtap_dumper *pdh; frame_data *fd; struct wtap_pkthdr hdr; + union pseudo_header pseudo_header; guint8 pd[65536]; name_ptr = get_basename(fname); *************** *** 1549,1558 **** hdr.caplen = fd->cap_len; hdr.len = fd->pkt_len; hdr.pkt_encap = fd->lnk_t; ! hdr.pseudo_header = fd->pseudo_header; ! wtap_seek_read(cf->cd_t, cf->fh, fd->file_off, pd, fd->cap_len); ! if (!wtap_dump(pdh, &hdr, pd, &err)) { simple_dialog(ESD_TYPE_WARN, NULL, file_write_error_message(err), fname); wtap_dump_close(pdh, &err); --- 1545,1554 ---- hdr.caplen = fd->cap_len; hdr.len = fd->pkt_len; hdr.pkt_encap = fd->lnk_t; ! wtap_seek_read(cf->wth, fd->file_off, &pseudo_header, ! pd, fd->cap_len); ! if (!wtap_dump(pdh, &hdr, &pseudo_header, pd, &err)) { simple_dialog(ESD_TYPE_WARN, NULL, file_write_error_message(err), fname); wtap_dump_close(pdh, &err); Index: file.h =================================================================== RCS file: /usr/local/cvsroot/ethereal/file.h,v retrieving revision 1.65 diff -c -r1.65 file.h *** file.h 2000/04/03 08:42:45 1.65 --- file.h 2000/05/01 06:21:17 *************** *** 70,76 **** typedef struct bpf_program bpf_prog; typedef struct _capture_file { - FILE_T fh; /* File handle for capture file */ int filed; /* File descriptor of capture file */ gchar *filename; /* Name of capture file */ gboolean is_tempfile; /* Is capture file a temporary file? */ --- 70,75 ---- *************** *** 101,106 **** --- 100,106 ---- #endif gchar *sfilter; /* Search filter string */ gboolean sbackward; /* TRUE if search is backward, FALSE if forward */ + union pseudo_header pseudo_header; /* Packet pseudo_header */ guint8 pd[WTAP_MAX_PACKET_SIZE]; /* Packet data */ GMemChunk *plist_chunk; /* Memory chunk for frame_data structures */ frame_data *plist; /* Packet list */ Index: packet-ascend.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/packet-ascend.c,v retrieving revision 1.10 diff -c -r1.10 packet-ascend.c *** packet-ascend.c 2000/03/27 17:53:18 1.10 --- packet-ascend.c 2000/05/01 06:21:18 *************** *** 32,37 **** --- 32,38 ---- #include <glib.h> #include <string.h> #include "packet.h" + #include "packet-ascend.h" #include "packet-eth.h" #include "packet-ppp.h" *************** *** 52,58 **** {0, NULL } }; void ! dissect_ascend( const u_char *pd, frame_data *fd, proto_tree *tree ) { proto_tree *fh_tree; proto_item *ti; --- 53,60 ---- {0, NULL } }; void ! dissect_ascend( const union pseudo_header *pseudo_header, const u_char *pd, ! frame_data *fd, proto_tree *tree ) { proto_tree *fh_tree; proto_item *ti; *************** *** 73,96 **** ti = proto_tree_add_text(tree, 0, 0, "Lucent/Ascend packet trace" ); fh_tree = proto_item_add_subtree(ti, ett_raw); proto_tree_add_item(fh_tree, hf_link_type, 0, 0, ! fd->pseudo_header.ascend.type); ! if (fd->pseudo_header.ascend.type == ASCEND_PFX_WDD) { proto_tree_add_item(fh_tree, hf_called_number, 0, 0, ! fd->pseudo_header.ascend.call_num); proto_tree_add_item(fh_tree, hf_chunk, 0, 0, ! fd->pseudo_header.ascend.chunk); proto_tree_add_item_hidden(fh_tree, hf_session_id, 0, 0, 0); } else { /* It's wandsession data */ proto_tree_add_item(fh_tree, hf_user_name, 0, 0, ! fd->pseudo_header.ascend.user); proto_tree_add_item(fh_tree, hf_session_id, 0, 0, ! fd->pseudo_header.ascend.sess); proto_tree_add_item_hidden(fh_tree, hf_chunk, 0, 0, 0); } ! proto_tree_add_item(fh_tree, hf_task, 0, 0, fd->pseudo_header.ascend.task); } ! switch (fd->pseudo_header.ascend.type) { case ASCEND_PFX_WDS_X: case ASCEND_PFX_WDS_R: dissect_ppp(pd, 0, fd, tree); --- 75,98 ---- ti = proto_tree_add_text(tree, 0, 0, "Lucent/Ascend packet trace" ); fh_tree = proto_item_add_subtree(ti, ett_raw); proto_tree_add_item(fh_tree, hf_link_type, 0, 0, ! pseudo_header->ascend.type); ! if (pseudo_header->ascend.type == ASCEND_PFX_WDD) { proto_tree_add_item(fh_tree, hf_called_number, 0, 0, ! pseudo_header->ascend.call_num); proto_tree_add_item(fh_tree, hf_chunk, 0, 0, ! pseudo_header->ascend.chunk); proto_tree_add_item_hidden(fh_tree, hf_session_id, 0, 0, 0); } else { /* It's wandsession data */ proto_tree_add_item(fh_tree, hf_user_name, 0, 0, ! pseudo_header->ascend.user); proto_tree_add_item(fh_tree, hf_session_id, 0, 0, ! pseudo_header->ascend.sess); proto_tree_add_item_hidden(fh_tree, hf_chunk, 0, 0, 0); } ! proto_tree_add_item(fh_tree, hf_task, 0, 0, pseudo_header->ascend.task); } ! switch (pseudo_header->ascend.type) { case ASCEND_PFX_WDS_X: case ASCEND_PFX_WDS_R: dissect_ppp(pd, 0, fd, tree); Index: packet-ascend.h =================================================================== RCS file: /usr/local/cvsroot/ethereal/packet-ascend.h,v retrieving revision 1.1 diff -c -r1.1 packet-ascend.h *** packet-ascend.h 2000/02/15 21:01:58 1.1 --- packet-ascend.h 2000/05/01 06:21:18 *************** *** 22,26 **** * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ! ! void dissect_ascend(const u_char *, frame_data *, proto_tree *); --- 22,26 ---- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ! void dissect_ascend(const union pseudo_header *, const u_char *, frame_data *, ! proto_tree *); Index: packet-atm.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/packet-atm.c,v retrieving revision 1.13 diff -c -r1.13 packet-atm.c *** packet-atm.c 2000/03/12 04:47:35 1.13 --- packet-atm.c 2000/05/01 06:21:19 *************** *** 37,42 **** --- 37,43 ---- #include "oui.h" #include "resolv.h" + #include "packet-atm.h" #include "packet-eth.h" #include "packet-llc.h" #include "packet-snmp.h" *************** *** 371,377 **** } static void ! dissect_lane(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) { if (check_col(fd, COL_PROTOCOL)) col_add_str(fd, COL_PROTOCOL, "ATM LANE"); --- 372,379 ---- } static void ! dissect_lane(const union pseudo_header *pseudo_header, const u_char *pd, ! int offset, frame_data *fd, proto_tree *tree) { if (check_col(fd, COL_PROTOCOL)) col_add_str(fd, COL_PROTOCOL, "ATM LANE"); *************** *** 379,385 **** col_add_str(fd, COL_INFO, "ATM LANE"); /* Is it LE Control, 802.3, 802.5, or "none of the above"? */ ! switch (fd->pseudo_header.ngsniffer_atm.AppHLType) { case AHLT_LANE_LE_CTRL: dissect_le_control(pd, offset, fd, tree); --- 381,387 ---- col_add_str(fd, COL_INFO, "ATM LANE"); /* Is it LE Control, 802.3, 802.5, or "none of the above"? */ ! switch (pseudo_header->ngsniffer_atm.AppHLType) { case AHLT_LANE_LE_CTRL: dissect_le_control(pd, offset, fd, tree); *************** *** 478,497 **** * We at least know it's AAL5.... */ static void ! atm_guess_content(const u_char *pd, frame_data *fd) { ! if (fd->pseudo_header.ngsniffer_atm.Vpi == 0) { /* * Traffic on some PVCs with a VPI of 0 and certain * VCIs is of particular types. */ ! switch (fd->pseudo_header.ngsniffer_atm.Vci) { case 5: /* * Signalling AAL. */ ! fd->pseudo_header.ngsniffer_atm.AppTrafType = ATT_AAL_SIGNALLING; return; --- 480,500 ---- * We at least know it's AAL5.... */ static void ! atm_guess_content(union pseudo_header *pseudo_header, const u_char *pd, ! frame_data *fd) { ! if (pseudo_header->ngsniffer_atm.Vpi == 0) { /* * Traffic on some PVCs with a VPI of 0 and certain * VCIs is of particular types. */ ! switch (pseudo_header->ngsniffer_atm.Vci) { case 5: /* * Signalling AAL. */ ! pseudo_header->ngsniffer_atm.AppTrafType = ATT_AAL_SIGNALLING; return; *************** *** 499,505 **** /* * ILMI. */ ! fd->pseudo_header.ngsniffer_atm.AppTrafType |= ATT_HL_ILMI; return; } --- 502,508 ---- /* * ILMI. */ ! pseudo_header->ngsniffer_atm.AppTrafType |= ATT_HL_ILMI; return; } *************** *** 514,530 **** * Looks like a SNAP header; assume it's LLC multiplexed * RFC 1483 traffic. */ ! fd->pseudo_header.ngsniffer_atm.AppTrafType |= ATT_HL_LLCMX; } else { /* * Assume it's LANE. */ ! fd->pseudo_header.ngsniffer_atm.AppTrafType |= ATT_HL_LANE; if (pd[0] == 0xff && pd[1] == 0x00) { /* * Looks like LE Control traffic. */ ! fd->pseudo_header.ngsniffer_atm.AppHLType = AHLT_LANE_LE_CTRL; } else { /* --- 517,533 ---- * Looks like a SNAP header; assume it's LLC multiplexed * RFC 1483 traffic. */ ! pseudo_header->ngsniffer_atm.AppTrafType |= ATT_HL_LLCMX; } else { /* * Assume it's LANE. */ ! pseudo_header->ngsniffer_atm.AppTrafType |= ATT_HL_LANE; if (pd[0] == 0xff && pd[1] == 0x00) { /* * Looks like LE Control traffic. */ ! pseudo_header->ngsniffer_atm.AppHLType = AHLT_LANE_LE_CTRL; } else { /* *************** *** 535,548 **** * still be situations where the user has to * tell us. */ ! fd->pseudo_header.ngsniffer_atm.AppHLType = AHLT_LANE_802_3; } } } void ! dissect_atm(const u_char *pd, frame_data *fd, proto_tree *tree) { int offset = 0; proto_tree *atm_tree; --- 538,552 ---- * still be situations where the user has to * tell us. */ ! pseudo_header->ngsniffer_atm.AppHLType = AHLT_LANE_802_3; } } } void ! dissect_atm(union pseudo_header *pseudo_header, const u_char *pd, ! frame_data *fd, proto_tree *tree) { int offset = 0; proto_tree *atm_tree; *************** *** 550,560 **** guint aal_type; guint hl_type; ! aal_type = fd->pseudo_header.ngsniffer_atm.AppTrafType & ATT_AALTYPE; ! hl_type = fd->pseudo_header.ngsniffer_atm.AppTrafType & ATT_HLTYPE; if (aal_type == ATT_AAL5) { if (hl_type == ATT_HL_UNKNOWN || ! fd->pseudo_header.ngsniffer_atm.AppHLType == AHLT_UNKNOWN) { /* * The joys of a connection-oriented link layer; the type of * traffic may be implied by the connection on which it's --- 554,564 ---- guint aal_type; guint hl_type; ! aal_type = pseudo_header->ngsniffer_atm.AppTrafType & ATT_AALTYPE; ! hl_type = pseudo_header->ngsniffer_atm.AppTrafType & ATT_HLTYPE; if (aal_type == ATT_AAL5) { if (hl_type == ATT_HL_UNKNOWN || ! pseudo_header->ngsniffer_atm.AppHLType == AHLT_UNKNOWN) { /* * The joys of a connection-oriented link layer; the type of * traffic may be implied by the connection on which it's *************** *** 575,594 **** * by which the user can specify what sort of traffic is on a * particular circuit. */ ! atm_guess_content(pd, fd); /* * OK, now get the AAL type and high-layer type again. */ ! aal_type = fd->pseudo_header.ngsniffer_atm.AppTrafType & ATT_AALTYPE; ! hl_type = fd->pseudo_header.ngsniffer_atm.AppTrafType & ATT_HLTYPE; } } if (check_col(fd, COL_PROTOCOL)) col_add_str(fd, COL_PROTOCOL, "ATM"); ! switch (fd->pseudo_header.ngsniffer_atm.channel) { case 0: /* Traffic from DCE to DTE. */ --- 579,598 ---- * by which the user can specify what sort of traffic is on a * particular circuit. */ ! atm_guess_content(pseudo_header, pd, fd); /* * OK, now get the AAL type and high-layer type again. */ ! aal_type = pseudo_header->ngsniffer_atm.AppTrafType & ATT_AALTYPE; ! hl_type = pseudo_header->ngsniffer_atm.AppTrafType & ATT_HLTYPE; } } if (check_col(fd, COL_PROTOCOL)) col_add_str(fd, COL_PROTOCOL, "ATM"); ! switch (pseudo_header->ngsniffer_atm.channel) { case 0: /* Traffic from DCE to DTE. */ *************** *** 635,662 **** case ATT_HL_VCMX: proto_tree_add_text(atm_tree, 0, 0, "VC multiplexed traffic type: %s", ! val_to_str(fd->pseudo_header.ngsniffer_atm.AppHLType, vcmx_type_vals, "Unknown VCMX traffic type (%x)")); break; case ATT_HL_LANE: proto_tree_add_text(atm_tree, 0, 0, "LANE traffic type: %s", ! val_to_str(fd->pseudo_header.ngsniffer_atm.AppHLType, lane_type_vals, "Unknown LANE traffic type (%x)")); break; case ATT_HL_IPSILON: proto_tree_add_text(atm_tree, 0, 0, "Ipsilon traffic type: %s", ! val_to_str(fd->pseudo_header.ngsniffer_atm.AppHLType, ipsilon_type_vals, "Unknown Ipsilon traffic type (%x)")); break; } } proto_tree_add_item(atm_tree, hf_atm_vpi, 0, 0, ! fd->pseudo_header.ngsniffer_atm.Vpi); proto_tree_add_item(atm_tree, hf_atm_vci, 0, 0, ! fd->pseudo_header.ngsniffer_atm.Vci); ! switch (fd->pseudo_header.ngsniffer_atm.channel) { case 0: /* Traffic from DCE to DTE. */ --- 639,666 ---- case ATT_HL_VCMX: proto_tree_add_text(atm_tree, 0, 0, "VC multiplexed traffic type: %s", ! val_to_str(pseudo_header->ngsniffer_atm.AppHLType, vcmx_type_vals, "Unknown VCMX traffic type (%x)")); break; case ATT_HL_LANE: proto_tree_add_text(atm_tree, 0, 0, "LANE traffic type: %s", ! val_to_str(pseudo_header->ngsniffer_atm.AppHLType, lane_type_vals, "Unknown LANE traffic type (%x)")); break; case ATT_HL_IPSILON: proto_tree_add_text(atm_tree, 0, 0, "Ipsilon traffic type: %s", ! val_to_str(pseudo_header->ngsniffer_atm.AppHLType, ipsilon_type_vals, "Unknown Ipsilon traffic type (%x)")); break; } } proto_tree_add_item(atm_tree, hf_atm_vpi, 0, 0, ! pseudo_header->ngsniffer_atm.Vpi); proto_tree_add_item(atm_tree, hf_atm_vci, 0, 0, ! pseudo_header->ngsniffer_atm.Vci); ! switch (pseudo_header->ngsniffer_atm.channel) { case 0: /* Traffic from DCE to DTE. */ *************** *** 671,680 **** default: /* Sniffers shouldn't provide anything other than 0 or 1. */ proto_tree_add_text(atm_tree, 0, 0, "Channel: %u", ! fd->pseudo_header.ngsniffer_atm.channel); break; } ! if (fd->pseudo_header.ngsniffer_atm.cells != 0) { /* * If the cell count is 0, assume it means we don't know how * many cells it was. --- 675,684 ---- default: /* Sniffers shouldn't provide anything other than 0 or 1. */ proto_tree_add_text(atm_tree, 0, 0, "Channel: %u", ! pseudo_header->ngsniffer_atm.channel); break; } ! if (pseudo_header->ngsniffer_atm.cells != 0) { /* * If the cell count is 0, assume it means we don't know how * many cells it was. *************** *** 687,700 **** * information. */ proto_tree_add_text(atm_tree, 0, 0, "Cells: %u", ! fd->pseudo_header.ngsniffer_atm.cells); if (aal_type == ATT_AAL5) { proto_tree_add_text(atm_tree, 0, 0, "AAL5 U2U: %u", ! fd->pseudo_header.ngsniffer_atm.aal5t_u2u); proto_tree_add_text(atm_tree, 0, 0, "AAL5 len: %u", ! fd->pseudo_header.ngsniffer_atm.aal5t_len); proto_tree_add_text(atm_tree, 0, 0, "AAL5 checksum: 0x%08X", ! fd->pseudo_header.ngsniffer_atm.aal5t_chksum); } } } --- 691,704 ---- * information. */ proto_tree_add_text(atm_tree, 0, 0, "Cells: %u", ! pseudo_header->ngsniffer_atm.cells); if (aal_type == ATT_AAL5) { proto_tree_add_text(atm_tree, 0, 0, "AAL5 U2U: %u", ! pseudo_header->ngsniffer_atm.aal5t_u2u); proto_tree_add_text(atm_tree, 0, 0, "AAL5 len: %u", ! pseudo_header->ngsniffer_atm.aal5t_len); proto_tree_add_text(atm_tree, 0, 0, "AAL5 checksum: 0x%08X", ! pseudo_header->ngsniffer_atm.aal5t_chksum); } } } *************** *** 716,722 **** break; case ATT_HL_LANE: ! dissect_lane(pd, offset, fd, tree); break; case ATT_HL_ILMI: --- 720,726 ---- break; case ATT_HL_LANE: ! dissect_lane(pseudo_header, pd, offset, fd, tree); break; case ATT_HL_ILMI: Index: packet-atm.h =================================================================== RCS file: /usr/local/cvsroot/ethereal/packet-atm.h,v retrieving revision 1.1 diff -c -r1.1 packet-atm.h *** packet-atm.h 2000/02/15 21:02:01 1.1 --- packet-atm.h 2000/05/01 06:21:19 *************** *** 22,26 **** * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ! ! void dissect_atm(const u_char *, frame_data *, proto_tree *); --- 22,26 ---- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ! void dissect_atm(union pseudo_header *, const u_char *, frame_data *, ! proto_tree *); Index: packet-lapb.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/packet-lapb.c,v retrieving revision 1.12 diff -c -r1.12 packet-lapb.c *** packet-lapb.c 2000/03/15 19:17:08 1.12 --- packet-lapb.c 2000/05/01 06:21:20 *************** *** 36,41 **** --- 36,42 ---- #include <glib.h> #include <string.h> #include "packet.h" + #include "packet-lapb.h" #include "packet-x25.h" #include "xdlc.h" *************** *** 49,55 **** static gint ett_lapb_control = -1; void ! dissect_lapb(const u_char *pd, frame_data *fd, proto_tree *tree) { proto_tree *lapb_tree, *ti; int is_response; --- 50,57 ---- static gint ett_lapb_control = -1; void ! dissect_lapb(const union pseudo_header *pseudo_header, const u_char *pd, ! frame_data *fd, proto_tree *tree) { proto_tree *lapb_tree, *ti; int is_response; *************** *** 69,75 **** return; } ! if (fd->pseudo_header.x25.flags & FROM_DCE) { if(check_col(fd, COL_RES_DL_DST)) col_add_str(fd, COL_RES_DL_DST, "DTE"); if(check_col(fd, COL_RES_DL_SRC)) --- 71,77 ---- return; } ! if (pseudo_header->x25.flags & FROM_DCE) { if(check_col(fd, COL_RES_DL_DST)) col_add_str(fd, COL_RES_DL_DST, "DTE"); if(check_col(fd, COL_RES_DL_SRC)) *************** *** 82,89 **** col_add_str(fd, COL_RES_DL_SRC, "DTE"); } ! if (((fd->pseudo_header.x25.flags & FROM_DCE) && pd[0] == 0x01) || ! (!(fd->pseudo_header.x25.flags & FROM_DCE) && pd[0] == 0x03)) is_response = TRUE; else is_response = FALSE; --- 84,91 ---- col_add_str(fd, COL_RES_DL_SRC, "DTE"); } ! if (((pseudo_header->x25.flags & FROM_DCE) && pd[0] == 0x01) || ! (!(pseudo_header->x25.flags & FROM_DCE) && pd[0] == 0x03)) is_response = TRUE; else is_response = FALSE; *************** *** 101,107 **** ett_lapb_control, is_response, FALSE); /* not end of frame ==> X.25 */ ! if (fd->cap_len > 2) dissect_x25(pd, 2, fd, tree); } void --- 103,109 ---- ett_lapb_control, is_response, FALSE); /* not end of frame ==> X.25 */ ! if (fd->cap_len > 2) dissect_x25(pseudo_header, pd, 2, fd, tree); } void Index: packet-lapb.h =================================================================== RCS file: /usr/local/cvsroot/ethereal/packet-lapb.h,v retrieving revision 1.1 diff -c -r1.1 packet-lapb.h *** packet-lapb.h 2000/02/15 21:02:30 1.1 --- packet-lapb.h 2000/05/01 06:21:20 *************** *** 22,26 **** * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ! ! void dissect_lapb(const u_char *, frame_data *, proto_tree *); --- 22,26 ---- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ! void dissect_lapb(const union pseudo_header *, const u_char *, frame_data *, ! proto_tree *); Index: packet-lapd.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/packet-lapd.c,v retrieving revision 1.5 diff -c -r1.5 packet-lapd.c *** packet-lapd.c 2000/02/15 21:02:31 1.5 --- packet-lapd.c 2000/05/01 06:21:21 *************** *** 36,41 **** --- 36,42 ---- #include <glib.h> #include <string.h> #include "packet.h" + #include "packet-lapd.h" #include "packet-q931.h" #include "xdlc.h" *************** *** 83,89 **** }; void ! dissect_lapd(const u_char *pd, frame_data *fd, proto_tree *tree) { proto_tree *lapd_tree, *addr_tree; proto_item *ti; --- 84,91 ---- }; void ! dissect_lapd(const union pseudo_header *pseudo_header, const u_char *pd, ! frame_data *fd, proto_tree *tree) { proto_tree *lapd_tree, *addr_tree; proto_item *ti; *************** *** 102,108 **** sapi = (address & LAPD_SAPI) >> LAPD_SAPI_SHIFT; lapd_header_len = 2; /* address */ ! if (fd->pseudo_header.lapd.from_network_to_user) { is_response = cr ? FALSE : TRUE; if(check_col(fd, COL_RES_DL_DST)) col_add_str(fd, COL_RES_DL_DST, "User"); --- 104,110 ---- sapi = (address & LAPD_SAPI) >> LAPD_SAPI_SHIFT; lapd_header_len = 2; /* address */ ! if (pseudo_header->lapd.from_network_to_user) { is_response = cr ? FALSE : TRUE; if(check_col(fd, COL_RES_DL_DST)) col_add_str(fd, COL_RES_DL_DST, "User"); Index: packet-lapd.h =================================================================== RCS file: /usr/local/cvsroot/ethereal/packet-lapd.h,v retrieving revision 1.1 diff -c -r1.1 packet-lapd.h *** packet-lapd.h 2000/02/15 21:02:32 1.1 --- packet-lapd.h 2000/05/01 06:21:21 *************** *** 22,26 **** * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ! ! void dissect_lapd(const u_char *, frame_data *, proto_tree *); --- 22,26 ---- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ! void dissect_lapd(const union pseudo_header *, const u_char *, frame_data *, ! proto_tree *); Index: packet-v120.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/packet-v120.c,v retrieving revision 1.5 diff -c -r1.5 packet-v120.c *** packet-v120.c 2000/03/17 05:21:48 1.5 --- packet-v120.c 2000/05/01 06:21:22 *************** *** 36,41 **** --- 36,42 ---- #include <glib.h> #include <string.h> #include "packet.h" + #include "packet-v120.h" #include "xdlc.h" #define FROM_DCE 0x80 *************** *** 53,59 **** static int dissect_v120_header(const u_char *pd, int offset, frame_data *fd, proto_tree *tree); void ! dissect_v120(const u_char *pd, frame_data *fd, proto_tree *tree) { proto_tree *v120_tree, *ti, *tc, *address_tree; int is_response; --- 54,61 ---- static int dissect_v120_header(const u_char *pd, int offset, frame_data *fd, proto_tree *tree); void ! dissect_v120(const union pseudo_header *pseudo_header, const u_char *pd, ! frame_data *fd, proto_tree *tree) { proto_tree *v120_tree, *ti, *tc, *address_tree; int is_response; *************** *** 77,83 **** return; } ! if (fd->pseudo_header.x25.flags & FROM_DCE) { if(check_col(fd, COL_RES_DL_DST)) col_add_str(fd, COL_RES_DL_DST, "DTE"); if(check_col(fd, COL_RES_DL_SRC)) --- 79,85 ---- return; } ! if (pseudo_header->x25.flags & FROM_DCE) { if(check_col(fd, COL_RES_DL_DST)) col_add_str(fd, COL_RES_DL_DST, "DTE"); if(check_col(fd, COL_RES_DL_SRC)) *************** *** 90,97 **** col_add_str(fd, COL_RES_DL_SRC, "DTE"); } ! if (((fd->pseudo_header.x25.flags & FROM_DCE) && pd[0] & 0x02) || ! (!(fd->pseudo_header.x25.flags & FROM_DCE) && !(pd[0] & 0x02))) is_response = TRUE; else is_response = FALSE; --- 92,99 ---- col_add_str(fd, COL_RES_DL_SRC, "DTE"); } ! if (((pseudo_header->x25.flags & FROM_DCE) && pd[0] & 0x02) || ! (!(pseudo_header->x25.flags & FROM_DCE) && !(pd[0] & 0x02))) is_response = TRUE; else is_response = FALSE; Index: packet-v120.h =================================================================== RCS file: /usr/local/cvsroot/ethereal/packet-v120.h,v retrieving revision 1.1 diff -c -r1.1 packet-v120.h *** packet-v120.h 2000/02/15 21:03:24 1.1 --- packet-v120.h 2000/05/01 06:21:22 *************** *** 22,26 **** * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ! ! void dissect_v120(const u_char *, frame_data *, proto_tree *); --- 22,26 ---- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ! void dissect_v120(const union pseudo_header *, const u_char *, frame_data *, ! proto_tree *); Index: packet-x25.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/packet-x25.c,v retrieving revision 1.24 diff -c -r1.24 packet-x25.c *** packet-x25.c 2000/04/15 22:11:12 1.24 --- packet-x25.c 2000/05/01 06:21:27 *************** *** 38,43 **** --- 38,44 ---- #include <string.h> #include "etypes.h" #include "packet.h" + #include "packet-x25.h" #include "packet-ip.h" #include "packet-osi.h" #include "packet-clnp.h" *************** *** 1365,1371 **** }; void ! dissect_x25(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) { proto_tree *x25_tree=0, *ti; int localoffset=offset; --- 1366,1373 ---- }; void ! dissect_x25(const union pseudo_header *pseudo_header, const u_char *pd, ! int offset, frame_data *fd, proto_tree *tree) { proto_tree *x25_tree=0, *ti; int localoffset=offset; *************** *** 1412,1419 **** case X25_CALL_REQUEST: if (check_col(fd, COL_INFO)) col_add_fstr(fd, COL_INFO, "%s VC:%d", ! (fd->pseudo_header.x25.flags & FROM_DCE) ? "Inc. call" ! : "Call req." , vc); if (x25_tree) { proto_tree_add_item(x25_tree, (modulo == 8) ? hf_x25_lcn : hf_ex25_lcn, --- 1414,1421 ---- case X25_CALL_REQUEST: if (check_col(fd, COL_INFO)) col_add_fstr(fd, COL_INFO, "%s VC:%d", ! (pseudo_header->x25.flags & FROM_DCE) ? "Inc. call" ! : "Call req." , vc); if (x25_tree) { proto_tree_add_item(x25_tree, (modulo == 8) ? hf_x25_lcn : hf_ex25_lcn, *************** *** 1421,1428 **** proto_tree_add_uint_format(x25_tree, (modulo == 8) ? hf_x25_type : hf_ex25_type, localoffset+2, 1, X25_CALL_REQUEST, ! (fd->pseudo_header.x25.flags & FROM_DCE) ? "Incoming call" ! : "Call request"); } localoffset += 3; if (localoffset < x25_pkt_len+offset) /* calling/called addresses */ --- 1423,1430 ---- proto_tree_add_uint_format(x25_tree, (modulo == 8) ? hf_x25_type : hf_ex25_type, localoffset+2, 1, X25_CALL_REQUEST, ! (pseudo_header->x25.flags & FROM_DCE) ? "Incoming call" ! : "Call request"); } localoffset += 3; if (localoffset < x25_pkt_len+offset) /* calling/called addresses */ *************** *** 1524,1531 **** case X25_CALL_ACCEPTED: if(check_col(fd, COL_INFO)) col_add_fstr(fd, COL_INFO, "%s VC:%d", ! (fd->pseudo_header.x25.flags & FROM_DCE) ? "Call conn." ! : "Call acc." , vc); if (x25_tree) { proto_tree_add_item(x25_tree, (modulo == 8) ? hf_x25_lcn : hf_ex25_lcn, --- 1526,1533 ---- case X25_CALL_ACCEPTED: if(check_col(fd, COL_INFO)) col_add_fstr(fd, COL_INFO, "%s VC:%d", ! (pseudo_header->x25.flags & FROM_DCE) ? "Call conn." ! : "Call acc." , vc); if (x25_tree) { proto_tree_add_item(x25_tree, (modulo == 8) ? hf_x25_lcn : hf_ex25_lcn, *************** *** 1533,1540 **** proto_tree_add_uint_format(x25_tree, (modulo == 8) ? hf_x25_type : hf_ex25_type, localoffset+2, 1, X25_CALL_ACCEPTED, ! (fd->pseudo_header.x25.flags & FROM_DCE) ? "Call connected" ! : "Call accepted"); } localoffset += 3; if (localoffset < x25_pkt_len+offset) /* calling/called addresses */ --- 1535,1542 ---- proto_tree_add_uint_format(x25_tree, (modulo == 8) ? hf_x25_type : hf_ex25_type, localoffset+2, 1, X25_CALL_ACCEPTED, ! (pseudo_header->x25.flags & FROM_DCE) ? "Call connected" ! : "Call accepted"); } localoffset += 3; if (localoffset < x25_pkt_len+offset) /* calling/called addresses */ *************** *** 1553,1560 **** case X25_CLEAR_REQUEST: if(check_col(fd, COL_INFO)) { col_add_fstr(fd, COL_INFO, "%s VC:%d %s - %s", ! (fd->pseudo_header.x25.flags & FROM_DCE) ? "Clear ind." ! : "Clear req." , vc, clear_code(pd[localoffset+3]), clear_diag(pd[localoffset+4])); } --- 1555,1562 ---- case X25_CLEAR_REQUEST: if(check_col(fd, COL_INFO)) { col_add_fstr(fd, COL_INFO, "%s VC:%d %s - %s", ! (pseudo_header->x25.flags & FROM_DCE) ? "Clear ind." ! : "Clear req." , vc, clear_code(pd[localoffset+3]), clear_diag(pd[localoffset+4])); } *************** *** 1565,1572 **** proto_tree_add_uint_format(x25_tree, (modulo == 8) ? hf_x25_type : hf_ex25_type, localoffset+2, 1, X25_CLEAR_REQUEST, ! (fd->pseudo_header.x25.flags & FROM_DCE) ? "Clear indication" ! : "Clear request"); if (localoffset+3 < x25_pkt_len+offset) proto_tree_add_text(x25_tree, localoffset+3, 1, "Cause : %s", clear_code(pd[localoffset+3])); --- 1567,1574 ---- proto_tree_add_uint_format(x25_tree, (modulo == 8) ? hf_x25_type : hf_ex25_type, localoffset+2, 1, X25_CLEAR_REQUEST, ! (pseudo_header->x25.flags & FROM_DCE) ? "Clear indication" ! : "Clear request"); if (localoffset+3 < x25_pkt_len+offset) proto_tree_add_text(x25_tree, localoffset+3, 1, "Cause : %s", clear_code(pd[localoffset+3])); *************** *** 1632,1639 **** case X25_RESET_REQUEST: if(check_col(fd, COL_INFO)) { col_add_fstr(fd, COL_INFO, "%s VC:%d %s - Diag.:%d", ! (fd->pseudo_header.x25.flags & FROM_DCE) ? "Reset ind." ! : "Reset req.", vc, reset_code(pd[localoffset+3]), (int)pd[localoffset+4]); } --- 1634,1641 ---- case X25_RESET_REQUEST: if(check_col(fd, COL_INFO)) { col_add_fstr(fd, COL_INFO, "%s VC:%d %s - Diag.:%d", ! (pseudo_header->x25.flags & FROM_DCE) ? "Reset ind." ! : "Reset req.", vc, reset_code(pd[localoffset+3]), (int)pd[localoffset+4]); } *************** *** 1644,1651 **** proto_tree_add_uint_format(x25_tree, (modulo == 8) ? hf_x25_type : hf_ex25_type, localoffset+2, 1, X25_RESET_REQUEST, ! (fd->pseudo_header.x25.flags & FROM_DCE) ? "Reset indication" ! : "Reset request"); if (localoffset+3 < x25_pkt_len+offset) proto_tree_add_text(x25_tree, localoffset+3, 1, "Cause : %s", reset_code(pd[localoffset+3])); --- 1646,1653 ---- proto_tree_add_uint_format(x25_tree, (modulo == 8) ? hf_x25_type : hf_ex25_type, localoffset+2, 1, X25_RESET_REQUEST, ! (pseudo_header->x25.flags & FROM_DCE) ? "Reset indication" ! : "Reset request"); if (localoffset+3 < x25_pkt_len+offset) proto_tree_add_text(x25_tree, localoffset+3, 1, "Cause : %s", reset_code(pd[localoffset+3])); *************** *** 1669,1676 **** case X25_RESTART_REQUEST: if(check_col(fd, COL_INFO)) { col_add_fstr(fd, COL_INFO, "%s %s - Diag.:%d", ! (fd->pseudo_header.x25.flags & FROM_DCE) ? "Restart ind." ! : "Restart req.", restart_code(pd[localoffset+3]), (int)pd[localoffset+4]); } --- 1671,1678 ---- case X25_RESTART_REQUEST: if(check_col(fd, COL_INFO)) { col_add_fstr(fd, COL_INFO, "%s %s - Diag.:%d", ! (pseudo_header->x25.flags & FROM_DCE) ? "Restart ind." ! : "Restart req.", restart_code(pd[localoffset+3]), (int)pd[localoffset+4]); } *************** *** 1678,1685 **** proto_tree_add_uint_format(x25_tree, (modulo == 8) ? hf_x25_type : hf_ex25_type, localoffset+2, 1, X25_RESTART_REQUEST, ! (fd->pseudo_header.x25.flags & FROM_DCE) ? "Restart indication" ! : "Restart request"); if (localoffset+3 < x25_pkt_len+offset) proto_tree_add_text(x25_tree, localoffset+3, 1, "Cause : %s", restart_code(pd[localoffset+3])); --- 1680,1687 ---- proto_tree_add_uint_format(x25_tree, (modulo == 8) ? hf_x25_type : hf_ex25_type, localoffset+2, 1, X25_RESTART_REQUEST, ! (pseudo_header->x25.flags & FROM_DCE) ? "Restart indication" ! : "Restart request"); if (localoffset+3 < x25_pkt_len+offset) proto_tree_add_text(x25_tree, localoffset+3, 1, "Cause : %s", restart_code(pd[localoffset+3])); *************** *** 1979,1988 **** proto_register_field_array (proto_ex25, hf128, array_length(hf128)); proto_register_subtree_array(ett, array_length(ett)); register_init_routine(&reinit_x25_hashtable); - } - - void - proto_reg_handoff_x25(void) - { - dissector_add("ethertype", ETHERTYPE_X25L3, dissect_x25); } --- 1981,1984 ---- Index: packet-x25.h =================================================================== RCS file: /usr/local/cvsroot/ethereal/packet-x25.h,v retrieving revision 1.3 diff -c -r1.3 packet-x25.h *** packet-x25.h 2000/02/22 07:42:50 1.3 --- packet-x25.h 2000/05/01 06:21:27 *************** *** 22,26 **** * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ! ! void dissect_x25(const u_char *, int, frame_data *, proto_tree *); --- 22,26 ---- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ! void dissect_x25(const union pseudo_header *, const u_char *, int, frame_data *, ! proto_tree *); Index: packet.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/packet.c,v retrieving revision 1.78 diff -c -r1.78 packet.c *** packet.c 2000/04/19 03:28:07 1.78 --- packet.c 2000/05/01 06:21:29 *************** *** 1109,1115 **** /* this routine checks the frame type from the cf structure */ void ! dissect_packet(const u_char *pd, frame_data *fd, proto_tree *tree) { proto_tree *fh_tree; proto_item *ti; --- 1109,1116 ---- /* this routine checks the frame type from the cf structure */ void ! dissect_packet(union pseudo_header *pseudo_header, const u_char *pd, ! frame_data *fd, proto_tree *tree) { proto_tree *fh_tree; proto_item *ti; *************** *** 1175,1181 **** dissect_ppp(pd, 0, fd, tree); break; case WTAP_ENCAP_LAPB : ! dissect_lapb(pd, fd, tree); break; case WTAP_ENCAP_RAW_IP : dissect_raw(pd, fd, tree); --- 1176,1182 ---- dissect_ppp(pd, 0, fd, tree); break; case WTAP_ENCAP_LAPB : ! dissect_lapb(pseudo_header, pd, fd, tree); break; case WTAP_ENCAP_RAW_IP : dissect_raw(pd, fd, tree); *************** *** 1184,1199 **** dissect_clip(pd, fd, tree); break; case WTAP_ENCAP_ATM_SNIFFER : ! dissect_atm(pd, fd, tree); break; case WTAP_ENCAP_ASCEND : ! dissect_ascend(pd, fd, tree); break; case WTAP_ENCAP_LAPD : ! dissect_lapd(pd, fd, tree); break; case WTAP_ENCAP_V120 : ! dissect_v120(pd, fd, tree); break; } --- 1185,1200 ---- dissect_clip(pd, fd, tree); break; case WTAP_ENCAP_ATM_SNIFFER : ! dissect_atm(pseudo_header, pd, fd, tree); break; case WTAP_ENCAP_ASCEND : ! dissect_ascend(pseudo_header, pd, fd, tree); break; case WTAP_ENCAP_LAPD : ! dissect_lapd(pseudo_header, pd, fd, tree); break; case WTAP_ENCAP_V120 : ! dissect_v120(pseudo_header, pd, fd, tree); break; } Index: packet.h =================================================================== RCS file: /usr/local/cvsroot/ethereal/packet.h,v retrieving revision 1.182 diff -c -r1.182 packet.h *** packet.h 2000/04/18 04:46:07 1.182 --- packet.h 2000/05/01 06:21:30 *************** *** 146,152 **** unsigned int encoding : 2; /* Character encoding (ASCII, EBCDIC...) */ unsigned int visited : 1; /* Has this packet been visited yet? 1=Yes,0=No*/ } flags; - union pseudo_header pseudo_header; /* "pseudo-header" from wiretap */ } frame_data; /* Types of addresses Ethereal knows about. */ --- 146,151 ---- *************** *** 314,320 **** * tree * * They should never modify the packet data. */ ! void dissect_packet(const u_char *, frame_data *, proto_tree *); void dissect_data(const u_char *, int, frame_data *, proto_tree *); --- 313,320 ---- * tree * * They should never modify the packet data. */ ! void dissect_packet(union pseudo_header *, const u_char *, frame_data *, ! proto_tree *); void dissect_data(const u_char *, int, frame_data *, proto_tree *); Index: tethereal.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/tethereal.c,v retrieving revision 1.26 diff -c -r1.26 tethereal.c *** tethereal.c 2000/04/14 05:39:43 1.26 --- tethereal.c 2000/05/01 06:21:32 *************** *** 111,119 **** static int load_cap_file(capture_file *, int); static void wtap_dispatch_cb_write(u_char *, const struct wtap_pkthdr *, int, ! const u_char *); static void wtap_dispatch_cb_print(u_char *, const struct wtap_pkthdr *, int, ! const u_char *); static gchar *col_info(frame_data *, gint); packet_info pi; --- 111,119 ---- static int load_cap_file(capture_file *, int); static void wtap_dispatch_cb_write(u_char *, const struct wtap_pkthdr *, int, ! union pseudo_header *, const u_char *); static void wtap_dispatch_cb_print(u_char *, const struct wtap_pkthdr *, int, ! union pseudo_header *, const u_char *); static gchar *col_info(frame_data *, gint); packet_info pi; *************** *** 197,203 **** cf.plist = NULL; cf.plist_end = NULL; cf.wth = NULL; - cf.fh = NULL; cf.filename = NULL; cf.user_saved = FALSE; cf.is_tempfile = FALSE; --- 197,202 ---- *************** *** 616,627 **** args.cf = &cf; args.pdh = ld->pdh; if (ld->pdh) { ! wtap_dispatch_cb_write((u_char *)&args, &whdr, 0, pd); cf.count++; printf("\r%u ", cf.count); fflush(stdout); } else { ! wtap_dispatch_cb_print((u_char *)&args, &whdr, 0, pd); } } --- 615,626 ---- args.cf = &cf; args.pdh = ld->pdh; if (ld->pdh) { ! wtap_dispatch_cb_write((u_char *)&args, &whdr, 0, NULL, pd); cf.count++; printf("\r%u ", cf.count); fflush(stdout); } else { ! wtap_dispatch_cb_print((u_char *)&args, &whdr, 0, NULL, pd); } } *************** *** 747,753 **** static void fill_in_fdata(frame_data *fdata, capture_file *cf, ! const struct wtap_pkthdr *phdr, int offset) { int i; --- 746,753 ---- static void fill_in_fdata(frame_data *fdata, capture_file *cf, ! const struct wtap_pkthdr *phdr, ! const union pseudo_header *pseudo_header, int offset) { int i; *************** *** 761,767 **** fdata->abs_usecs = phdr->ts.tv_usec; fdata->flags.encoding = CHAR_ASCII; fdata->flags.visited = 0; - fdata->pseudo_header = phdr->pseudo_header; fdata->cinfo = NULL; fdata->num = cf->count; --- 761,766 ---- *************** *** 816,822 **** static void wtap_dispatch_cb_write(u_char *user, const struct wtap_pkthdr *phdr, int offset, ! const u_char *buf) { cb_args_t *args = (cb_args_t *) user; capture_file *cf = args->cf; --- 815,821 ---- static void wtap_dispatch_cb_write(u_char *user, const struct wtap_pkthdr *phdr, int offset, ! union pseudo_header *pseudo_header, const u_char *buf) { cb_args_t *args = (cb_args_t *) user; capture_file *cf = args->cf; *************** *** 828,836 **** cf->count++; if (cf->rfcode) { ! fill_in_fdata(&fdata, cf, phdr, offset); protocol_tree = proto_tree_create_root(); ! dissect_packet(buf, &fdata, protocol_tree); passed = dfilter_apply(cf->rfcode, protocol_tree, buf, fdata.cap_len); } else { protocol_tree = NULL; --- 827,835 ---- cf->count++; if (cf->rfcode) { ! fill_in_fdata(&fdata, cf, phdr, pseudo_header, offset); protocol_tree = proto_tree_create_root(); ! dissect_packet(pseudo_header, buf, &fdata, protocol_tree); passed = dfilter_apply(cf->rfcode, protocol_tree, buf, fdata.cap_len); } else { protocol_tree = NULL; *************** *** 838,844 **** } if (passed) { /* XXX - do something if this fails */ ! wtap_dump(pdh, phdr, buf, &err); } if (protocol_tree != NULL) proto_tree_free(protocol_tree); --- 837,843 ---- } if (passed) { /* XXX - do something if this fails */ ! wtap_dump(pdh, phdr, pseudo_header, buf, &err); } if (protocol_tree != NULL) proto_tree_free(protocol_tree); *************** *** 846,852 **** static void wtap_dispatch_cb_print(u_char *user, const struct wtap_pkthdr *phdr, int offset, ! const u_char *buf) { cb_args_t *args = (cb_args_t *) user; capture_file *cf = args->cf; --- 845,851 ---- static void wtap_dispatch_cb_print(u_char *user, const struct wtap_pkthdr *phdr, int offset, ! union pseudo_header *pseudo_header, const u_char *buf) { cb_args_t *args = (cb_args_t *) user; capture_file *cf = args->cf; *************** *** 857,870 **** cf->count++; ! fill_in_fdata(&fdata, cf, phdr, offset); passed = TRUE; if (cf->rfcode || verbose) protocol_tree = proto_tree_create_root(); else protocol_tree = NULL; ! dissect_packet(buf, &fdata, protocol_tree); if (cf->rfcode) passed = dfilter_apply(cf->rfcode, protocol_tree, buf, fdata.cap_len); if (passed) { --- 856,869 ---- cf->count++; ! fill_in_fdata(&fdata, cf, phdr, pseudo_header, offset); passed = TRUE; if (cf->rfcode || verbose) protocol_tree = proto_tree_create_root(); else protocol_tree = NULL; ! dissect_packet(pseudo_header, buf, &fdata, protocol_tree); if (cf->rfcode) passed = dfilter_apply(cf->rfcode, protocol_tree, buf, fdata.cap_len); if (passed) { *************** *** 998,1004 **** struct stat cf_stat; char err_msg[2048+1]; ! wth = wtap_open_offline(fname, &err); if (wth == NULL) goto fail; --- 997,1003 ---- struct stat cf_stat; char err_msg[2048+1]; ! wth = wtap_open_offline(fname, &err, FALSE); if (wth == NULL) goto fail; *************** *** 1020,1026 **** init_all_protocols(); cf->wth = wth; - cf->fh = fh; cf->filed = fd; cf->f_len = cf_stat.st_size; --- 1019,1024 ---- Index: gtk/main.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/gtk/main.c,v retrieving revision 1.117 diff -c -r1.117 main.c *** main.c 2000/04/14 09:00:25 1.117 --- main.c 2000/05/01 06:21:36 *************** *** 834,847 **** static void packet_list_select_cb(GtkWidget *w, gint row, gint col, gpointer evt) { - #ifdef HAVE_LIBPCAP - if (!sync_mode) { - #endif - if (cf.wth) - return; - #ifdef HAVE_LIBPCAP - } - #endif blank_packetinfo(); select_packet(&cf, row); } --- 834,839 ---- *************** *** 1174,1180 **** cf.plist = NULL; cf.plist_end = NULL; cf.wth = NULL; - cf.fh = NULL; cf.filename = NULL; cf.user_saved = FALSE; cf.is_tempfile = FALSE; --- 1166,1171 ---- Index: gtk/packet_win.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/gtk/packet_win.c,v retrieving revision 1.5 diff -c -r1.5 packet_win.c *** packet_win.c 2000/04/13 20:39:38 1.5 --- packet_win.c 2000/05/01 06:21:37 *************** *** 73,78 **** --- 73,79 ---- struct PacketWinData { gint cap_len; gint encoding; + union pseudo_header pseudo_header; /* Pseudo-header for packet */ guint8 *pd; /* Data for packet */ proto_tree *protocol_tree; /* Protocol tree for packet */ GtkWidget *main; *************** *** 167,176 **** DataPtr->cap_len = cf.current_frame->cap_len; DataPtr->encoding = cf.current_frame->flags.encoding; DataPtr->pd = g_malloc(DataPtr->cap_len); memcpy(DataPtr->pd, cf.pd, DataPtr->cap_len); DataPtr->protocol_tree = proto_tree_create_root(); ! dissect_packet(DataPtr->pd, cf.current_frame, DataPtr->protocol_tree); DataPtr->main = main_w; DataPtr->tv_scrollw = tv_scrollw; DataPtr->tree_view = tree_view; --- 168,179 ---- DataPtr->cap_len = cf.current_frame->cap_len; DataPtr->encoding = cf.current_frame->flags.encoding; + memcpy(&DataPtr->pseudo_header, &cf.pseudo_header, sizeof DataPtr->pseudo_header); DataPtr->pd = g_malloc(DataPtr->cap_len); memcpy(DataPtr->pd, cf.pd, DataPtr->cap_len); DataPtr->protocol_tree = proto_tree_create_root(); ! dissect_packet(&DataPtr->pseudo_header, DataPtr->pd, cf.current_frame, ! DataPtr->protocol_tree); DataPtr->main = main_w; DataPtr->tv_scrollw = tv_scrollw; DataPtr->tree_view = tree_view; Index: wiretap/ascend-grammar.y =================================================================== RCS file: /usr/local/cvsroot/ethereal/wiretap/ascend-grammar.y,v retrieving revision 1.10 diff -c -r1.10 ascend-grammar.y *** ascend-grammar.y 2000/01/22 06:22:35 1.10 --- ascend-grammar.y 2000/05/01 06:21:37 *************** *** 63,69 **** #define NFH_PATH "/dev/null" - extern void ascend_init_lexer(FILE *fh, FILE *nfh); extern int at_eof; int yyparse(void); --- 63,68 ---- *************** *** 232,238 **** /* Parse the capture file. Return the offset of the next packet, or zero if there is none. */ int ! parse_ascend(FILE *fh, void *pd, struct ascend_phdr *phdr, ascend_pkthdr *hdr, int len) { /* yydebug = 1; */ --- 231,237 ---- /* Parse the capture file. Return the offset of the next packet, or zero if there is none. */ int ! parse_ascend(FILE_T *fh, void *pd, struct ascend_phdr *phdr, ascend_pkthdr *hdr, int len) { /* yydebug = 1; */ Index: wiretap/ascend-int.h =================================================================== RCS file: /usr/local/cvsroot/ethereal/wiretap/ascend-int.h,v retrieving revision 1.4 diff -c -r1.4 ascend-int.h *** ascend-int.h 1999/11/24 19:29:45 1.4 --- ascend-int.h 2000/05/01 06:21:38 *************** *** 43,49 **** int ascendlex(void); void init_parse_ascend(void); ! int parse_ascend(FILE *fh, void *pd, struct ascend_phdr *phdr, ascend_pkthdr *hdr, int len); #endif /* ! __ASCEND_INT_H__ */ --- 43,50 ---- int ascendlex(void); void init_parse_ascend(void); ! void ascend_init_lexer(FILE_T *fh, FILE *nfh); ! int parse_ascend(FILE_T *fh, void *pd, struct ascend_phdr *phdr, ascend_pkthdr *hdr, int len); #endif /* ! __ASCEND_INT_H__ */ Index: wiretap/ascend-scanner.l =================================================================== RCS file: /usr/local/cvsroot/ethereal/wiretap/ascend-scanner.l,v retrieving revision 1.13 diff -c -r1.13 ascend-scanner.l *** ascend-scanner.l 2000/02/15 21:06:58 1.13 --- ascend-scanner.l 2000/05/01 06:21:38 *************** *** 253,259 **** int ascendwrap() { return 1; } ! void ascend_init_lexer(FILE *fh, FILE *nfh) { yyrestart(0); yyout = nfh; --- 253,259 ---- int ascendwrap() { return 1; } ! void ascend_init_lexer(FILE_T *fh, FILE *nfh) { yyrestart(0); yyout = nfh; Index: wiretap/ascend.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/wiretap/ascend.c,v retrieving revision 1.13 diff -c -r1.13 ascend.c *** ascend.c 2000/03/22 07:06:56 1.13 --- ascend.c 2000/05/01 06:21:39 *************** *** 82,87 **** --- 82,89 ---- #define ASCEND_W2_SIZE (sizeof ascend_w2magic / sizeof ascend_w2magic[0]) static int ascend_read(wtap *wth, int *err); + static int ascend_seek_read (wtap *wth, int seek_off, + union pseudo_header *pseudo_header, guint8 *pd, int len); static void ascend_close(wtap *wth); /* Seeks to the beginning of the next packet, and returns the *************** *** 150,155 **** --- 152,158 ---- wth->file_type = WTAP_FILE_ASCEND; wth->snapshot_length = ASCEND_MAX_PKT_LEN; wth->subtype_read = ascend_read; + wth->subtype_seek_read = ascend_seek_read; wth->subtype_close = ascend_close; wth->capture.ascend = g_malloc(sizeof(ascend_t)); *************** *** 188,194 **** if (offset < 1) { return 0; } ! if (! parse_ascend(wth->fh, buf, &wth->phdr.pseudo_header.ascend, &header, 0)) { *err = WTAP_ERR_BAD_RECORD; return -1; } --- 191,197 ---- if (offset < 1) { return 0; } ! if (! parse_ascend(wth->fh, buf, &wth->pseudo_header.ascend, &header, 0)) { *err = WTAP_ERR_BAD_RECORD; return -1; } *************** *** 209,218 **** return offset; } ! int ascend_seek_read (FILE *fh, int seek_off, guint8 *pd, int len) { ! file_seek(fh, seek_off - 1, SEEK_SET); ! return parse_ascend(fh, pd, NULL, NULL, len); } static void ascend_close(wtap *wth) --- 212,222 ---- return offset; } ! static int ascend_seek_read (wtap *wth, int seek_off, ! union pseudo_header *pseudo_header, guint8 *pd, int len) { ! file_seek(wth->random_fh, seek_off - 1, SEEK_SET); ! return parse_ascend(wth->random_fh, pd, &pseudo_header->ascend, NULL, len); } static void ascend_close(wtap *wth) Index: wiretap/ascend.h =================================================================== RCS file: /usr/local/cvsroot/ethereal/wiretap/ascend.h,v retrieving revision 1.5 diff -c -r1.5 ascend.h *** ascend.h 2000/01/22 06:22:36 1.5 --- ascend.h 2000/05/01 06:21:39 *************** *** 26,29 **** #define ASCEND_MAX_PKT_LEN (ASCEND_MAX_DATA_ROWS * ASCEND_MAX_DATA_COLS) int ascend_open(wtap *wth, int *err); - int ascend_seek_read (FILE *fh, int seek_off, guint8 *pd, int len); --- 26,28 ---- Index: wiretap/file.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/wiretap/file.c,v retrieving revision 1.49 diff -c -r1.49 file.c *** file.c 2000/03/22 07:06:58 1.49 --- file.c 2000/05/01 06:21:40 *************** *** 96,111 **** i4btrace_open, }; ! int wtap_def_seek_read (FILE *fh, int seek_off, guint8 *pd, int len) { ! file_seek(fh, seek_off, SEEK_SET); ! return file_read(pd, sizeof(guint8), len, fh); } #define N_FILE_TYPES (sizeof open_routines / sizeof open_routines[0]) ! /* Opens a file and prepares a wtap struct */ ! wtap* wtap_open_offline(const char *filename, int *err) { struct stat statb; wtap *wth; --- 96,119 ---- i4btrace_open, }; ! int wtap_def_seek_read(wtap *wth, int seek_off, ! union pseudo_header *pseudo_header, guint8 *pd, int len) { ! file_seek(wth->random_fh, seek_off, SEEK_SET); ! ! return file_read(pd, sizeof(guint8), len, wth->random_fh); } #define N_FILE_TYPES (sizeof open_routines / sizeof open_routines[0]) ! /* Opens a file and prepares a wtap struct. ! If "do_random" is TRUE, it opens the file twice; the second open ! allows the application to do random-access I/O without moving ! the seek offset for sequential I/O, which is used by Ethereal ! so that it can do sequential I/O to a capture file that's being ! written to as new packets arrive independently of random I/O done ! to display protocol trees for packets when they're selected. */ ! wtap* wtap_open_offline(const char *filename, int *err, gboolean do_random) { struct stat statb; wtap *wth; *************** *** 148,153 **** --- 156,171 ---- return NULL; } + if (do_random) { + if (!(wth->random_fh = file_open(filename, "rb"))) { + *err = errno; + file_close(wth->fh); + g_free(wth); + return NULL; + } + } else + wth->random_fh = NULL; + /* initialization */ wth->file_encap = WTAP_ENCAP_UNKNOWN; wth->data_offset = 0; *************** *** 174,179 **** --- 192,199 ---- } /* Well, it's not one of the types of file we know about. */ + if (wth->random_fh != NULL) + file_close(wth->random_fh); file_close(wth->fh); g_free(wth); *err = WTAP_ERR_FILE_UNKNOWN_FORMAT; *************** *** 424,432 **** } gboolean wtap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const u_char *pd, int *err) { ! return (wdh->subtype_write)(wdh, phdr, pd, err); } gboolean wtap_dump_close(wtap_dumper *wdh, int *err) --- 444,452 ---- } gboolean wtap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const union pseudo_header *pseudo_header, const u_char *pd, int *err) { ! return (wdh->subtype_write)(wdh, phdr, pseudo_header, pd, err); } gboolean wtap_dump_close(wtap_dumper *wdh, int *err) Index: wiretap/i4btrace.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/wiretap/i4btrace.c,v retrieving revision 1.4 diff -c -r1.4 i4btrace.c *** i4btrace.c 2000/04/15 21:12:37 1.4 --- i4btrace.c 2000/05/01 06:21:40 *************** *** 33,38 **** --- 33,43 ---- #include "i4b_trace.h" static int i4btrace_read(wtap *wth, int *err); + static int i4btrace_seek_read(wtap *wth, int seek_off, + union pseudo_header *pseudo_header, u_char *pd, int length); + static int i4b_read_rec_header(FILE_T *fh, i4b_trace_hdr_t *hdr, int *err); + static void i4b_byte_swap_header(wtap *wth, i4b_trace_hdr_t *hdr); + static int i4b_read_rec_data(FILE_T *fh, char *pd, int length, int *err); /* * Test some fields in the header to see if they make sense. *************** *** 91,96 **** --- 96,102 ---- wth->file_type = WTAP_FILE_I4BTRACE; wth->capture.i4btrace = g_malloc(sizeof(i4btrace_t)); wth->subtype_read = i4btrace_read; + wth->subtype_seek_read = i4btrace_seek_read; wth->snapshot_length = 2048; /* actual length set per packet */ wth->capture.i4btrace->bchannel_prot[0] = -1; *************** *** 107,145 **** /* Read the next packet */ static int i4btrace_read(wtap *wth, int *err) { ! int bytes_read; i4b_trace_hdr_t hdr; guint16 length; - int data_offset; void *bufp; /* Read record header. */ ! errno = WTAP_ERR_CANT_READ; ! bytes_read = file_read(&hdr, 1, sizeof hdr, wth->fh); ! if (bytes_read != sizeof hdr) { ! *err = file_error(wth->fh); ! if (*err != 0) ! return -1; ! if (bytes_read != 0) { ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } ! return 0; } wth->data_offset += sizeof hdr; ! if (wth->capture.i4btrace->byte_swapped) { ! /* ! * Byte-swap the header. ! */ ! hdr.length = BSWAP32(hdr.length); ! hdr.unit = BSWAP32(hdr.unit); ! hdr.type = BSWAP32(hdr.type); ! hdr.dir = BSWAP32(hdr.dir); ! hdr.trunc = BSWAP32(hdr.trunc); ! hdr.count = BSWAP32(hdr.count); ! hdr.time.tv_sec = BSWAP32(hdr.time.tv_sec); ! hdr.time.tv_usec = BSWAP32(hdr.time.tv_usec); ! } length = hdr.length - sizeof(hdr); if (length == 0) return 0; --- 113,133 ---- /* Read the next packet */ static int i4btrace_read(wtap *wth, int *err) { ! int record_offset; ! int ret; i4b_trace_hdr_t hdr; guint16 length; void *bufp; /* Read record header. */ ! record_offset = wth->data_offset; ! ret = i4b_read_rec_header(wth->fh, &hdr, err); ! if (ret <= 0) { ! /* Read error or EOF */ ! return ret; } wth->data_offset += sizeof hdr; ! i4b_byte_swap_header(wth, &hdr); length = hdr.length - sizeof(hdr); if (length == 0) return 0; *************** *** 150,172 **** wth->phdr.ts.tv_sec = hdr.time.tv_sec; wth->phdr.ts.tv_usec = hdr.time.tv_usec; ! wth->phdr.pseudo_header.x25.flags = (hdr.dir == FROM_TE) ? 0x00 : 0x80; /* * Read the packet data. */ buffer_assure_space(wth->frame_buffer, length); - data_offset = wth->data_offset; - errno = WTAP_ERR_CANT_READ; bufp = buffer_start_ptr(wth->frame_buffer); ! bytes_read = file_read(bufp, 1, length, wth->fh); ! ! if (bytes_read != length) { ! *err = file_error(wth->fh); ! if (*err == 0) ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } wth->data_offset += length; /* --- 138,152 ---- wth->phdr.ts.tv_sec = hdr.time.tv_sec; wth->phdr.ts.tv_usec = hdr.time.tv_usec; ! wth->pseudo_header.x25.flags = (hdr.dir == FROM_TE) ? 0x00 : 0x80; /* * Read the packet data. */ buffer_assure_space(wth->frame_buffer, length); bufp = buffer_start_ptr(wth->frame_buffer); ! if (i4b_read_rec_data(wth->fh, bufp, length, err) < 0) ! return -1; /* Read error */ wth->data_offset += length; /* *************** *** 199,204 **** else wth->phdr.pkt_encap = WTAP_ENCAP_NULL; } ! return data_offset; } --- 179,279 ---- else wth->phdr.pkt_encap = WTAP_ENCAP_NULL; } + + /* + * XXX - there is no file header for i4btrace files, so the + * first record begins at the beginning of the file, hence + * its offset is 0. + * + * Unfortunately, a return value of 0 means "end of file". + * + * Therefore, we return the record offset + 1, and compensate + * for that in "i4btrace_seek_read()". + */ + return record_offset + 1; + } + + static int + i4btrace_seek_read(wtap *wth, int seek_off, + union pseudo_header *pseudo_header, u_char *pd, int length) + { + int ret; + int err; /* XXX - return this */ + i4b_trace_hdr_t hdr; + + /* + * We subtract 1 because we added 1 before returning the record + * offset in "i4btrace_read()"; see the comment above. + */ + file_seek(wth->random_fh, seek_off - 1, SEEK_SET); + + /* Read record header. */ + ret = i4b_read_rec_header(wth->random_fh, &hdr, &err); + if (ret <= 0) { + /* Read error or EOF */ + return ret; + } + i4b_byte_swap_header(wth, &hdr); + + pseudo_header->x25.flags = (hdr.dir == FROM_TE) ? 0x00 : 0x80; + + /* + * Read the packet data. + */ + return i4b_read_rec_data(wth->random_fh, pd, length, &err); + } + + static int + i4b_read_rec_header(FILE_T *fh, i4b_trace_hdr_t *hdr, int *err) + { + int bytes_read; + + errno = WTAP_ERR_CANT_READ; + bytes_read = file_read(hdr, 1, sizeof *hdr, fh); + if (bytes_read != sizeof *hdr) { + *err = file_error(fh); + if (*err != 0) + return -1; + if (bytes_read != 0) { + *err = WTAP_ERR_SHORT_READ; + return -1; + } + return 0; + } + return 1; + } + + static void + i4b_byte_swap_header(wtap *wth, i4b_trace_hdr_t *hdr) + { + if (wth->capture.i4btrace->byte_swapped) { + /* + * Byte-swap the header. + */ + hdr->length = BSWAP32(hdr->length); + hdr->unit = BSWAP32(hdr->unit); + hdr->type = BSWAP32(hdr->type); + hdr->dir = BSWAP32(hdr->dir); + hdr->trunc = BSWAP32(hdr->trunc); + hdr->count = BSWAP32(hdr->count); + hdr->time.tv_sec = BSWAP32(hdr->time.tv_sec); + hdr->time.tv_usec = BSWAP32(hdr->time.tv_usec); + } + } ! static int ! i4b_read_rec_data(FILE_T *fh, char *pd, int length, int *err) ! { ! int bytes_read; ! ! errno = WTAP_ERR_CANT_READ; ! bytes_read = file_read(pd, 1, length, fh); ! ! if (bytes_read != length) { ! *err = file_error(fh); ! if (*err == 0) ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } ! return 0; } Index: wiretap/iptrace.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/wiretap/iptrace.c,v retrieving revision 1.26 diff -c -r1.26 iptrace.c *** iptrace.c 2000/03/30 21:41:11 1.26 --- iptrace.c 2000/05/01 06:21:42 *************** *** 33,41 **** #include "iptrace.h" static int iptrace_read_1_0(wtap *wth, int *err); static int iptrace_read_2_0(wtap *wth, int *err); static int wtap_encap_ift(unsigned int ift); - static void get_atm_pseudo_header(wtap *wth, guint8 *header, guint8 *pd); int iptrace_open(wtap *wth, int *err) { --- 33,50 ---- #include "iptrace.h" static int iptrace_read_1_0(wtap *wth, int *err); + static int iptrace_seek_read_1_0(wtap *wth, int seek_off, + union pseudo_header *pseudo_header, u_char *pd, int packet_size); static int iptrace_read_2_0(wtap *wth, int *err); + static int iptrace_seek_read_2_0(wtap *wth, int seek_off, + union pseudo_header *pseudo_header, u_char *pd, int packet_size); + static int iptrace_read_rec_header(FILE_T *fh, guint8 *header, int header_len, + int *err); + static int iptrace_read_rec_data(FILE_T *fh, guint8 *data_ptr, int packet_size, + int *err); + static void get_atm_pseudo_header(union pseudo_header *pseudo_header, + guint8 *header); static int wtap_encap_ift(unsigned int ift); int iptrace_open(wtap *wth, int *err) { *************** *** 58,67 **** --- 67,78 ---- if (strcmp(name, "iptrace 1.0") == 0) { wth->file_type = WTAP_FILE_IPTRACE_1_0; wth->subtype_read = iptrace_read_1_0; + wth->subtype_seek_read = iptrace_seek_read_1_0; } else if (strcmp(name, "iptrace 2.0") == 0) { wth->file_type = WTAP_FILE_IPTRACE_2_0; wth->subtype_read = iptrace_read_2_0; + wth->subtype_seek_read = iptrace_seek_read_2_0; } else { return 0; *************** *** 88,136 **** /* Read the next packet */ static int iptrace_read_1_0(wtap *wth, int *err) { ! int bytes_read; ! int data_offset; guint32 packet_size; guint8 header[30]; guint8 *data_ptr; iptrace_1_0_phdr pkt_hdr; /* Read the descriptor data */ ! errno = WTAP_ERR_CANT_READ; ! bytes_read = file_read(header, 1, 30, wth->fh); ! if (bytes_read != 30) { ! *err = file_error(wth->fh); ! if (*err != 0) ! return -1; ! if (bytes_read != 0) { ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } ! return 0; } wth->data_offset += 30; /* Read the packet data */ packet_size = pntohl(&header[0]) - 0x16; buffer_assure_space( wth->frame_buffer, packet_size ); - data_offset = wth->data_offset; - errno = WTAP_ERR_CANT_READ; data_ptr = buffer_start_ptr( wth->frame_buffer ); ! bytes_read = file_read( data_ptr, 1, packet_size, wth->fh ); ! ! if (bytes_read != packet_size) { ! *err = file_error(wth->fh); ! if (*err == 0) ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } wth->data_offset += packet_size; - - /* AIX saves time in nsec, not usec. It's easier to make iptrace - * files more Unix-compliant here than try to get the calling - * program to know when to use nsec or usec */ - wth->phdr.len = packet_size; wth->phdr.caplen = packet_size; wth->phdr.ts.tv_sec = pntohl(&header[4]); --- 99,128 ---- /* Read the next packet */ static int iptrace_read_1_0(wtap *wth, int *err) { ! int record_offset; ! int ret; guint32 packet_size; guint8 header[30]; guint8 *data_ptr; iptrace_1_0_phdr pkt_hdr; /* Read the descriptor data */ ! record_offset = wth->data_offset; ! ret = iptrace_read_rec_header(wth->fh, header, 30, err); ! if (ret <= 0) { ! /* Read error or EOF */ ! return ret; } wth->data_offset += 30; /* Read the packet data */ packet_size = pntohl(&header[0]) - 0x16; buffer_assure_space( wth->frame_buffer, packet_size ); data_ptr = buffer_start_ptr( wth->frame_buffer ); ! if (iptrace_read_rec_data(wth->fh, data_ptr, packet_size, err) < 0) ! return -1; /* Read error */ wth->data_offset += packet_size; wth->phdr.len = packet_size; wth->phdr.caplen = packet_size; wth->phdr.ts.tv_sec = pntohl(&header[4]); *************** *** 152,158 **** } if ( wth->phdr.pkt_encap == WTAP_ENCAP_ATM_SNIFFER ) { ! get_atm_pseudo_header(wth, header, data_ptr); } /* If the per-file encapsulation isn't known, set it to this --- 144,150 ---- } if ( wth->phdr.pkt_encap == WTAP_ENCAP_ATM_SNIFFER ) { ! get_atm_pseudo_header(&wth->pseudo_header, header); } /* If the per-file encapsulation isn't known, set it to this *************** *** 168,176 **** wth->file_encap = WTAP_ENCAP_PER_PACKET; } ! return data_offset; } /*********************************************************** * iptrace 2.0 * ***********************************************************/ --- 160,192 ---- wth->file_encap = WTAP_ENCAP_PER_PACKET; } ! return record_offset; } + static int iptrace_seek_read_1_0(wtap *wth, int seek_off, + union pseudo_header *pseudo_header, u_char *pd, int packet_size) + { + int ret; + int err; /* XXX - return this */ + guint8 header[30]; + + file_seek(wth->random_fh, seek_off, SEEK_SET); + + /* Read the descriptor data */ + ret = iptrace_read_rec_header(wth->random_fh, header, 30, &err); + if (ret <= 0) { + /* Read error or EOF */ + return ret; + } + + if ( wtap_encap_ift(header[28]) == WTAP_ENCAP_ATM_SNIFFER ) { + get_atm_pseudo_header(pseudo_header, header); + } + + /* Read the packet data */ + return iptrace_read_rec_data(wth->random_fh, pd, packet_size, &err); + } + /*********************************************************** * iptrace 2.0 * ***********************************************************/ *************** *** 192,236 **** /* Read the next packet */ static int iptrace_read_2_0(wtap *wth, int *err) { ! int bytes_read; ! int data_offset; guint32 packet_size; guint8 header[40]; guint8 *data_ptr; iptrace_2_0_phdr pkt_hdr; /* Read the descriptor data */ ! errno = WTAP_ERR_CANT_READ; ! bytes_read = file_read(header, 1, 40, wth->fh); ! if (bytes_read != 40) { ! *err = file_error(wth->fh); ! if (*err != 0) ! return -1; ! if (bytes_read != 0) { ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } ! return 0; } wth->data_offset += 40; /* Read the packet data */ packet_size = pntohl(&header[0]) - 32; buffer_assure_space( wth->frame_buffer, packet_size ); - data_offset = wth->data_offset; - errno = WTAP_ERR_CANT_READ; data_ptr = buffer_start_ptr( wth->frame_buffer ); ! bytes_read = file_read( data_ptr, 1, packet_size, wth->fh ); ! ! if (bytes_read != packet_size) { ! *err = file_error(wth->fh); ! if (*err == 0) ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } wth->data_offset += packet_size; - /* AIX saves time in nsec, not usec. It's easier to make iptrace * files more Unix-compliant here than try to get the calling * program to know when to use nsec or usec */ --- 208,237 ---- /* Read the next packet */ static int iptrace_read_2_0(wtap *wth, int *err) { ! int record_offset; ! int ret; guint32 packet_size; guint8 header[40]; guint8 *data_ptr; iptrace_2_0_phdr pkt_hdr; /* Read the descriptor data */ ! record_offset = wth->data_offset; ! ret = iptrace_read_rec_header(wth->fh, header, 40, err); ! if (ret <= 0) { ! /* Read error or EOF */ ! return ret; } wth->data_offset += 40; /* Read the packet data */ packet_size = pntohl(&header[0]) - 32; buffer_assure_space( wth->frame_buffer, packet_size ); data_ptr = buffer_start_ptr( wth->frame_buffer ); ! if (iptrace_read_rec_data(wth->fh, data_ptr, packet_size, err) < 0) ! return -1; /* Read error */ wth->data_offset += packet_size; /* AIX saves time in nsec, not usec. It's easier to make iptrace * files more Unix-compliant here than try to get the calling * program to know when to use nsec or usec */ *************** *** 256,262 **** } if ( wth->phdr.pkt_encap == WTAP_ENCAP_ATM_SNIFFER ) { ! get_atm_pseudo_header(wth, header, data_ptr); } /* If the per-file encapsulation isn't known, set it to this --- 257,263 ---- } if ( wth->phdr.pkt_encap == WTAP_ENCAP_ATM_SNIFFER ) { ! get_atm_pseudo_header(&wth->pseudo_header, header); } /* If the per-file encapsulation isn't known, set it to this *************** *** 271,278 **** if (wth->file_encap != wth->phdr.pkt_encap) wth->file_encap = WTAP_ENCAP_PER_PACKET; } ! return data_offset; } /* --- 272,340 ---- if (wth->file_encap != wth->phdr.pkt_encap) wth->file_encap = WTAP_ENCAP_PER_PACKET; } + + return record_offset; + } + + static int iptrace_seek_read_2_0(wtap *wth, int seek_off, + union pseudo_header *pseudo_header, u_char *pd, int packet_size) + { + int ret; + int err; /* XXX - return this */ + guint8 header[40]; + + file_seek(wth->random_fh, seek_off, SEEK_SET); + + /* Read the descriptor data */ + ret = iptrace_read_rec_header(wth->random_fh, header, 40, &err); + if (ret <= 0) { + /* Read error or EOF */ + return ret; + } + + if ( wtap_encap_ift(header[28]) == WTAP_ENCAP_ATM_SNIFFER ) { + get_atm_pseudo_header(pseudo_header, header); + } + + /* Read the packet data */ + return iptrace_read_rec_data(wth->random_fh, pd, packet_size, &err); + } + + static int + iptrace_read_rec_header(FILE_T *fh, guint8 *header, int header_len, int *err) + { + int bytes_read; + + errno = WTAP_ERR_CANT_READ; + bytes_read = file_read(header, 1, header_len, fh); + if (bytes_read != header_len) { + *err = file_error(fh); + if (*err != 0) + return -1; + if (bytes_read != 0) { + *err = WTAP_ERR_SHORT_READ; + return -1; + } + return 0; + } + return 1; + } + + static int + iptrace_read_rec_data(FILE_T *fh, guint8 *data_ptr, int packet_size, int *err) + { + int bytes_read; + + errno = WTAP_ERR_CANT_READ; + bytes_read = file_read( data_ptr, 1, packet_size, fh ); ! if (bytes_read != packet_size) { ! *err = file_error(fh); ! if (*err == 0) ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } ! return 0; } /* *************** *** 292,298 **** * in some fashion what sort of traffic it is, or being told by the user. */ static void ! get_atm_pseudo_header(wtap *wth, guint8 *header, guint8 *pd) { char if_text[9]; char *decimal; --- 354,360 ---- * in some fashion what sort of traffic it is, or being told by the user. */ static void ! get_atm_pseudo_header(union pseudo_header *pseudo_header, guint8 *header) { char if_text[9]; char *decimal; *************** *** 309,334 **** decimal++; Vci = strtoul(decimal, NULL, 10); } ! wth->phdr.pseudo_header.ngsniffer_atm.Vpi = Vpi; ! wth->phdr.pseudo_header.ngsniffer_atm.Vci = Vci; /* * OK, which value means "DTE->DCE" and which value means * "DCE->DTE"? */ ! wth->phdr.pseudo_header.ngsniffer_atm.channel = header[29]; /* We don't have this information */ ! wth->phdr.pseudo_header.ngsniffer_atm.cells = 0; ! wth->phdr.pseudo_header.ngsniffer_atm.aal5t_u2u = 0; ! wth->phdr.pseudo_header.ngsniffer_atm.aal5t_len = 0; ! wth->phdr.pseudo_header.ngsniffer_atm.aal5t_chksum = 0; /* Assume it's AAL5 traffic, but indicate that we don't know what it is beyond that. */ ! wth->phdr.pseudo_header.ngsniffer_atm.AppTrafType = ! ATT_AAL5|ATT_HL_UNKNOWN; ! wth->phdr.pseudo_header.ngsniffer_atm.AppHLType = AHLT_UNKNOWN; } /* Given an RFC1573 (SNMP ifType) interface type, --- 371,395 ---- decimal++; Vci = strtoul(decimal, NULL, 10); } ! pseudo_header->ngsniffer_atm.Vpi = Vpi; ! pseudo_header->ngsniffer_atm.Vci = Vci; /* * OK, which value means "DTE->DCE" and which value means * "DCE->DTE"? */ ! pseudo_header->ngsniffer_atm.channel = header[29]; /* We don't have this information */ ! pseudo_header->ngsniffer_atm.cells = 0; ! pseudo_header->ngsniffer_atm.aal5t_u2u = 0; ! pseudo_header->ngsniffer_atm.aal5t_len = 0; ! pseudo_header->ngsniffer_atm.aal5t_chksum = 0; /* Assume it's AAL5 traffic, but indicate that we don't know what it is beyond that. */ ! pseudo_header->ngsniffer_atm.AppTrafType = ATT_AAL5|ATT_HL_UNKNOWN; ! pseudo_header->ngsniffer_atm.AppHLType = AHLT_UNKNOWN; } /* Given an RFC1573 (SNMP ifType) interface type, Index: wiretap/lanalyzer.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/wiretap/lanalyzer.c,v retrieving revision 1.21 diff -c -r1.21 lanalyzer.c *** lanalyzer.c 2000/03/22 07:06:58 1.21 --- lanalyzer.c 2000/05/01 06:21:42 *************** *** 87,92 **** --- 87,93 ---- wth->file_type = WTAP_FILE_LANALYZER; wth->capture.lanalyzer = g_malloc(sizeof(lanalyzer_t)); wth->subtype_read = lanalyzer_read; + wth->subtype_seek_read = wtap_def_seek_read; wth->subtype_close = lanalyzer_close; wth->snapshot_length = 0; Index: wiretap/libpcap.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/wiretap/libpcap.c,v retrieving revision 1.33 diff -c -r1.33 libpcap.c *** libpcap.c 2000/03/22 07:06:58 1.33 --- libpcap.c 2000/05/01 06:21:43 *************** *** 90,96 **** static void adjust_header(wtap *wth, struct pcaprec_hdr *hdr); static void libpcap_close(wtap *wth); static gboolean libpcap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const u_char *pd, int *err); /* * XXX - this is a bit of a mess. OpenBSD, and perhaps NetBSD, and --- 90,96 ---- static void adjust_header(wtap *wth, struct pcaprec_hdr *hdr); static void libpcap_close(wtap *wth); static gboolean libpcap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const union pseudo_header *pseudo_header, const u_char *pd, int *err); /* * XXX - this is a bit of a mess. OpenBSD, and perhaps NetBSD, and *************** *** 260,265 **** --- 260,266 ---- wth->capture.pcap->version_major = hdr.version_major; wth->capture.pcap->version_minor = hdr.version_minor; wth->subtype_read = libpcap_read; + wth->subtype_seek_read = wtap_def_seek_read; wth->subtype_close = libpcap_close; wth->file_encap = pcap_encap[hdr.network]; wth->snapshot_length = hdr.snaplen; *************** *** 563,569 **** /* Write a record for a packet to a dump file. Returns TRUE on success, FALSE on failure. */ static gboolean libpcap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const u_char *pd, int *err) { struct pcaprec_modified_hdr rec_hdr; int hdr_size; --- 564,570 ---- /* Write a record for a packet to a dump file. Returns TRUE on success, FALSE on failure. */ static gboolean libpcap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const union pseudo_header *pseudo_header, const u_char *pd, int *err) { struct pcaprec_modified_hdr rec_hdr; int hdr_size; Index: wiretap/netmon.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/wiretap/netmon.c,v retrieving revision 1.28 diff -c -r1.28 netmon.c *** netmon.c 2000/03/22 23:47:28 1.28 --- netmon.c 2000/05/01 06:21:45 *************** *** 97,103 **** static int netmon_read(wtap *wth, int *err); static void netmon_close(wtap *wth); static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const u_char *pd, int *err); static gboolean netmon_dump_close(wtap_dumper *wdh, int *err); int netmon_open(wtap *wth, int *err) --- 97,103 ---- static int netmon_read(wtap *wth, int *err); static void netmon_close(wtap *wth); static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const union pseudo_header *pseudo_header, const u_char *pd, int *err); static gboolean netmon_dump_close(wtap_dumper *wdh, int *err); int netmon_open(wtap *wth, int *err) *************** *** 186,191 **** --- 186,192 ---- wth->file_type = file_type; wth->capture.netmon = g_malloc(sizeof(netmon_t)); wth->subtype_read = netmon_read; + wth->subtype_seek_read = wtap_def_seek_read; wth->subtype_close = netmon_close; wth->file_encap = netmon_encap[hdr.network]; wth->snapshot_length = 16384; /* XXX - not available in header */ *************** *** 471,477 **** /* Write a record for a packet to a dump file. Returns TRUE on success, FALSE on failure. */ static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const u_char *pd, int *err) { netmon_dump_t *priv = wdh->private.netmon; struct netmonrec_1_x_hdr rec_1_x_hdr; --- 472,478 ---- /* Write a record for a packet to a dump file. Returns TRUE on success, FALSE on failure. */ static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const union pseudo_header *pseudo_header, const u_char *pd, int *err) { netmon_dump_t *priv = wdh->private.netmon; struct netmonrec_1_x_hdr rec_1_x_hdr; Index: wiretap/nettl.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/wiretap/nettl.c,v retrieving revision 1.10 diff -c -r1.10 nettl.c *** nettl.c 2000/04/15 21:12:37 1.10 --- nettl.c 2000/05/01 06:21:45 *************** *** 65,70 **** --- 65,76 ---- /* header is followed by data and once again the total length (2 bytes) ! */ static int nettl_read(wtap *wth, int *err); + static int nettl_seek_read(wtap *wth, int seek_off, + union pseudo_header *pseudo_header, u_char *pd, int length); + static int nettl_read_rec_header(wtap *wth, FILE_T *fh, + struct wtap_pkthdr *phdr, union pseudo_header *pseudo_header, + int *err); + static int nettl_read_rec_data(FILE_T *fh, char *pd, int length, int *err); static void nettl_close(wtap *wth); int nettl_open(wtap *wth, int *err) *************** *** 109,114 **** --- 115,121 ---- else wth->capture.nettl->is_hpux_11 = FALSE; wth->subtype_read = nettl_read; + wth->subtype_seek_read = nettl_seek_read; wth->subtype_close = nettl_close; wth->snapshot_length = 16384; /* not available in header, only in frame */ *************** *** 118,136 **** /* Read the next packet */ static int nettl_read(wtap *wth, int *err) { ! int bytes_read; struct nettlrec_sx25l2_hdr lapb_hdr; struct nettlrec_ns_ls_ip_hdr ip_hdr; guint16 length; ! int data_offset; guint8 encap[4]; guint8 dummy[4]; - /* Read record header. */ errno = WTAP_ERR_CANT_READ; ! bytes_read = file_read(encap, 1, 4, wth->fh); if (bytes_read != 4) { ! *err = file_error(wth->fh); if (*err != 0) return -1; if (bytes_read != 0) { --- 125,194 ---- /* Read the next packet */ static int nettl_read(wtap *wth, int *err) { ! int record_offset; ! int ret; ! ! /* Read record header. */ ! record_offset = wth->data_offset; ! ret = nettl_read_rec_header(wth, wth->fh, &wth->phdr, &wth->pseudo_header, ! err); ! if (ret <= 0) { ! /* Read error or EOF */ ! return ret; ! } ! wth->data_offset += ret; ! ! /* ! * Read the packet data. ! */ ! buffer_assure_space(wth->frame_buffer, wth->phdr.caplen); ! if (nettl_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer), ! wth->phdr.caplen, err) < 0) ! return -1; /* Read error */ ! wth->data_offset += wth->phdr.caplen; ! return record_offset; ! } ! ! static int ! nettl_seek_read(wtap *wth, int seek_off, ! union pseudo_header *pseudo_header, u_char *pd, int length) ! { ! int ret; ! int err; /* XXX - return this */ ! struct wtap_pkthdr phdr; ! ! file_seek(wth->random_fh, seek_off, SEEK_SET); ! ! /* Read record header. */ ! ret = nettl_read_rec_header(wth, wth->random_fh, &phdr, pseudo_header, ! &err); ! if (ret <= 0) { ! /* Read error or EOF */ ! return ret; ! } ! ! /* ! * Read the packet data. ! */ ! return nettl_read_rec_data(wth->random_fh, pd, length, &err); ! } ! ! static int ! nettl_read_rec_header(wtap *wth, FILE_T *fh, struct wtap_pkthdr *phdr, ! union pseudo_header *pseudo_header, int *err) ! { ! int bytes_read; struct nettlrec_sx25l2_hdr lapb_hdr; struct nettlrec_ns_ls_ip_hdr ip_hdr; guint16 length; ! int offset = 0; guint8 encap[4]; guint8 dummy[4]; errno = WTAP_ERR_CANT_READ; ! bytes_read = file_read(encap, 1, 4, fh); if (bytes_read != 4) { ! *err = file_error(fh); if (*err != 0) return -1; if (bytes_read != 0) { *************** *** 139,151 **** } return 0; } ! wth->data_offset += 4; switch (encap[3]) { case NETTL_SUBSYS_NS_LS_IP : ! wth->phdr.pkt_encap = WTAP_ENCAP_RAW_IP; ! bytes_read = file_read(&ip_hdr, 1, sizeof ip_hdr, wth->fh); if (bytes_read != sizeof ip_hdr) { ! *err = file_error(wth->fh); if (*err != 0) return -1; if (bytes_read != 0) { --- 197,210 ---- } return 0; } ! offset += 4; ! switch (encap[3]) { case NETTL_SUBSYS_NS_LS_IP : ! phdr->pkt_encap = WTAP_ENCAP_RAW_IP; ! bytes_read = file_read(&ip_hdr, 1, sizeof ip_hdr, fh); if (bytes_read != sizeof ip_hdr) { ! *err = file_error(fh); if (*err != 0) return -1; if (bytes_read != 0) { *************** *** 154,167 **** } return 0; } ! wth->data_offset += sizeof ip_hdr; /* The packet header in HP-UX 11 nettl traces is 4 octets longer than * HP-UX 9 and 10 */ if (wth->capture.nettl->is_hpux_11) { ! bytes_read = file_read(dummy, 1, 4, wth->fh); if (bytes_read != 4) { ! *err = file_error(wth->fh); if (*err != 0) return -1; if (bytes_read != 0) { --- 213,226 ---- } return 0; } ! offset += sizeof ip_hdr; /* The packet header in HP-UX 11 nettl traces is 4 octets longer than * HP-UX 9 and 10 */ if (wth->capture.nettl->is_hpux_11) { ! bytes_read = file_read(dummy, 1, 4, fh); if (bytes_read != 4) { ! *err = file_error(fh); if (*err != 0) return -1; if (bytes_read != 0) { *************** *** 170,208 **** } return 0; } ! wth->data_offset += 4; } length = pntohl(&ip_hdr.length); if (length <= 0) return 0; ! wth->phdr.len = length; ! wth->phdr.caplen = length; ! ! wth->phdr.ts.tv_sec = pntohl(&ip_hdr.sec); ! wth->phdr.ts.tv_usec = pntohl(&ip_hdr.usec); ! /* ! * Read the packet data. ! */ ! buffer_assure_space(wth->frame_buffer, length); ! data_offset = wth->data_offset; ! errno = WTAP_ERR_CANT_READ; ! bytes_read = file_read(buffer_start_ptr(wth->frame_buffer), 1, ! length, wth->fh); ! ! if (bytes_read != length) { ! *err = file_error(wth->fh); ! if (*err == 0) ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } ! wth->data_offset += length; break; case NETTL_SUBSYS_SX25L2 : ! wth->phdr.pkt_encap = WTAP_ENCAP_LAPB; ! bytes_read = file_read(&lapb_hdr, 1, sizeof lapb_hdr, wth->fh); if (bytes_read != sizeof lapb_hdr) { ! *err = file_error(wth->fh); if (*err != 0) return -1; if (bytes_read != 0) { --- 229,250 ---- } return 0; } ! offset += 4; } length = pntohl(&ip_hdr.length); if (length <= 0) return 0; ! phdr->len = length; ! phdr->caplen = length; ! phdr->ts.tv_sec = pntohl(&ip_hdr.sec); ! phdr->ts.tv_usec = pntohl(&ip_hdr.usec); break; case NETTL_SUBSYS_SX25L2 : ! phdr->pkt_encap = WTAP_ENCAP_LAPB; ! bytes_read = file_read(&lapb_hdr, 1, sizeof lapb_hdr, fh); if (bytes_read != sizeof lapb_hdr) { ! *err = file_error(fh); if (*err != 0) return -1; if (bytes_read != 0) { *************** *** 211,222 **** } return 0; } ! wth->data_offset += sizeof lapb_hdr; if (wth->capture.nettl->is_hpux_11) { ! bytes_read = file_read(dummy, 1, 4, wth->fh); if (bytes_read != 4) { ! *err = file_error(wth->fh); if (*err != 0) return -1; if (bytes_read != 0) { --- 253,264 ---- } return 0; } ! offset += sizeof lapb_hdr; if (wth->capture.nettl->is_hpux_11) { ! bytes_read = file_read(dummy, 1, 4, fh); if (bytes_read != 4) { ! *err = file_error(fh); if (*err != 0) return -1; if (bytes_read != 0) { *************** *** 225,266 **** } return 0; } ! wth->data_offset += 4; } length = pntohs(&lapb_hdr.length); if (length <= 0) return 0; ! wth->phdr.len = length; ! wth->phdr.caplen = length; ! wth->phdr.ts.tv_sec = pntohl(&lapb_hdr.sec); ! wth->phdr.ts.tv_usec = pntohl(&lapb_hdr.usec); ! wth->phdr.pseudo_header.x25.flags = (lapb_hdr.from_dce & 0x20 ? 0x80 : 0x00); ! ! /* ! * Read the packet data. ! */ ! buffer_assure_space(wth->frame_buffer, length); ! data_offset = wth->data_offset; ! errno = WTAP_ERR_CANT_READ; ! bytes_read = file_read(buffer_start_ptr(wth->frame_buffer), 1, ! length, wth->fh); ! ! if (bytes_read != length) { ! *err = file_error(wth->fh); ! if (*err == 0) ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } ! wth->data_offset += length; break; default: g_message("nettl: network type %u unknown or unsupported", encap[3]); *err = WTAP_ERR_UNSUPPORTED_ENCAP; return -1; } ! return data_offset; } static void nettl_close(wtap *wth) --- 267,307 ---- } return 0; } ! offset += 4; } length = pntohs(&lapb_hdr.length); if (length <= 0) return 0; ! phdr->len = length; ! phdr->caplen = length; ! phdr->ts.tv_sec = pntohl(&lapb_hdr.sec); ! phdr->ts.tv_usec = pntohl(&lapb_hdr.usec); ! pseudo_header->x25.flags = (lapb_hdr.from_dce & 0x20 ? 0x80 : 0x00); break; default: g_message("nettl: network type %u unknown or unsupported", encap[3]); *err = WTAP_ERR_UNSUPPORTED_ENCAP; return -1; + } + return offset; + } + + static int + nettl_read_rec_data(FILE_T *fh, char *pd, int length, int *err) + { + int bytes_read; + + bytes_read = file_read(pd, 1, length, fh); + + if (bytes_read != length) { + *err = file_error(fh); + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; + return -1; } ! return 0; } static void nettl_close(wtap *wth) Index: wiretap/netxray.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/wiretap/netxray.c,v retrieving revision 1.25 diff -c -r1.25 netxray.c *** netxray.c 2000/03/22 07:06:55 1.25 --- netxray.c 2000/05/01 06:21:46 *************** *** 93,99 **** static int netxray_read(wtap *wth, int *err); static void netxray_close(wtap *wth); static gboolean netxray_dump_1_1(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const u_char *pd, int *err); static gboolean netxray_dump_close_1_1(wtap_dumper *wdh, int *err); int netxray_open(wtap *wth, int *err) --- 93,99 ---- static int netxray_read(wtap *wth, int *err); static void netxray_close(wtap *wth); static gboolean netxray_dump_1_1(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const union pseudo_header *pseudo_header, const u_char *pd, int *err); static gboolean netxray_dump_close_1_1(wtap_dumper *wdh, int *err); int netxray_open(wtap *wth, int *err) *************** *** 187,192 **** --- 187,193 ---- wth->file_type = file_type; wth->capture.netxray = g_malloc(sizeof(netxray_t)); wth->subtype_read = netxray_read; + wth->subtype_seek_read = wtap_def_seek_read; wth->subtype_close = netxray_close; wth->file_encap = netxray_encap[hdr.network]; wth->snapshot_length = 16384; /* XXX - not available in header */ *************** *** 361,367 **** /* Write a record for a packet to a dump file. Returns TRUE on success, FALSE on failure. */ static gboolean netxray_dump_1_1(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const u_char *pd, int *err) { netxray_dump_t *priv = wdh->private.netxray; guint32 timestamp; --- 362,368 ---- /* Write a record for a packet to a dump file. Returns TRUE on success, FALSE on failure. */ static gboolean netxray_dump_1_1(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const union pseudo_header *pseudo_header, const u_char *pd, int *err) { netxray_dump_t *priv = wdh->private.netxray; guint32 timestamp; Index: wiretap/ngsniffer.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/wiretap/ngsniffer.c,v retrieving revision 1.37 diff -c -r1.37 ngsniffer.c *** ngsniffer.c 2000/03/22 07:06:57 1.37 --- ngsniffer.c 2000/05/01 06:21:49 *************** *** 247,255 **** static double Usec[] = { 15.0, 0.838096, 15.0, 0.5, 2.0, 1.0, 0.1 }; static int ngsniffer_read(wtap *wth, int *err); static void ngsniffer_close(wtap *wth); static gboolean ngsniffer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const u_char *pd, int *err); static gboolean ngsniffer_dump_close(wtap_dumper *wdh, int *err); int ngsniffer_open(wtap *wth, int *err) --- 247,268 ---- static double Usec[] = { 15.0, 0.838096, 15.0, 0.5, 2.0, 1.0, 0.1 }; static int ngsniffer_read(wtap *wth, int *err); + static int ngsniffer_seek_read(wtap *wth, int seek_off, + union pseudo_header *pseudo_header, u_char *pd, int packet_size); + static int ngsniffer_read_rec_header(FILE_T *fh, guint16 *typep, + guint16 *lengthp, int *err); + static int ngsniffer_read_frame2(FILE_T *fh, struct frame2_rec *frame2, + int *err); + static void set_pseudo_header_frame2(union pseudo_header *pseudo_header, + struct frame2_rec *frame2); + static int ngsniffer_read_frame4(FILE_T *fh, struct frame4_rec *frame4, + int *err); + static void set_pseudo_header_frame4(union pseudo_header *pseudo_header, + struct frame4_rec *frame4); + static int ngsniffer_read_rec_data(FILE_T *fh, char *pd, int length, int *err); static void ngsniffer_close(wtap *wth); static gboolean ngsniffer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const union pseudo_header *pseudo_header, const u_char *pd, int *err); static gboolean ngsniffer_dump_close(wtap_dumper *wdh, int *err); int ngsniffer_open(wtap *wth, int *err) *************** *** 371,376 **** --- 384,390 ---- wth->file_type = WTAP_FILE_NGSNIFFER; wth->capture.ngsniffer = g_malloc(sizeof(ngsniffer_t)); wth->subtype_read = ngsniffer_read; + wth->subtype_seek_read = ngsniffer_seek_read; wth->subtype_close = ngsniffer_close; wth->snapshot_length = 16384; /* not available in header, only in frame */ wth->capture.ngsniffer->timeunit = Usec[version.timeunit]; *************** *** 415,461 **** /* Read the next packet */ static int ngsniffer_read(wtap *wth, int *err) { ! int bytes_read; ! char record_type[2]; ! char record_length[4]; /* only 1st 2 bytes are length */ guint16 type, length; struct frame2_rec frame2; struct frame4_rec frame4; double t; guint16 time_low, time_med, time_high, true_size, size; - int data_offset; u_char *pd; for (;;) { /* * Read the record header. */ ! errno = WTAP_ERR_CANT_READ; ! bytes_read = file_read(record_type, 1, 2, wth->fh); ! if (bytes_read != 2) { ! *err = file_error(wth->fh); ! if (*err != 0) ! return -1; ! if (bytes_read != 0) { ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } ! return 0; } ! wth->data_offset += 2; ! errno = WTAP_ERR_CANT_READ; ! bytes_read = file_read(record_length, 1, 4, wth->fh); ! if (bytes_read != 4) { ! *err = file_error(wth->fh); ! if (*err == 0) ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } ! wth->data_offset += 4; - type = pletohs(record_type); - length = pletohs(record_length); - switch (type) { case REC_FRAME2: --- 429,455 ---- /* Read the next packet */ static int ngsniffer_read(wtap *wth, int *err) { ! int record_offset; ! int ret; guint16 type, length; struct frame2_rec frame2; struct frame4_rec frame4; double t; guint16 time_low, time_med, time_high, true_size, size; u_char *pd; for (;;) { /* * Read the record header. */ ! record_offset = wth->data_offset; ! ret = ngsniffer_read_rec_header(wth->fh, &type, &length, err); ! if (ret <= 0) { ! /* Read error or EOF */ ! return ret; } ! wth->data_offset += 6; switch (type) { case REC_FRAME2: *************** *** 470,482 **** } /* Read the f_frame2_struct */ ! errno = WTAP_ERR_CANT_READ; ! bytes_read = file_read(&frame2, 1, sizeof frame2, wth->fh); ! if (bytes_read != sizeof frame2) { ! *err = file_error(wth->fh); ! if (*err == 0) ! *err = WTAP_ERR_SHORT_READ; ! return -1; } wth->data_offset += sizeof frame2; time_low = pletohs(&frame2.time_low); --- 464,473 ---- } /* Read the f_frame2_struct */ ! ret = ngsniffer_read_frame2(wth->fh, &frame2, err); ! if (ret < 0) { ! /* Read error */ ! return ret; } wth->data_offset += sizeof frame2; time_low = pletohs(&frame2.time_low); *************** *** 489,519 **** t = (double)time_low+(double)(time_med)*65536.0 + (double)time_high*4294967296.0; - - /* - * In one PPP "Internetwork analyzer" capture, - * the only bit seen in "fs" is the 0x80 bit, - * which probably indicates the packet's - * direction; all other bits were zero. - * All bits in "frame2.flags" were zero. - * - * In one X.25 "Interenetwork analyzer" capture, - * the only bit seen in "fs" is the 0x80 bit, - * which probably indicates the packet's - * direction; all other bits were zero. - * "frame2.flags" was always 0x18. - * - * In one Ethernet capture, "fs" was always 0, - * and "flags" was either 0 or 0x18, with no - * obvious correlation with anything. - * - * In one Token Ring capture, "fs" was either 0 - * or 0xcc, and "flags" was either 0 or 0x18, - * with no obvious correlation with anything. - */ - wth->phdr.pseudo_header.x25.flags = - (frame2.fs & 0x80) ? 0x00 : 0x80; goto found; case REC_FRAME4: --- 480,487 ---- t = (double)time_low+(double)(time_med)*65536.0 + (double)time_high*4294967296.0; + set_pseudo_header_frame2(&wth->pseudo_header, &frame2); goto found; case REC_FRAME4: *************** *** 528,541 **** } /* Read the f_frame4_struct */ ! errno = WTAP_ERR_CANT_READ; ! bytes_read = file_read(&frame4, 1, sizeof frame4, wth->fh); ! if (bytes_read != sizeof frame4) { ! *err = file_error(wth->fh); ! if (*err == 0) ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } wth->data_offset += sizeof frame4; time_low = pletohs(&frame4.time_low); time_med = pletohs(&frame4.time_med); --- 496,502 ---- } /* Read the f_frame4_struct */ ! ret = ngsniffer_read_frame4(wth->fh, &frame4, err); wth->data_offset += sizeof frame4; time_low = pletohs(&frame4.time_low); time_med = pletohs(&frame4.time_med); *************** *** 552,575 **** t = (double)time_low+(double)(time_med)*65536.0 + (double)time_high*4294967296.0; ! wth->phdr.pseudo_header.ngsniffer_atm.AppTrafType = ! frame4.atm_info.AppTrafType; ! wth->phdr.pseudo_header.ngsniffer_atm.AppHLType = ! frame4.atm_info.AppHLType; ! wth->phdr.pseudo_header.ngsniffer_atm.Vpi = ! pletohs(&frame4.atm_info.Vpi); ! wth->phdr.pseudo_header.ngsniffer_atm.Vci = ! pletohs(&frame4.atm_info.Vci); ! wth->phdr.pseudo_header.ngsniffer_atm.channel = ! pletohs(&frame4.atm_info.channel); ! wth->phdr.pseudo_header.ngsniffer_atm.cells = ! pletohs(&frame4.atm_info.cells); ! wth->phdr.pseudo_header.ngsniffer_atm.aal5t_u2u = ! pletohs(&frame4.atm_info.Trailer.aal5t_u2u); ! wth->phdr.pseudo_header.ngsniffer_atm.aal5t_len = ! pletohs(&frame4.atm_info.Trailer.aal5t_len); ! wth->phdr.pseudo_header.ngsniffer_atm.aal5t_chksum = ! pletohl(&frame4.atm_info.Trailer.aal5t_chksum); goto found; case REC_EOF: --- 513,519 ---- t = (double)time_low+(double)(time_med)*65536.0 + (double)time_high*4294967296.0; ! set_pseudo_header_frame4(&wth->pseudo_header, &frame4); goto found; case REC_EOF: *************** *** 599,615 **** * Read the packet data. */ buffer_assure_space(wth->frame_buffer, length); - data_offset = wth->data_offset; - errno = WTAP_ERR_CANT_READ; pd = buffer_start_ptr(wth->frame_buffer); ! bytes_read = file_read(pd, 1, length, wth->fh); ! ! if (bytes_read != length) { ! *err = file_error(wth->fh); ! if (*err == 0) ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } wth->data_offset += length; if (wth->file_encap == WTAP_ENCAP_UNKNOWN) { --- 543,551 ---- * Read the packet data. */ buffer_assure_space(wth->frame_buffer, length); pd = buffer_start_ptr(wth->frame_buffer); ! if (ngsniffer_read_rec_data(wth->fh, pd, length, err) < 0) ! return -1; /* Read error */ wth->data_offset += length; if (wth->file_encap == WTAP_ENCAP_UNKNOWN) { *************** *** 637,647 **** wth->phdr.ts.tv_usec = (unsigned long)((t-(double)(wth->phdr.ts.tv_sec)) *1.0e6); wth->phdr.pkt_encap = wth->file_encap; ! return data_offset; } ! static void ! ngsniffer_close(wtap *wth) { g_free(wth->capture.ngsniffer); } --- 573,764 ---- wth->phdr.ts.tv_usec = (unsigned long)((t-(double)(wth->phdr.ts.tv_sec)) *1.0e6); wth->phdr.pkt_encap = wth->file_encap; ! return record_offset; ! } ! ! static int ngsniffer_seek_read(wtap *wth, int seek_off, ! union pseudo_header *pseudo_header, u_char *pd, int packet_size) ! { ! int ret; ! int err; /* XXX - return this */ ! guint16 type, length; ! struct frame2_rec frame2; ! struct frame4_rec frame4; ! ! file_seek(wth->random_fh, seek_off, SEEK_SET); ! ! ret = ngsniffer_read_rec_header(wth->random_fh, &type, &length, &err); ! if (ret <= 0) { ! /* Read error or EOF */ ! return ret; ! } ! ! switch (type) { ! ! case REC_FRAME2: ! /* Read the f_frame2_struct */ ! ret = ngsniffer_read_frame2(wth->random_fh, &frame2, &err); ! if (ret < 0) { ! /* Read error */ ! return ret; ! } ! ! length -= sizeof frame2; /* we already read that much */ ! ! set_pseudo_header_frame2(pseudo_header, &frame2); ! break; ! ! case REC_FRAME4: ! /* Read the f_frame4_struct */ ! ret = ngsniffer_read_frame4(wth->random_fh, &frame4, &err); ! ! length -= sizeof frame4; /* we already read that much */ ! ! set_pseudo_header_frame4(pseudo_header, &frame4); ! break; ! ! default: ! /* ! * "Can't happen". ! */ ! g_assert_not_reached(); ! return -1; ! } ! ! /* ! * Got the pseudo-header (if any), now get the data. ! */ ! return ngsniffer_read_rec_data(wth->random_fh, pd, packet_size, &err); ! } ! ! static int ngsniffer_read_rec_header(FILE_T *fh, guint16 *typep, ! guint16 *lengthp, int *err) ! { ! int bytes_read; ! char record_type[2]; ! char record_length[4]; /* only 1st 2 bytes are length */ ! ! /* ! * Read the record header. ! */ ! errno = WTAP_ERR_CANT_READ; ! bytes_read = file_read(record_type, 1, 2, fh); ! if (bytes_read != 2) { ! *err = file_error(fh); ! if (*err != 0) ! return -1; ! if (bytes_read != 0) { ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } ! return 0; ! } ! errno = WTAP_ERR_CANT_READ; ! bytes_read = file_read(record_length, 1, 4, fh); ! if (bytes_read != 4) { ! *err = file_error(fh); ! if (*err == 0) ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } ! ! *typep = pletohs(record_type); ! *lengthp = pletohs(record_length); ! return 1; /* success */ ! } ! ! static int ngsniffer_read_frame2(FILE_T *fh, struct frame2_rec *frame2, ! int *err) ! { ! int bytes_read; ! ! /* Read the f_frame2_struct */ ! errno = WTAP_ERR_CANT_READ; ! bytes_read = file_read(frame2, 1, sizeof *frame2, fh); ! if (bytes_read != sizeof *frame2) { ! *err = file_error(fh); ! if (*err == 0) ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } ! return 0; ! } ! ! static void set_pseudo_header_frame2(union pseudo_header *pseudo_header, ! struct frame2_rec *frame2) ! { ! /* ! * In one PPP "Internetwork analyzer" capture, ! * the only bit seen in "fs" is the 0x80 bit, ! * which probably indicates the packet's ! * direction; all other bits were zero. ! * All bits in "frame2.flags" were zero. ! * ! * In one X.25 "Interenetwork analyzer" capture, ! * the only bit seen in "fs" is the 0x80 bit, ! * which probably indicates the packet's ! * direction; all other bits were zero. ! * "frame2.flags" was always 0x18. ! * ! * In one Ethernet capture, "fs" was always 0, ! * and "flags" was either 0 or 0x18, with no ! * obvious correlation with anything. ! * ! * In one Token Ring capture, "fs" was either 0 ! * or 0xcc, and "flags" was either 0 or 0x18, ! * with no obvious correlation with anything. ! */ ! pseudo_header->x25.flags = (frame2->fs & 0x80) ? 0x00 : 0x80; ! } ! ! static int ngsniffer_read_frame4(FILE_T *fh, struct frame4_rec *frame4, ! int *err) ! { ! int bytes_read; ! ! /* Read the f_frame4_struct */ ! errno = WTAP_ERR_CANT_READ; ! bytes_read = file_read(frame4, 1, sizeof *frame4, fh); ! if (bytes_read != sizeof *frame4) { ! *err = file_error(fh); ! if (*err == 0) ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } ! return 0; ! } ! ! static void set_pseudo_header_frame4(union pseudo_header *pseudo_header, ! struct frame4_rec *frame4) ! { ! pseudo_header->ngsniffer_atm.AppTrafType = frame4->atm_info.AppTrafType; ! pseudo_header->ngsniffer_atm.AppHLType = frame4->atm_info.AppHLType; ! pseudo_header->ngsniffer_atm.Vpi = pletohs(&frame4->atm_info.Vpi); ! pseudo_header->ngsniffer_atm.Vci = pletohs(&frame4->atm_info.Vci); ! pseudo_header->ngsniffer_atm.channel = pletohs(&frame4->atm_info.channel); ! pseudo_header->ngsniffer_atm.cells = pletohs(&frame4->atm_info.cells); ! pseudo_header->ngsniffer_atm.aal5t_u2u = pletohs(&frame4->atm_info.Trailer.aal5t_u2u); ! pseudo_header->ngsniffer_atm.aal5t_len = pletohs(&frame4->atm_info.Trailer.aal5t_len); ! pseudo_header->ngsniffer_atm.aal5t_chksum = pletohl(&frame4->atm_info.Trailer.aal5t_chksum); ! } ! ! static int ngsniffer_read_rec_data(FILE_T *fh, char *pd, int length, int *err) ! { ! int bytes_read; ! ! errno = WTAP_ERR_CANT_READ; ! bytes_read = file_read(pd, 1, length, fh); ! ! if (bytes_read != length) { ! *err = file_error(fh); ! if (*err == 0) ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } ! return 0; } ! static void ngsniffer_close(wtap *wth) { g_free(wth->capture.ngsniffer); } *************** *** 717,723 **** /* Write a record for a packet to a dump file. Returns TRUE on success, FALSE on failure. */ static gboolean ngsniffer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const u_char *pd, int *err) { ngsniffer_dump_t *priv = wdh->private.ngsniffer; struct frame2_rec rec_hdr; --- 834,840 ---- /* Write a record for a packet to a dump file. Returns TRUE on success, FALSE on failure. */ static gboolean ngsniffer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const union pseudo_header *pseudo_header, const u_char *pd, int *err) { ngsniffer_dump_t *priv = wdh->private.ngsniffer; struct frame2_rec rec_hdr; *************** *** 792,798 **** rec_hdr.time_high = pletohs(&t_high); rec_hdr.size = pletohs(&phdr->caplen); if (wdh->encap == WTAP_ENCAP_LAPB || wdh->encap == WTAP_ENCAP_PPP) ! rec_hdr.fs = (phdr->pseudo_header.x25.flags & 0x80) ? 0x00 : 0x80; else rec_hdr.fs = 0; rec_hdr.flags = 0; --- 909,915 ---- rec_hdr.time_high = pletohs(&t_high); rec_hdr.size = pletohs(&phdr->caplen); if (wdh->encap == WTAP_ENCAP_LAPB || wdh->encap == WTAP_ENCAP_PPP) ! rec_hdr.fs = (pseudo_header->x25.flags & 0x80) ? 0x00 : 0x80; else rec_hdr.fs = 0; rec_hdr.flags = 0; Index: wiretap/radcom.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/wiretap/radcom.c,v retrieving revision 1.20 diff -c -r1.20 radcom.c *** radcom.c 2000/04/15 21:12:37 1.20 --- radcom.c 2000/05/01 06:21:49 *************** *** 68,73 **** --- 68,78 ---- }; static int radcom_read(wtap *wth, int *err); + static int radcom_seek_read(wtap *wth, int seek_off, + union pseudo_header *pseudo_header, u_char *pd, int length); + static int radcom_read_rec_header(FILE_T *fh, struct radcomrec_hdr *hdr, + int *err); + static int radcom_read_rec_data(FILE_T *fh, char *pd, int length, int *err); int radcom_open(wtap *wth, int *err) { *************** *** 134,139 **** --- 139,145 ---- /* This is a radcom file */ wth->file_type = WTAP_FILE_RADCOM; wth->subtype_read = radcom_read; + wth->subtype_seek_read = radcom_seek_read; wth->snapshot_length = 16384; /* not available in header, only in frame */ tm.tm_year = pletohs(&start_date.year)-1900; *************** *** 218,243 **** /* Read the next packet */ static int radcom_read(wtap *wth, int *err) { ! int bytes_read; struct radcomrec_hdr hdr; guint16 length; guint32 sec; struct tm tm; - int data_offset; char fcs[2]; /* Read record header. */ ! errno = WTAP_ERR_CANT_READ; ! bytes_read = file_read(&hdr, 1, sizeof hdr, wth->fh); ! if (bytes_read != sizeof hdr) { ! *err = file_error(wth->fh); ! if (*err != 0) ! return -1; ! if (bytes_read != 0) { ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } ! return 0; } wth->data_offset += sizeof hdr; length = pletohs(&hdr.length); --- 224,244 ---- /* Read the next packet */ static int radcom_read(wtap *wth, int *err) { ! int record_offset; ! int ret; struct radcomrec_hdr hdr; guint16 length; guint32 sec; + int bytes_read; struct tm tm; char fcs[2]; /* Read record header. */ ! record_offset = wth->data_offset; ! ret = radcom_read_rec_header(wth->fh, &hdr, err); ! if (ret <= 0) { ! /* Read error or EOF */ ! return ret; } wth->data_offset += sizeof hdr; length = pletohs(&hdr.length); *************** *** 259,281 **** tm.tm_isdst = -1; wth->phdr.ts.tv_sec = mktime(&tm); wth->phdr.ts.tv_usec = pletohl(&hdr.date.usec); ! wth->phdr.pseudo_header.x25.flags = (hdr.dce & 0x1) ? 0x00 : 0x80; /* * Read the packet data. */ buffer_assure_space(wth->frame_buffer, length); ! data_offset = wth->data_offset; ! errno = WTAP_ERR_CANT_READ; ! bytes_read = file_read(buffer_start_ptr(wth->frame_buffer), 1, ! length, wth->fh); ! ! if (bytes_read != length) { ! *err = file_error(wth->fh); ! if (*err == 0) ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } wth->data_offset += length; wth->phdr.pkt_encap = wth->file_encap; --- 260,274 ---- tm.tm_isdst = -1; wth->phdr.ts.tv_sec = mktime(&tm); wth->phdr.ts.tv_usec = pletohl(&hdr.date.usec); ! wth->pseudo_header.x25.flags = (hdr.dce & 0x1) ? 0x00 : 0x80; /* * 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) < 0) ! return -1; /* Read error */ wth->data_offset += length; wth->phdr.pkt_encap = wth->file_encap; *************** *** 293,298 **** } wth->data_offset += sizeof fcs; } ! return data_offset; } --- 286,353 ---- } wth->data_offset += sizeof fcs; } + + return record_offset; + } + + static int + radcom_seek_read(wtap *wth, int seek_off, + union pseudo_header *pseudo_header, u_char *pd, int length) + { + int ret; + int err; /* XXX - return this */ + struct radcomrec_hdr hdr; + + file_seek(wth->random_fh, seek_off, SEEK_SET); + + /* Read record header. */ + ret = radcom_read_rec_header(wth->random_fh, &hdr, &err); + if (ret <= 0) { + /* Read error or EOF */ + return ret; + } + + pseudo_header->x25.flags = (hdr.dce & 0x1) ? 0x00 : 0x80; + + /* + * Read the packet data. + */ + return radcom_read_rec_data(wth->random_fh, pd, length, &err); + } + + static int + radcom_read_rec_header(FILE_T *fh, struct radcomrec_hdr *hdr, int *err) + { + int bytes_read; + + errno = WTAP_ERR_CANT_READ; + bytes_read = file_read(hdr, 1, sizeof *hdr, fh); + if (bytes_read != sizeof *hdr) { + *err = file_error(fh); + if (*err != 0) + return -1; + if (bytes_read != 0) { + *err = WTAP_ERR_SHORT_READ; + return -1; + } + return 0; + } + return 1; + } ! static int ! radcom_read_rec_data(FILE_T *fh, char *pd, int length, int *err) ! { ! int bytes_read; ! ! errno = WTAP_ERR_CANT_READ; ! bytes_read = file_read(pd, 1, length, fh); ! ! if (bytes_read != length) { ! *err = file_error(fh); ! if (*err == 0) ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } ! return 0; } Index: wiretap/snoop.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/wiretap/snoop.c,v retrieving revision 1.25 diff -c -r1.25 snoop.c *** snoop.c 2000/02/19 08:00:04 1.25 --- snoop.c 2000/05/01 06:21:51 *************** *** 56,63 **** }; static int snoop_read(wtap *wth, int *err); static gboolean snoop_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const u_char *pd, int *err); /* * See --- 56,68 ---- }; static int snoop_read(wtap *wth, int *err); + static int snoop_seek_read(wtap *wth, int seek_off, + union pseudo_header *pseudo_header, u_char *pd, int length); + static int snoop_read_atm_pseudoheader(FILE_T *fh, + union pseudo_header *pseudo_header, int *err); + static int snoop_read_rec_data(FILE_T *fh, char *pd, int length, int *err); static gboolean snoop_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const union pseudo_header *pseudo_header, const u_char *pd, int *err); /* * See *************** *** 194,199 **** --- 199,205 ---- /* This is a snoop file */ wth->file_type = WTAP_FILE_SNOOP; wth->subtype_read = snoop_read; + wth->subtype_seek_read = snoop_seek_read; wth->file_encap = snoop_encap[hdr.network]; wth->snapshot_length = 16384; /* XXX - not available in header */ return 1; *************** *** 205,214 **** guint32 rec_size; guint32 packet_size; guint32 orig_size; int bytes_read; struct snooprec_hdr hdr; - char atm_phdr[4]; - int data_offset; char padbuf[4]; int padbytes; int bytes_to_read; --- 211,219 ---- guint32 rec_size; guint32 packet_size; guint32 orig_size; + int data_offset; int bytes_read; struct snooprec_hdr hdr; char padbuf[4]; int padbytes; int bytes_to_read; *************** *** 242,247 **** --- 247,254 ---- return -1; } + data_offset = wth->data_offset; + /* * If this is an ATM packet, the first four bytes are the * direction of the packet (transmit/receive), the VPI, and *************** *** 258,299 **** packet_size); *err = WTAP_ERR_BAD_RECORD; return -1; - } - errno = WTAP_ERR_CANT_READ; - bytes_read = file_read(atm_phdr, 1, 4, wth->fh); - if (bytes_read != 4) { - *err = file_error(wth->fh); - if (*err == 0) - *err = WTAP_ERR_SHORT_READ; - return -1; } ! ! wth->phdr.pseudo_header.ngsniffer_atm.channel = ! (atm_phdr[0] & 0x80) ? 1 : 0; ! wth->phdr.pseudo_header.ngsniffer_atm.Vpi = atm_phdr[1]; ! wth->phdr.pseudo_header.ngsniffer_atm.Vci = pntohs(&atm_phdr[2]); ! ! /* We don't have this information */ ! wth->phdr.pseudo_header.ngsniffer_atm.cells = 0; ! wth->phdr.pseudo_header.ngsniffer_atm.aal5t_u2u = 0; ! wth->phdr.pseudo_header.ngsniffer_atm.aal5t_len = 0; ! wth->phdr.pseudo_header.ngsniffer_atm.aal5t_chksum = 0; /* - * Assume it's AAL5; we know nothing more about it. - * - * For what it's worth, in one "atmsnoop" capture, - * the lower 7 bits of the first byte of the header - * were 0x05 for ILMI traffic, 0x06 for Signalling - * AAL traffic, and 0x02 for at least some RFC 1483-style - * LLC multiplexed traffic. - */ - wth->phdr.pseudo_header.ngsniffer_atm.AppTrafType = - ATT_AAL5|ATT_HL_UNKNOWN; - wth->phdr.pseudo_header.ngsniffer_atm.AppHLType = - AHLT_UNKNOWN; - - /* * Don't count the pseudo-header as part of the packet. */ rec_size -= 4; --- 265,276 ---- packet_size); *err = WTAP_ERR_BAD_RECORD; return -1; } ! if (snoop_read_atm_pseudoheader(wth->fh, &wth->pseudo_header, ! err) < 0) ! return -1; /* Read error */ /* * Don't count the pseudo-header as part of the packet. */ rec_size -= 4; *************** *** 303,319 **** } buffer_assure_space(wth->frame_buffer, packet_size); ! data_offset = wth->data_offset; ! errno = WTAP_ERR_CANT_READ; ! bytes_read = file_read(buffer_start_ptr(wth->frame_buffer), 1, ! packet_size, wth->fh); ! ! if (bytes_read != packet_size) { ! *err = file_error(wth->fh); ! if (*err == 0) ! *err = WTAP_ERR_SHORT_READ; ! return -1; ! } wth->data_offset += packet_size; wth->phdr.ts.tv_sec = ntohl(hdr.ts_sec); --- 280,288 ---- } buffer_assure_space(wth->frame_buffer, packet_size); ! if (snoop_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer), ! packet_size, err) < 0) ! return -1; /* Read error */ wth->data_offset += packet_size; wth->phdr.ts.tv_sec = ntohl(hdr.ts_sec); *************** *** 349,354 **** --- 318,405 ---- return data_offset; } + static int + snoop_seek_read(wtap *wth, int seek_off, + union pseudo_header *pseudo_header, u_char *pd, int length) + { + int ret; + int err; /* XXX - return this */ + + file_seek(wth->random_fh, seek_off, SEEK_SET); + + if (wth->file_encap == WTAP_ENCAP_ATM_SNIFFER) { + ret = snoop_read_atm_pseudoheader(wth->random_fh, pseudo_header, + &err); + if (ret < 0) { + /* Read error */ + return ret; + } + } + + /* + * Read the packet data. + */ + return snoop_read_rec_data(wth->random_fh, pd, length, &err); + } + + static int + snoop_read_atm_pseudoheader(FILE_T *fh, union pseudo_header *pseudo_header, + int *err) + { + char atm_phdr[4]; + int bytes_read; + + errno = WTAP_ERR_CANT_READ; + bytes_read = file_read(atm_phdr, 1, 4, fh); + if (bytes_read != 4) { + *err = file_error(fh); + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; + return -1; + } + + pseudo_header->ngsniffer_atm.channel = (atm_phdr[0] & 0x80) ? 1 : 0; + pseudo_header->ngsniffer_atm.Vpi = atm_phdr[1]; + pseudo_header->ngsniffer_atm.Vci = pntohs(&atm_phdr[2]); + + /* We don't have this information */ + pseudo_header->ngsniffer_atm.cells = 0; + pseudo_header->ngsniffer_atm.aal5t_u2u = 0; + pseudo_header->ngsniffer_atm.aal5t_len = 0; + pseudo_header->ngsniffer_atm.aal5t_chksum = 0; + + /* + * Assume it's AAL5; we know nothing more about it. + * + * For what it's worth, in one "atmsnoop" capture, + * the lower 7 bits of the first byte of the header + * were 0x05 for ILMI traffic, 0x06 for Signalling + * AAL traffic, and 0x02 for at least some RFC 1483-style + * LLC multiplexed traffic. + */ + pseudo_header->ngsniffer_atm.AppTrafType = ATT_AAL5|ATT_HL_UNKNOWN; + pseudo_header->ngsniffer_atm.AppHLType = AHLT_UNKNOWN; + + return 0; + } + + static int + snoop_read_rec_data(FILE_T *fh, char *pd, int length, int *err) + { + int bytes_read; + + errno = WTAP_ERR_CANT_READ; + bytes_read = file_read(pd, 1, length, fh); + + if (bytes_read != length) { + *err = file_error(fh); + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; + return -1; + } + return 0; + } + static const int wtap_encap[] = { -1, /* WTAP_ENCAP_UNKNOWN -> unsupported */ 0x04, /* WTAP_ENCAP_ETHERNET -> DL_ETHER */ *************** *** 420,426 **** /* Write a record for a packet to a dump file. Returns TRUE on success, FALSE on failure. */ static gboolean snoop_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const u_char *pd, int *err) { struct snooprec_hdr rec_hdr; int nwritten; --- 471,477 ---- /* Write a record for a packet to a dump file. Returns TRUE on success, FALSE on failure. */ static gboolean snoop_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, ! const union pseudo_header *pseudo_header, const u_char *pd, int *err) { struct snooprec_hdr rec_hdr; int nwritten; Index: wiretap/toshiba.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/wiretap/toshiba.c,v retrieving revision 1.8 diff -c -r1.8 toshiba.c *** toshiba.c 2000/03/04 14:22:29 1.8 --- toshiba.c 2000/05/01 06:21:52 *************** *** 105,114 **** #define TOSHIBA_REC_MAGIC_SIZE (sizeof toshiba_rec_magic / sizeof toshiba_rec_magic[0]) static int toshiba_read(wtap *wth, int *err); static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf, int byte_offset); ! static int parse_toshiba_hex_dump(FILE *fh, int pkt_len, guint8* buf, int *err); ! static int parse_toshiba_rec_hdr(wtap *wth, FILE *fh, int *err); ! static int parse_toshiba(FILE *fh, guint8 *pd, int len); /* Seeks to the beginning of the next packet, and returns the byte offset. Returns -1 on failure. */ --- 105,115 ---- #define TOSHIBA_REC_MAGIC_SIZE (sizeof toshiba_rec_magic / sizeof toshiba_rec_magic[0]) static int toshiba_read(wtap *wth, int *err); + static int toshiba_seek_read(wtap *wth, int seek_off, union pseudo_header *pseudo_header, guint8 *pd, int len); static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf, int byte_offset); ! static int parse_toshiba_hex_dump(FILE_T *fh, int pkt_len, guint8* buf, int *err); ! static int parse_toshiba_rec_hdr(wtap *wth, FILE_T *fh, ! union pseudo_header *pseudo_header, int *err); /* Seeks to the beginning of the next packet, and returns the byte offset. Returns -1 on failure. */ *************** *** 192,197 **** --- 193,199 ---- wth->file_type = WTAP_FILE_TOSHIBA; wth->snapshot_length = 16384; /* just guessing */ wth->subtype_read = toshiba_read; + wth->subtype_seek_read = toshiba_seek_read; return 1; } *************** *** 210,216 **** } /* Parse the header */ ! pkt_len = parse_toshiba_rec_hdr(wth, wth->fh, err); /* Make sure we have enough room for the packet */ buffer_assure_space(wth->frame_buffer, wth->snapshot_length); --- 212,219 ---- } /* Parse the header */ ! pkt_len = parse_toshiba_rec_hdr(wth, wth->fh, ! &wth->pseudo_header, err); /* Make sure we have enough room for the packet */ buffer_assure_space(wth->frame_buffer, wth->snapshot_length); *************** *** 224,257 **** } /* Used to read packets in random-access fashion */ - int - toshiba_seek_read (FILE *fh, int seek_off, guint8 *pd, int len) - { - file_seek(fh, seek_off - 1, SEEK_SET); - return parse_toshiba(fh, pd, len); - } - - /* Used to read packets in random-access fashion */ static int ! parse_toshiba(FILE *fh, guint8 *pd, int len) { int pkt_len; int err; ! pkt_len = parse_toshiba_rec_hdr(NULL, fh, &err); if (pkt_len != len) { return -1; } ! parse_toshiba_hex_dump(fh, pkt_len, pd, &err); return 0; } /* Parses a packet record header. */ static int ! parse_toshiba_rec_hdr(wtap *wth, FILE *fh, int *err) { char line[TOSHIBA_LINE_LENGTH]; int num_items_scanned; --- 227,257 ---- } /* Used to read packets in random-access fashion */ static int ! toshiba_seek_read (wtap *wth, int seek_off, union pseudo_header *pseudo_header, ! guint8 *pd, int len) { int pkt_len; int err; ! file_seek(wth->random_fh, seek_off - 1, SEEK_SET); + pkt_len = parse_toshiba_rec_hdr(NULL, wth->random_fh, pseudo_header, + &err); + if (pkt_len != len) { return -1; } ! parse_toshiba_hex_dump(wth->random_fh, pkt_len, pd, &err); return 0; } /* Parses a packet record header. */ static int ! parse_toshiba_rec_hdr(wtap *wth, FILE_T *fh, ! union pseudo_header *pseudo_header, int *err) { char line[TOSHIBA_LINE_LENGTH]; int num_items_scanned; *************** *** 315,342 **** wth->phdr.ts.tv_usec = csec * 10000; wth->phdr.caplen = pkt_len; wth->phdr.len = pkt_len; ! switch (channel[0]) { ! case 'B': wth->phdr.pkt_encap = WTAP_ENCAP_PPP; ! break; ! case 'D': wth->phdr.pkt_encap = WTAP_ENCAP_LAPD; ! wth->phdr.pseudo_header.lapd.from_network_to_user = ! (direction[0] == 'R' ? TRUE : FALSE ); ! break; ! default: wth->phdr.pkt_encap = WTAP_ENCAP_ETHERNET; ! break; ! } } return pkt_len; } /* Converts ASCII hex dump to binary data */ static int ! parse_toshiba_hex_dump(FILE *fh, int pkt_len, guint8* buf, int *err) { char line[TOSHIBA_LINE_LENGTH]; int i, hex_lines; --- 315,345 ---- wth->phdr.ts.tv_usec = csec * 10000; wth->phdr.caplen = pkt_len; wth->phdr.len = pkt_len; ! } ! switch (channel[0]) { ! case 'B': ! if (wth) wth->phdr.pkt_encap = WTAP_ENCAP_PPP; ! break; ! case 'D': ! if (wth) wth->phdr.pkt_encap = WTAP_ENCAP_LAPD; ! pseudo_header->lapd.from_network_to_user = ! (direction[0] == 'R' ? TRUE : FALSE ); ! break; ! default: ! if (wth) wth->phdr.pkt_encap = WTAP_ENCAP_ETHERNET; ! break; } return pkt_len; } /* Converts ASCII hex dump to binary data */ static int ! parse_toshiba_hex_dump(FILE_T *fh, int pkt_len, guint8* buf, int *err) { char line[TOSHIBA_LINE_LENGTH]; int i, hex_lines; Index: wiretap/toshiba.h =================================================================== RCS file: /usr/local/cvsroot/ethereal/wiretap/toshiba.h,v retrieving revision 1.1 diff -c -r1.1 toshiba.h *** toshiba.h 1999/10/31 17:46:10 1.1 --- toshiba.h 2000/05/01 06:21:52 *************** *** 22,25 **** */ int toshiba_open(wtap *wth, int *err); - int toshiba_seek_read (FILE *fh, int seek_off, guint8 *pd, int len); --- 22,24 ---- Index: wiretap/wtap.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/wiretap/wtap.c,v retrieving revision 1.39 diff -c -r1.39 wtap.c *** wtap.c 2000/04/08 00:33:04 1.39 --- wtap.c 2000/05/01 06:21:52 *************** *** 187,204 **** return strerror(err); } ! void wtap_close(wtap *wth) { ! if (wth->subtype_close != NULL) ! (*wth->subtype_close)(wth); ! ! file_close(wth->fh); if (wth->frame_buffer) { buffer_free(wth->frame_buffer); g_free(wth->frame_buffer); } g_free(wth); } --- 187,220 ---- return strerror(err); } ! /* Close only the sequential side, freeing up memory it uses. ! Note that we do *not* want to call the subtype's close function, ! as it would free any per-subtype data, and that data may be ! needed by the random-access side. */ ! void wtap_sequential_close(wtap *wth) { ! if (wth->fh != NULL) { ! file_close(wth->fh); ! wth->fh = NULL; ! } if (wth->frame_buffer) { buffer_free(wth->frame_buffer); g_free(wth->frame_buffer); + wth->frame_buffer = NULL; } + } + + void wtap_close(wtap *wth) + { + wtap_sequential_close(wth); + if (wth->subtype_close != NULL) + (*wth->subtype_close)(wth); + + if (wth->random_fh != NULL) + file_close(wth->random_fh); + g_free(wth); } *************** *** 214,220 **** while ((data_offset = wth->subtype_read(wth, err)) > 0) { callback(user, &wth->phdr, data_offset, ! buffer_start_ptr(wth->frame_buffer)); if (count > 0 && ++loop >= count) break; } --- 230,236 ---- while ((data_offset = wth->subtype_read(wth, err)) > 0) { callback(user, &wth->phdr, data_offset, ! &wth->pseudo_header, buffer_start_ptr(wth->frame_buffer)); if (count > 0 && ++loop >= count) break; } *************** *** 224,240 **** return TRUE; /* success */ } ! int wtap_seek_read(int file_type, FILE *fh, int seek_off, guint8 *pd, int len) { ! switch (file_type) { ! ! case WTAP_FILE_ASCEND: ! return ascend_seek_read(fh, seek_off, pd, len); ! ! case WTAP_FILE_TOSHIBA: ! return toshiba_seek_read(fh, seek_off, pd, len); ! ! default: ! return wtap_def_seek_read(fh, seek_off, pd, len); ! } } --- 240,247 ---- return TRUE; /* success */ } ! int wtap_seek_read(wtap *wth, int seek_off, ! union pseudo_header *pseudo_header, guint8 *pd, int len) { ! return wth->subtype_seek_read(wth, seek_off, pseudo_header, pd, len); } Index: wiretap/wtap.h =================================================================== RCS file: /usr/local/cvsroot/ethereal/wiretap/wtap.h,v retrieving revision 1.67 diff -c -r1.67 wtap.h *** wtap.h 2000/04/15 21:12:36 1.67 --- wtap.h 2000/05/01 06:21:53 *************** *** 304,326 **** guint32 caplen; guint32 len; int pkt_encap; - union pseudo_header pseudo_header; }; typedef void (*wtap_handler)(u_char*, const struct wtap_pkthdr*, ! int, const u_char *); struct wtap; struct Buffer; typedef int (*subtype_read_func)(struct wtap*, int*); typedef struct wtap { FILE_T fh; int fd; /* File descriptor for cap file */ int file_type; int snapshot_length; struct Buffer *frame_buffer; struct wtap_pkthdr phdr; long data_offset; --- 304,329 ---- guint32 caplen; guint32 len; int pkt_encap; }; typedef void (*wtap_handler)(u_char*, const struct wtap_pkthdr*, ! int, union pseudo_header *pseudo_header, const u_char *); struct wtap; struct Buffer; typedef int (*subtype_read_func)(struct wtap*, int*); + typedef int (*subtype_seek_read_func)(struct wtap*, int, union pseudo_header*, + guint8*, int); typedef struct wtap { FILE_T fh; int fd; /* File descriptor for cap file */ + FILE_T random_fh; /* Secondary FILE_T for random access */ int file_type; int snapshot_length; struct Buffer *frame_buffer; struct wtap_pkthdr phdr; + union pseudo_header pseudo_header; long data_offset; *************** *** 336,341 **** --- 339,345 ---- } capture; subtype_read_func subtype_read; + subtype_seek_read_func subtype_seek_read; void (*subtype_close)(struct wtap*); int file_encap; /* per-file, for those file formats that have *************** *** 346,352 **** struct wtap_dumper; typedef gboolean (*subtype_write_func)(struct wtap_dumper*, ! const struct wtap_pkthdr*, const u_char*, int*); typedef gboolean (*subtype_close_func)(struct wtap_dumper*, int*); typedef struct { --- 350,357 ---- struct wtap_dumper; typedef gboolean (*subtype_write_func)(struct wtap_dumper*, ! const struct wtap_pkthdr*, const union pseudo_header*, ! const u_char*, int*); typedef gboolean (*subtype_close_func)(struct wtap_dumper*, int*); typedef struct { *************** *** 394,400 **** * * a negative number, indicating the type of error, on other failures. */ ! wtap* wtap_open_offline(const char *filename, int *err); int wtap_loop(wtap *wth, int, wtap_handler, u_char*, int*); int wtap_read(wtap *wth, int *err); --- 399,405 ---- * * a negative number, indicating the type of error, on other failures. */ ! wtap* wtap_open_offline(const char *filename, int *err, gboolean do_random); int wtap_loop(wtap *wth, int, wtap_handler, u_char*, int*); int wtap_read(wtap *wth, int *err); *************** *** 413,421 **** int wtap_short_string_to_encap(const char *short_name); const char *wtap_strerror(int err); void wtap_close(wtap *wth); ! int wtap_seek_read (int file_type, FILE *fh, int seek_off, guint8 *pd, int len); ! int wtap_def_seek_read (FILE *fh, int seek_off, guint8 *pd, int len); gboolean wtap_dump_can_open(int filetype); gboolean wtap_dump_can_write_encap(int filetype, int encap); --- 418,429 ---- int wtap_short_string_to_encap(const char *short_name); const char *wtap_strerror(int err); + void wtap_sequential_close(wtap *wth); void wtap_close(wtap *wth); ! int wtap_seek_read (wtap *wth, int seek_off, ! union pseudo_header *pseudo_header, guint8 *pd, int len); ! int wtap_def_seek_read (wtap *wth, int seek_off, ! union pseudo_header *pseudo_header, guint8 *pd, int len); gboolean wtap_dump_can_open(int filetype); gboolean wtap_dump_can_write_encap(int filetype, int encap); *************** *** 423,430 **** int snaplen, int *err); wtap_dumper* wtap_dump_fdopen(int fd, int filetype, int encap, int snaplen, int *err); ! gboolean wtap_dump(wtap_dumper *, const struct wtap_pkthdr *, const u_char *, ! int *err); FILE* wtap_dump_file(wtap_dumper *); gboolean wtap_dump_close(wtap_dumper *, int *); --- 431,438 ---- int snaplen, int *err); wtap_dumper* wtap_dump_fdopen(int fd, int filetype, int encap, int snaplen, int *err); ! gboolean wtap_dump(wtap_dumper *, const struct wtap_pkthdr *, ! const union pseudo_header *pseudo_header, const u_char *, int *err); FILE* wtap_dump_file(wtap_dumper *); gboolean wtap_dump_close(wtap_dumper *, int *);
- Next by Date: [ethereal-dev] String types
- Next by thread: Re: [ethereal-dev] Patch to remove pseudo-header from "frame_data" structure
- Index(es):