I removed the per-file encapsulation type from wiretap, and make all filetypes

provide a per-packet encapsulation type. this required minor modifications to
ethereal.

svn path=/trunk/; revision=162
This commit is contained in:
Gilbert Ramirez 1999-01-07 16:15:37 +00:00
parent f8046a1f29
commit 7757b2e72b
10 changed files with 39 additions and 35 deletions

8
file.c
View File

@ -1,7 +1,7 @@
/* file.c /* file.c
* File I/O routines * File I/O routines
* *
* $Id: file.c,v 1.17 1999/01/03 01:57:24 guy Exp $ * $Id: file.c,v 1.18 1999/01/07 16:15:34 gram Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -114,7 +114,6 @@ open_cap_file(char *fname, capture_file *cf) {
/* Next, find out what type of file we're dealing with */ /* Next, find out what type of file we're dealing with */
#ifdef WITH_WIRETAP #ifdef WITH_WIRETAP
cf->cd_t = WTAP_FILE_UNKNOWN; cf->cd_t = WTAP_FILE_UNKNOWN;
cf->lnk_t = WTAP_ENCAP_NONE;
#else #else
cf->cd_t = CD_UNKNOWN; cf->cd_t = CD_UNKNOWN;
cf->lnk_t = DLT_NULL; cf->lnk_t = DLT_NULL;
@ -185,7 +184,6 @@ open_cap_file(char *fname, capture_file *cf) {
cf->fh = wtap_file(cf->wth); cf->fh = wtap_file(cf->wth);
cf->cd_t = wtap_file_type(cf->wth); cf->cd_t = wtap_file_type(cf->wth);
cf->snap = wtap_snapshot_length(cf->wth); cf->snap = wtap_snapshot_length(cf->wth);
cf->lnk_t = wtap_encapsulation(cf->wth);
#endif #endif
return 0; return 0;
@ -325,14 +323,12 @@ pcap_dispatch_cb(u_char *user, const struct pcap_pkthdr *phdr,
fdata->cap_len = phdr->caplen; fdata->cap_len = phdr->caplen;
#ifdef WITH_WIRETAP #ifdef WITH_WIRETAP
fdata->file_off = offset; fdata->file_off = offset;
fdata->lnk_t = phdr->pkt_encap;
#else #else
fdata->file_off = ftell(cf->fh) - phdr->caplen; fdata->file_off = ftell(cf->fh) - phdr->caplen;
#endif #endif
fdata->abs_secs = phdr->ts.tv_sec; fdata->abs_secs = phdr->ts.tv_sec;
fdata->abs_usecs = phdr->ts.tv_usec; fdata->abs_usecs = phdr->ts.tv_usec;
#ifdef WITH_WIRETAP
fdata->lnk_t = phdr->pkt_encap;
#endif
/* If we don't have the time stamp of the first packet, it's because this /* If we don't have the time stamp of the first packet, it's because this
is the first packet. Save the time stamp of this packet as the time is the first packet. Save the time stamp of this packet as the time

4
file.h
View File

@ -1,7 +1,7 @@
/* file.h /* file.h
* Definitions for file structures and routines * Definitions for file structures and routines
* *
* $Id: file.h,v 1.8 1999/01/02 06:10:53 gram Exp $ * $Id: file.h,v 1.9 1999/01/07 16:15:35 gram Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -64,7 +64,9 @@ typedef struct _capture_file {
int swap; /* Swap data bytes? */ int swap; /* Swap data bytes? */
guint16 cd_t; /* Capture data type */ guint16 cd_t; /* Capture data type */
guint32 vers; /* Version. For tcpdump minor is appended to major */ guint32 vers; /* Version. For tcpdump minor is appended to major */
#ifndef WITH_WIRETAP
guint32 lnk_t; /* Network link type */ guint32 lnk_t; /* Network link type */
#endif
guint32 count; /* Packet count */ guint32 count; /* Packet count */
guint32 drops; /* Dropped packets */ guint32 drops; /* Dropped packets */
guint32 esec; /* Elapsed seconds */ guint32 esec; /* Elapsed seconds */

View File

@ -1,7 +1,7 @@
/* packet.c /* packet.c
* Routines for packet disassembly * Routines for packet disassembly
* *
* $Id: packet.c,v 1.17 1999/01/05 07:33:38 guy Exp $ * $Id: packet.c,v 1.18 1999/01/07 16:15:35 gram Exp $
* *
* Ethereal - Network traffic analyzer * Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org> * By Gerald Combs <gerald@zing.org>
@ -310,9 +310,6 @@ dissect_packet(const u_char *pd, frame_data *fd, GtkTree *tree)
GtkWidget *fh_tree, *ti; GtkWidget *fh_tree, *ti;
struct tm *tmp; struct tm *tmp;
time_t then; time_t then;
#ifdef WITH_WIRETAP
guint32 lnk_t;
#endif
/* Put in frame header information. */ /* Put in frame header information. */
if (check_col(fd, COL_ABS_TIME)) { if (check_col(fd, COL_ABS_TIME)) {
@ -357,14 +354,7 @@ dissect_packet(const u_char *pd, frame_data *fd, GtkTree *tree)
} }
#ifdef WITH_WIRETAP #ifdef WITH_WIRETAP
if (cf.lnk_t == WTAP_ENCAP_PER_PACKET) { switch (fd->lnk_t) {
lnk_t = fd->lnk_t;
}
else {
lnk_t = cf.lnk_t;
}
switch (lnk_t) {
case WTAP_ENCAP_ETHERNET : case WTAP_ENCAP_ETHERNET :
dissect_eth(pd, fd, tree); dissect_eth(pd, fd, tree);
break; break;

View File

@ -1,6 +1,6 @@
/* iptrace.c /* iptrace.c
* *
* $Id: iptrace.c,v 1.1 1999/01/03 04:30:13 gram Exp $ * $Id: iptrace.c,v 1.2 1999/01/07 16:15:35 gram Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu> * Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@ -41,7 +41,6 @@ int iptrace_open(wtap *wth)
if (strcmp(name, "iptrace 2.0") != 0) { if (strcmp(name, "iptrace 2.0") != 0) {
return WTAP_FILE_UNKNOWN; return WTAP_FILE_UNKNOWN;
} }
wth->encapsulation = WTAP_ENCAP_PER_PACKET;
wth->subtype_read = iptrace_read; wth->subtype_read = iptrace_read;
return WTAP_FILE_IPTRACE; return WTAP_FILE_IPTRACE;

View File

@ -1,6 +1,6 @@
/* lanalyzer.c /* lanalyzer.c
* *
* $Id: lanalyzer.c,v 1.6 1998/12/13 05:38:13 gram Exp $ * $Id: lanalyzer.c,v 1.7 1999/01/07 16:15:35 gram Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu> * Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@ -214,6 +214,7 @@ int lanalyzer_read(wtap *wth)
wth->phdr.len = true_size - 4; wth->phdr.len = true_size - 4;
wth->phdr.caplen = packet_size; wth->phdr.caplen = packet_size;
wth->phdr.pkt_encap = wth->encapsulation;
return data_offset; return data_offset;
} }

View File

@ -1,6 +1,6 @@
/* libpcap.c /* libpcap.c
* *
* $Id: libpcap.c,v 1.2 1998/12/17 06:39:10 gram Exp $ * $Id: libpcap.c,v 1.3 1999/01/07 16:15:36 gram Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu> * Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@ -207,6 +207,7 @@ int libpcap_read(wtap *wth)
wth->phdr.ts.tv_usec = hdr.ts_usec; wth->phdr.ts.tv_usec = hdr.ts_usec;
wth->phdr.caplen = packet_size; wth->phdr.caplen = packet_size;
wth->phdr.len = hdr.orig_len; wth->phdr.len = hdr.orig_len;
wth->phdr.pkt_encap = wth->encapsulation;
return data_offset; return data_offset;
} }

View File

@ -1,6 +1,6 @@
/* ngsniffer.c /* ngsniffer.c
* *
* $Id: ngsniffer.c,v 1.10 1998/12/17 06:39:12 gram Exp $ * $Id: ngsniffer.c,v 1.11 1999/01/07 16:15:36 gram Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu> * Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@ -746,5 +746,6 @@ found:
wth->phdr.ts.tv_sec = (long)t; wth->phdr.ts.tv_sec = (long)t;
wth->phdr.ts.tv_usec = (unsigned long)((t-(double)(wth->phdr.ts.tv_sec)) wth->phdr.ts.tv_usec = (unsigned long)((t-(double)(wth->phdr.ts.tv_sec))
*1.0e6); *1.0e6);
wth->phdr.pkt_encap = wth->encapsulation;
return data_offset; return data_offset;
} }

View File

@ -1,6 +1,6 @@
/* snoop.c /* snoop.c
* *
* $Id: snoop.c,v 1.1 1998/11/15 05:29:14 guy Exp $ * $Id: snoop.c,v 1.2 1999/01/07 16:15:36 gram Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu> * Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@ -145,6 +145,7 @@ int snoop_read(wtap *wth)
wth->phdr.ts.tv_usec = ntohl(hdr.ts_usec); wth->phdr.ts.tv_usec = ntohl(hdr.ts_usec);
wth->phdr.caplen = packet_size; wth->phdr.caplen = packet_size;
wth->phdr.len = ntohl(hdr.orig_len); wth->phdr.len = ntohl(hdr.orig_len);
wth->phdr.pkt_encap = wth->encapsulation;
/* Skip over the padding. */ /* Skip over the padding. */
fseek(wth->fh, ntohl(hdr.rec_len) - (sizeof hdr + packet_size), fseek(wth->fh, ntohl(hdr.rec_len) - (sizeof hdr + packet_size),

View File

@ -1,6 +1,6 @@
/* wtap.c /* wtap.c
* *
* $Id: wtap.c,v 1.3 1998/11/15 05:29:16 guy Exp $ * $Id: wtap.c,v 1.4 1999/01/07 16:15:36 gram Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu> * Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@ -33,11 +33,6 @@ int wtap_file_type(wtap *wth)
return wth->file_type; return wth->file_type;
} }
int wtap_encapsulation(wtap *wth)
{
return wth->encapsulation;
}
int wtap_snapshot_length(wtap *wth) int wtap_snapshot_length(wtap *wth)
{ {
@ -46,7 +41,27 @@ int wtap_snapshot_length(wtap *wth)
void wtap_close(wtap *wth) void wtap_close(wtap *wth)
{ {
/* XXX - free up memory? */ /* free up memory. If any capture structure ever allocates
* its own memory, it would be better to make a *close() function
* for each filetype, like pcap_close(0, lanalyzer_close(), etc.
* But for now this will work. */
switch(wth->file_type) {
case WTAP_FILE_PCAP:
free(wth->capture.pcap);
break;
case WTAP_FILE_LANALYZER:
free(wth->capture.lanalyzer);
break;
case WTAP_FILE_NGSNIFFER:
free(wth->capture.ngsniffer);
break;
default:
/* nothing */
}
fclose(wth->fh); fclose(wth->fh);
} }

View File

@ -1,6 +1,6 @@
/* wtap.h /* wtap.h
* *
* $Id: wtap.h,v 1.9 1999/01/02 06:10:55 gram Exp $ * $Id: wtap.h,v 1.10 1999/01/07 16:15:37 gram Exp $
* *
* Wiretap Library * Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu> * Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@ -32,7 +32,6 @@
#define WTAP_ENCAP_RAW_IP 6 #define WTAP_ENCAP_RAW_IP 6
#define WTAP_ENCAP_ARCNET 7 #define WTAP_ENCAP_ARCNET 7
#define WTAP_ENCAP_ATM_RFC1483 8 #define WTAP_ENCAP_ATM_RFC1483 8
#define WTAP_ENCAP_PER_PACKET 9
/* File types that can be read by wiretap */ /* File types that can be read by wiretap */
#define WTAP_FILE_UNKNOWN 0 #define WTAP_FILE_UNKNOWN 0
@ -109,7 +108,6 @@ void wtap_loop(wtap *wth, int, wtap_handler, u_char*);
FILE* wtap_file(wtap *wth); FILE* wtap_file(wtap *wth);
int wtap_snapshot_length(wtap *wth); /* per file */ int wtap_snapshot_length(wtap *wth); /* per file */
int wtap_file_type(wtap *wth); int wtap_file_type(wtap *wth);
int wtap_encapsulation(wtap *wth); /* per file */
void wtap_close(wtap *wth); void wtap_close(wtap *wth);