* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
*
+ * Enhancements by Mark C. Brown <mbrown@hp.com>
+ * Copyright (C) 2003, 2005 Hewlett-Packard Development Company, L.P.
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
0x54, 0x52, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80
};
+/* HP nettl file header */
+struct nettl_file_hdr {
+ guchar magic[12];
+ guchar file_name[56];
+ guchar tz[20];
+ guchar host_name[9];
+ guchar os_vers[9];
+ guchar os_v;
+ guint8 xxa[8];
+ guchar model[11];
+ guint16 unknown;
+};
+
/* HP nettl record header for the SX25L2 subsystem - The FCS is not included in the file. */
struct nettlrec_sx25l2_hdr {
guint8 xxa[8];
/* HP nettl record header for the NS_LS_IP subsystem */
/* This also works for BASE100 and GSC100BT */
+/* see /usr/include/sys/netdiag1.h for hints */
struct nettlrec_ns_ls_ip_hdr {
- guint8 xxa[8];
- guint8 rectype;
- guint8 xxb[19];
- guint8 caplen[4];
- guint8 length[4];
- guint8 sec[4];
- guint8 usec[4];
- guint8 xxc[16];
+ guint32 devid;
+ guint8 xxa[4];
+ guint32 kind;
+ guint8 xxb[16];
+ guint32 caplen;
+ guint32 length;
+ guint32 sec;
+ guint32 usec;
+ guint32 pid;
+ guint8 xxc[10];
+ guint16 uid;
};
+/* Full record header for writing out a nettl file */
+struct nettlrec_dump_hdr {
+ guint16 hdr_len;
+ guint16 subsys;
+ struct nettlrec_ns_ls_ip_hdr hdr;
+ guint8 xxd[4];
+};
/* header is followed by data and once again the total length (2 bytes) ! */
static gboolean nettl_read_rec_data(FILE_T fh, guchar *pd, int length,
int *err, gboolean fddihack);
static void nettl_close(wtap *wth);
+static gboolean nettl_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
+ const union wtap_pseudo_header *pseudo_header, const guchar *pd, int *err);
int nettl_open(wtap *wth, int *err, gchar **err_info _U_)
{
char magic[12], os_vers[2];
+ guint16 dummy[2];
+ int subsys;
int bytes_read;
/* Read in the string that should be at the start of a HP file */
wth->subtype_close = nettl_close;
wth->snapshot_length = 0; /* not available in header, only in frame */
+ /* read the first header to take a guess at the file encap */
+ bytes_read = file_read(dummy, 1, 4, wth->fh);
+ if (bytes_read != 4) {
+ if (*err != 0)
+ return -1;
+ if (bytes_read != 0) {
+ *err = WTAP_ERR_SHORT_READ;
+ return -1;
+ }
+ return 0;
+ }
+
+ subsys = g_ntohs(dummy[1]);
+ switch (subsys) {
+ case NETTL_SUBSYS_HPPB_FDDI :
+ case NETTL_SUBSYS_EISA_FDDI :
+ case NETTL_SUBSYS_PCI_FDDI :
+ case NETTL_SUBSYS_HSC_FDDI :
+ wth->file_encap = WTAP_ENCAP_NETTL_FDDI;
+ break;
+ case NETTL_SUBSYS_TOKEN :
+ case NETTL_SUBSYS_PCI_TR :
+ wth->file_encap = WTAP_ENCAP_NETTL_TOKEN_RING;
+ break;
+ case NETTL_SUBSYS_NS_LS_IP :
+ case NETTL_SUBSYS_NS_LS_LOOPBACK :
+ case NETTL_SUBSYS_NS_LS_TCP :
+ case NETTL_SUBSYS_NS_LS_UDP :
+ case NETTL_SUBSYS_NS_LS_IPV6 :
+ wth->file_encap = WTAP_ENCAP_NETTL_RAW_IP;
+ break;
+ default:
+ /* If this assumption is bad, the read will catch it */
+ wth->file_encap = WTAP_ENCAP_NETTL_ETHERNET;
+ }
+
+ if (file_seek(wth->fh, 0x80, SEEK_SET, err) == -1)
+ return -1;
+ wth->data_offset = 0x80;
+
return 1;
}
struct nettlrec_ns_ls_drv_eth_hdr drv_eth_hdr;
guint16 length;
int offset = 0;
- int encap;
+ int subsys;
int padlen;
- guint8 dummy[4];
+ guint16 dummy[2];
guchar dummyc[12];
errno = WTAP_ERR_CANT_READ;
return 0;
}
offset += 4;
- encap=dummy[3];
- switch (encap) {
+ subsys = g_ntohs(dummy[1]);
+ switch (subsys) {
case NETTL_SUBSYS_LAN100 :
+ case NETTL_SUBSYS_EISA100BT :
case NETTL_SUBSYS_BASE100 :
case NETTL_SUBSYS_GSC100BT :
case NETTL_SUBSYS_PCI100BT :
case NETTL_SUBSYS_SPP100BT :
+ case NETTL_SUBSYS_100VG :
case NETTL_SUBSYS_GELAN :
case NETTL_SUBSYS_BTLAN :
case NETTL_SUBSYS_INTL100 :
case NETTL_SUBSYS_IGELAN :
case NETTL_SUBSYS_IETHER :
+ case NETTL_SUBSYS_IXGBE :
case NETTL_SUBSYS_HPPB_FDDI :
+ case NETTL_SUBSYS_EISA_FDDI :
case NETTL_SUBSYS_PCI_FDDI :
+ case NETTL_SUBSYS_HSC_FDDI :
case NETTL_SUBSYS_TOKEN :
case NETTL_SUBSYS_PCI_TR :
case NETTL_SUBSYS_NS_LS_IP :
case NETTL_SUBSYS_NS_LS_IPV6 :
case NETTL_SUBSYS_NS_LS_ICMPV6 :
case NETTL_SUBSYS_NS_LS_ICMP :
- if( (encap == NETTL_SUBSYS_NS_LS_IP)
- || (encap == NETTL_SUBSYS_NS_LS_LOOPBACK)
- || (encap == NETTL_SUBSYS_NS_LS_UDP)
- || (encap == NETTL_SUBSYS_NS_LS_TCP)
- || (encap == NETTL_SUBSYS_NS_LS_IPV6)) {
- phdr->pkt_encap = WTAP_ENCAP_RAW_IP;
- } else if (encap == NETTL_SUBSYS_NS_LS_ICMP) {
- phdr->pkt_encap = WTAP_ENCAP_RAW_ICMP;
- } else if (encap == NETTL_SUBSYS_NS_LS_ICMPV6) {
- phdr->pkt_encap = WTAP_ENCAP_RAW_ICMPV6;
- } else if( (encap == NETTL_SUBSYS_HPPB_FDDI)
- || (encap == NETTL_SUBSYS_PCI_FDDI) ) {
- phdr->pkt_encap = WTAP_ENCAP_FDDI;
- } else if( (encap == NETTL_SUBSYS_PCI_TR)
- || (encap == NETTL_SUBSYS_TOKEN) ) {
- phdr->pkt_encap = WTAP_ENCAP_TOKEN_RING;
+ if( (subsys == NETTL_SUBSYS_NS_LS_IP)
+ || (subsys == NETTL_SUBSYS_NS_LS_LOOPBACK)
+ || (subsys == NETTL_SUBSYS_NS_LS_UDP)
+ || (subsys == NETTL_SUBSYS_NS_LS_TCP)
+ || (subsys == NETTL_SUBSYS_NS_LS_IPV6)) {
+ phdr->pkt_encap = WTAP_ENCAP_NETTL_RAW_IP;
+ } else if (subsys == NETTL_SUBSYS_NS_LS_ICMP) {
+ phdr->pkt_encap = WTAP_ENCAP_NETTL_RAW_ICMP;
+ } else if (subsys == NETTL_SUBSYS_NS_LS_ICMPV6) {
+ phdr->pkt_encap = WTAP_ENCAP_NETTL_RAW_ICMPV6;
+ } else if( (subsys == NETTL_SUBSYS_HPPB_FDDI)
+ || (subsys == NETTL_SUBSYS_EISA_FDDI)
+ || (subsys == NETTL_SUBSYS_PCI_FDDI)
+ || (subsys == NETTL_SUBSYS_HSC_FDDI) ) {
+ phdr->pkt_encap = WTAP_ENCAP_NETTL_FDDI;
+ } else if( (subsys == NETTL_SUBSYS_PCI_TR)
+ || (subsys == NETTL_SUBSYS_TOKEN) ) {
+ phdr->pkt_encap = WTAP_ENCAP_NETTL_TOKEN_RING;
} else {
- phdr->pkt_encap = WTAP_ENCAP_ETHERNET;
- /* We assume there's no FCS in this frame. */
- pseudo_header->eth.fcs_len = 0;
+ phdr->pkt_encap = WTAP_ENCAP_NETTL_ETHERNET;
}
bytes_read = file_read(&ip_hdr, 1, sizeof ip_hdr, fh);
}
/* HPPB FDDI has different inbound vs outbound trace records */
- if (encap == NETTL_SUBSYS_HPPB_FDDI) {
- if (ip_hdr.rectype == NETTL_HDR_PDUIN) {
+ if (subsys == NETTL_SUBSYS_HPPB_FDDI) {
+ if (pntohl(&ip_hdr.kind) == NETTL_HDR_PDUIN) {
/* inbound is very strange...
there are an extra 3 bytes after the DSAP and SSAP
for SNAP frames ???
if (length <= 0)
return 0;
phdr->len = length;
- length = pntohl(&ip_hdr.caplen);
- phdr->caplen = length;
+ phdr->caplen = pntohl(&ip_hdr.caplen);
} else {
- /* outbound has an extra padding */
+ /* outbound appears to have variable padding */
bytes_read = file_read(dummyc, 1, 9, fh);
if (bytes_read != 9) {
*err = file_error(fh);
length = pntohl(&ip_hdr.caplen);
phdr->caplen = length - padlen;
}
- } else if (encap == NETTL_SUBSYS_PCI_FDDI) {
- /* PCI FDDI has an extra 3 bytes of padding */
+ } else if ( (subsys == NETTL_SUBSYS_PCI_FDDI)
+ || (subsys == NETTL_SUBSYS_EISA_FDDI)
+ || (subsys == NETTL_SUBSYS_HSC_FDDI) ) {
+ /* other flavor FDDI cards have an extra 3 bytes of padding */
bytes_read = file_read(dummy, 1, 3, fh);
if (bytes_read != 3) {
*err = file_error(fh);
phdr->len = length - 3;
length = pntohl(&ip_hdr.caplen);
phdr->caplen = length - 3;
- } else if (encap == NETTL_SUBSYS_NS_LS_LOOPBACK) {
+ } else if (subsys == NETTL_SUBSYS_NS_LS_LOOPBACK) {
/* LOOPBACK has an extra 26 bytes of padding */
bytes_read = file_read(dummy, 1, 26, fh);
if (bytes_read != 26) {
if (length <= 0)
return 0;
phdr->len = length;
- length = pntohl(&ip_hdr.caplen);
- phdr->caplen = length;
+ phdr->caplen = pntohl(&ip_hdr.caplen);
}
phdr->ts.tv_sec = pntohl(&ip_hdr.sec);
/* XXX we dont know how to identify this as ethernet frames, so
we assumes everything is. We will crash and burn for anything else */
/* for encapsulated 100baseT we do this */
- phdr->pkt_encap = WTAP_ENCAP_ETHERNET;
- /* We assume there's no FCS in this frame. */
- pseudo_header->eth.fcs_len = 0;
+ phdr->pkt_encap = WTAP_ENCAP_NETTL_ETHERNET;
bytes_read = file_read(&drv_eth_hdr, 1, sizeof drv_eth_hdr, fh);
if (bytes_read != sizeof drv_eth_hdr) {
*err = file_error(fh);
length = pntohs(&drv_eth_hdr.length);
if (length <= 0) return 0;
phdr->len = length;
- length = pntohs(&drv_eth_hdr.caplen);
- phdr->caplen = length;
+ phdr->caplen = pntohs(&drv_eth_hdr.caplen);
phdr->ts.tv_sec = pntohl(&ip_hdr.sec);
phdr->ts.tv_usec = pntohl(&ip_hdr.usec);
(lapb_hdr.from_dce & 0x20 ? FROM_DCE : 0x00);
break;
default:
- *err = WTAP_ERR_UNSUPPORTED_ENCAP;
- *err_info = g_strdup_printf("nettl: subsystem %u unknown or unsupported",
- encap);
- return -1;
+ wth->file_encap = WTAP_ENCAP_PER_PACKET;
+ phdr->pkt_encap = WTAP_ENCAP_NETTL_UNKNOWN;
+ 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) {
+ *err = WTAP_ERR_SHORT_READ;
+ return -1;
+ }
+ return 0;
+ }
+ offset += sizeof ip_hdr;
+ length = pntohl(&ip_hdr.length);
+ if (length <= 0) return 0;
+ phdr->len = length;
+ phdr->caplen = pntohl(&ip_hdr.caplen);
+ phdr->ts.tv_sec = pntohl(&ip_hdr.sec);
+ phdr->ts.tv_usec = pntohl(&ip_hdr.usec);
+ 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) {
+ *err = WTAP_ERR_SHORT_READ;
+ return -1;
+ }
+ return 0;
+ }
+ offset += 4;
+ }
}
+
+ pseudo_header->nettl.subsys = subsys;
+ pseudo_header->nettl.devid = pntohl(&ip_hdr.devid);
+ pseudo_header->nettl.kind = pntohl(&ip_hdr.kind);
+ pseudo_header->nettl.pid = pntohl(&ip_hdr.pid);
+ pseudo_header->nettl.uid = pntohs(&ip_hdr.uid);
+
return offset;
}
guint8 dummy[3];
if (fddihack == TRUE) {
- /* read in FC, dest, src and DSAP */
- if (file_read(pd, 1, 14, fh) == 14) {
+ /* read in FC, dest, src, DSAP and SSAP */
+ if (file_read(pd, 1, 15, fh) == 15) {
if (pd[13] == 0xAA) {
/* it's SNAP, have to eat 3 bytes??? */
if (file_read(dummy, 1, 3, fh) == 3) {
- p=pd+14;
- bytes_read = file_read(p, 1, length-17, fh);
- bytes_read += 17;
+ p=pd+15;
+ bytes_read = file_read(p, 1, length-18, fh);
+ bytes_read += 18;
} else {
bytes_read = -1;
}
} else {
/* not SNAP */
- p=pd+14;
- bytes_read = file_read(p, 1, length-14, fh);
- bytes_read += 14;
+ p=pd+15;
+ bytes_read = file_read(p, 1, length-15, fh);
+ bytes_read += 15;
}
} else
bytes_read = -1;
{
g_free(wth->capture.nettl);
}
+
+
+/* Returns 0 if we could write the specified encapsulation type,
+ an error indication otherwise. nettl files are WTAP_ENCAP_UNKNOWN
+ when they are first opened, so we allow that for tethereal read/write.
+ */
+
+int nettl_dump_can_write_encap(int encap)
+{
+
+ switch (encap) {
+ case WTAP_ENCAP_ETHERNET:
+ case WTAP_ENCAP_FDDI_BITSWAPPED:
+ case WTAP_ENCAP_TOKEN_RING:
+ case WTAP_ENCAP_NETTL_ETHERNET:
+ case WTAP_ENCAP_NETTL_FDDI:
+ case WTAP_ENCAP_NETTL_TOKEN_RING:
+ case WTAP_ENCAP_NETTL_RAW_IP:
+ case WTAP_ENCAP_NETTL_RAW_ICMP:
+ case WTAP_ENCAP_NETTL_RAW_ICMPV6:
+ case WTAP_ENCAP_PER_PACKET:
+ case WTAP_ENCAP_UNKNOWN:
+ case WTAP_ENCAP_NETTL_UNKNOWN:
+ return 0;
+ default:
+ return WTAP_ERR_UNSUPPORTED_ENCAP;
+ }
+}
+
+
+/* Returns TRUE on success, FALSE on failure;
+ sets "*err" to an error code on failure */
+gboolean nettl_dump_open(wtap_dumper *wdh, gboolean cant_seek _U_, int *err)
+{
+ struct nettl_file_hdr file_hdr;
+ size_t nwritten;
+
+ /* This is a nettl file */
+ wdh->subtype_write = nettl_dump;
+ wdh->subtype_close = NULL;
+
+ /* Write the file header. */
+ memset(&file_hdr,0,sizeof(file_hdr));
+ memcpy(file_hdr.magic,nettl_magic_hpux10,sizeof(file_hdr.magic));
+ strcpy(file_hdr.file_name,"/tmp/ethereal.TRC000");
+ strcpy(file_hdr.tz,"UTC");
+ strcpy(file_hdr.host_name,"ethereal");
+ strcpy(file_hdr.os_vers,"B.11.11");
+ file_hdr.os_v=0x55;
+ strcpy(file_hdr.model,"9000/800");
+ file_hdr.unknown=g_htons(0x406);
+ nwritten = fwrite(&file_hdr, 1, sizeof file_hdr, wdh->fh);
+ if (nwritten != sizeof(file_hdr)) {
+ if (nwritten == 0 && ferror(wdh->fh))
+ *err = errno;
+ else
+ *err = WTAP_ERR_SHORT_WRITE;
+ return FALSE;
+ }
+ wdh->bytes_dumped += sizeof(file_hdr);
+
+ return TRUE;
+}
+
+/* Write a record for a packet to a dump file.
+ Returns TRUE on success, FALSE on failure. */
+static gboolean nettl_dump(wtap_dumper *wdh,
+ const struct wtap_pkthdr *phdr,
+ const union wtap_pseudo_header *pseudo_header _U_,
+ const guchar *pd, int *err)
+{
+ struct nettlrec_dump_hdr rec_hdr;
+ guint32 dummy=0;
+ size_t nwritten;
+
+ memset(&rec_hdr,0,sizeof(rec_hdr));
+ rec_hdr.hdr_len = g_htons(sizeof(rec_hdr));
+ rec_hdr.hdr.kind = g_htonl(NETTL_HDR_PDUIN);
+ rec_hdr.hdr.sec = g_htonl(phdr->ts.tv_sec);
+ rec_hdr.hdr.usec = g_htonl(phdr->ts.tv_usec);
+ rec_hdr.hdr.caplen = g_htonl(phdr->caplen);
+ rec_hdr.hdr.length = g_htonl(phdr->len);
+ rec_hdr.hdr.devid = -1;
+ rec_hdr.hdr.pid = -1;
+ rec_hdr.hdr.uid = -1;
+
+ switch (phdr->pkt_encap) {
+
+ case WTAP_ENCAP_NETTL_FDDI:
+ /* account for pad bytes */
+ rec_hdr.hdr.caplen = g_htonl(phdr->caplen + 3);
+ rec_hdr.hdr.length = g_htonl(phdr->len + 3);
+ /* fall through and fill the rest of the fields */
+ case WTAP_ENCAP_NETTL_ETHERNET:
+ case WTAP_ENCAP_NETTL_TOKEN_RING:
+ case WTAP_ENCAP_NETTL_RAW_IP:
+ case WTAP_ENCAP_NETTL_RAW_ICMP:
+ case WTAP_ENCAP_NETTL_RAW_ICMPV6:
+ case WTAP_ENCAP_NETTL_UNKNOWN:
+ rec_hdr.subsys = g_htons(pseudo_header->nettl.subsys);
+ rec_hdr.hdr.devid = g_htonl(pseudo_header->nettl.devid);
+ rec_hdr.hdr.kind = g_htonl(pseudo_header->nettl.kind);
+ rec_hdr.hdr.pid = g_htonl(pseudo_header->nettl.pid);
+ rec_hdr.hdr.uid = g_htons(pseudo_header->nettl.uid);
+ break;
+
+ case WTAP_ENCAP_RAW_IP:
+ rec_hdr.subsys = g_htons(NETTL_SUBSYS_NS_LS_IP);
+ break;
+
+ case WTAP_ENCAP_ETHERNET:
+ rec_hdr.subsys = g_htons(NETTL_SUBSYS_BTLAN);
+ break;
+
+ case WTAP_ENCAP_FDDI_BITSWAPPED:
+ rec_hdr.subsys = g_htons(NETTL_SUBSYS_PCI_FDDI);
+ /* account for pad bytes */
+ rec_hdr.hdr.caplen = g_htonl(phdr->caplen + 3);
+ rec_hdr.hdr.length = g_htonl(phdr->len + 3);
+ break;
+
+ case WTAP_ENCAP_TOKEN_RING:
+ rec_hdr.subsys = g_htons(NETTL_SUBSYS_PCI_TR);
+ break;
+
+ default:
+ /* found one we don't support */
+ *err = WTAP_ERR_UNSUPPORTED_ENCAP;
+ return FALSE;
+ }
+
+ nwritten = fwrite(&rec_hdr, 1, sizeof(rec_hdr), wdh->fh);
+ if (nwritten != sizeof(rec_hdr)) {
+ if (nwritten == 0 && ferror(wdh->fh))
+ *err = errno;
+ else
+ *err = WTAP_ERR_SHORT_WRITE;
+ return FALSE;
+ }
+ wdh->bytes_dumped += sizeof(rec_hdr);
+
+ if ((phdr->pkt_encap == WTAP_ENCAP_FDDI_BITSWAPPED) ||
+ (phdr->pkt_encap == WTAP_ENCAP_NETTL_FDDI)) {
+ /* add those weird 3 bytes of padding */
+ nwritten = fwrite(&dummy, 1, 3, wdh->fh);
+ if (nwritten != 3) {
+ if (nwritten == 0 && ferror(wdh->fh))
+ *err = errno;
+ else
+ *err = WTAP_ERR_SHORT_WRITE;
+ return FALSE;
+ }
+ wdh->bytes_dumped += 3;
+ }
+
+ /* write actual PDU data */
+
+ nwritten = fwrite(pd, 1, phdr->caplen, wdh->fh);
+ if (nwritten != phdr->caplen) {
+ if (nwritten == 0 && ferror(wdh->fh))
+ *err = errno;
+ else
+ *err = WTAP_ERR_SHORT_WRITE;
+ return FALSE;
+ }
+ wdh->bytes_dumped += phdr->caplen;
+
+ return TRUE;
+}