/* wtap.c
*
- * $Id: wtap.c,v 1.24 1999/10/05 07:22:53 guy Exp $
+ * $Id: wtap.c,v 1.35 1999/12/12 22:53:25 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
#include "file.h"
#include "buffer.h"
#include "ascend.h"
+#include "toshiba.h"
FILE* wtap_file(wtap *wth)
{
return wth->snapshot_length;
}
-const char *wtap_file_type_string(wtap *wth)
+int wtap_file_encap(wtap *wth)
{
- switch (wth->file_type) {
- case WTAP_FILE_WTAP:
- return "wiretap";
+ return wth->file_encap;
+}
- case WTAP_FILE_PCAP:
- return "pcap";
+/* Table of the encapsulation types we know about. */
+const static struct encap_type_info {
+ const char *name;
+ const char *short_name;
+} encap_table[WTAP_NUM_ENCAP_TYPES] = {
+ /* WTAP_ENCAP_UNKNOWN */
+ { "Unknown", NULL },
- case WTAP_FILE_LANALYZER:
- return "Novell LANalyzer";
+ /* WTAP_ENCAP_ETHERNET */
+ { "Ethernet", "ether" },
- case WTAP_FILE_NGSNIFFER:
- return "Network Associates Sniffer (DOS-based)";
+ /* WTAP_ENCAP_TR */
+ { "Token Ring", "tr" },
- case WTAP_FILE_SNOOP:
- return "snoop";
+ /* WTAP_ENCAP_SLIP */
+ { "SLIP", "slip" },
- case WTAP_FILE_IPTRACE:
- return "iptrace";
+ /* WTAP_ENCAP_PPP */
+ { "PPP", "ppp" },
- case WTAP_FILE_NETMON_1_x:
- return "Microsoft Network Monitor 1.x";
+ /* WTAP_ENCAP_FDDI */
+ { "FDDI", "fddi" },
- case WTAP_FILE_NETMON_2_x:
- return "Microsoft Network Monitor 2.x";
+ /* WTAP_ENCAP_FDDI_BITSWAPPED */
+ { "FDDI with bit-swapped MAC addresses", "fddi-swapped" },
- case WTAP_FILE_NETXRAY_1_0:
- return "Cinco Networks NetXRay";
+ /* WTAP_ENCAP_RAW_IP */
+ { "Raw IP", "rawip" },
- case WTAP_FILE_NETXRAY_1_1:
- return "Network Associates Sniffer (Windows-based) 1.1";
+ /* WTAP_ENCAP_ARCNET */
+ { "ARCNET", "arcnet" },
- case WTAP_FILE_NETXRAY_2_001:
- return "Network Associates Sniffer (Windows-based) 2.001";
+ /* WTAP_ENCAP_ATM_RFC1483 */
+ { "RFC 1483 ATM", "atm-rfc1483" },
- case WTAP_FILE_RADCOM:
- return "RADCOM WAN/LAN analyzer";
+ /* WTAP_ENCAP_LINUX_ATM_CLIP */
+ { "Linux ATM CLIP", "linux-atm-clip" },
- case WTAP_FILE_ASCEND:
- return "Lucent/Ascend access server trace";
+ /* WTAP_ENCAP_LAPB */
+ { "LAPB", "lapb" },
+
+ /* WTAP_ENCAP_ATM_SNIFFER */
+ { "ATM Sniffer", "atm-sniffer" },
+
+ /* WTAP_ENCAP_NULL */
+ { "NULL", "null" },
+
+ /* WTAP_ENCAP_ASCEND */
+ { "Lucent/Ascend access equipment", "ascend" },
+
+ /* WTAP_ENCAP_LAPD */
+ { "LAPD", "lapd" },
+
+ /* WTAP_ENCAP_V120 */
+ { "V.120", "v120" },
+};
- default:
- g_error("Unknown capture file type %d", wth->file_type);
- return NULL;
+/* Name that should be somewhat descriptive. */
+const char *wtap_encap_string(int encap)
+{
+ if (encap < 0 || encap >= WTAP_NUM_ENCAP_TYPES)
+ return NULL;
+ else
+ return encap_table[encap].name;
+}
+
+/* Name to use in, say, a command-line flag specifying the type. */
+const char *wtap_encap_short_string(int encap)
+{
+ if (encap < 0 || encap >= WTAP_NUM_ENCAP_TYPES)
+ return NULL;
+ else
+ return encap_table[encap].short_name;
+}
+
+/* Translate a short name to a capture file type. */
+int wtap_short_string_to_encap(const char *short_name)
+{
+ int encap;
+
+ for (encap = 0; encap < WTAP_NUM_ENCAP_TYPES; encap++) {
+ if (encap_table[encap].short_name != NULL &&
+ strcmp(short_name, encap_table[encap].short_name) == 0)
+ return encap;
}
+ return -1; /* no such encapsulation type */
}
static const char *wtap_errlist[] = {
* But for now this will work. */
switch(wth->file_type) {
case WTAP_FILE_PCAP:
+ case WTAP_FILE_PCAP_MODIFIED:
g_free(wth->capture.pcap);
break;
g_free(wth->capture.ascend);
break;
+ case WTAP_FILE_NETTL:
+ g_free(wth->capture.nettl);
+ break;
+
/* default:
nothing */
}
file_close(wth->fh);
+
+ if (wth->frame_buffer) {
+ buffer_free(wth->frame_buffer);
+ g_free(wth->frame_buffer);
+ }
+
+ g_free(wth);
}
int wtap_loop(wtap *wth, int count, wtap_handler callback, u_char* user,
return TRUE; /* success */
}
-int wtap_seek_read(int encaps, FILE *fh, int seek_off, guint8 *pd, int len)
+int wtap_seek_read(int file_type, FILE *fh, int seek_off, guint8 *pd, int len)
{
- switch (encaps) {
+ switch (file_type) {
- case WTAP_ENCAP_ASCEND:
+ 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);
}