6 * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
8 * Enhancements by Mark C. Brown <mbrown@hp.com>
9 * Copyright (C) 2003, 2005 Hewlett-Packard Development Company, L.P.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
34 #include "file_wrappers.h"
38 /* HP nettl file header */
40 /* Magic number size */
44 static guint8 nettl_magic_hpux9[MAGIC_SIZE] = {
45 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xD0, 0x00
47 /* HP-UX 10.x and 11.x */
48 static guint8 nettl_magic_hpux10[MAGIC_SIZE] = {
49 0x54, 0x52, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80
52 #define FILE_HDR_SIZE 128
53 #define NETTL_FILENAME_SIZE 56
55 struct nettl_file_hdr {
56 guint8 magic[MAGIC_SIZE];
57 gchar file_name[NETTL_FILENAME_SIZE];
64 guint16 unknown; /* just padding to 128 bytes? */
67 /* HP nettl record header */
68 /* see /usr/include/sys/netdiag1.h for hints */
86 * This is what we treat as the minimum size of a record header.
87 * It is *not* necessarily the same as sizeof(struct nettlrec_hdr),
88 * because it doesn't include any padding added to the structure.
90 #define NETTL_REC_HDR_LEN 64
92 /* HP nettl record header for the SX25L2 subsystem - The FCS is not included
94 struct nettlrec_sx25l2_hdr {
107 The following shows what the header and subheader looks like for NS_LS_DRIVER
108 The capture was taken on HPUX11 and for a 100baseT interface.
110 000080 00 44 00 0b 00 00 00 02 00 00 00 00 20 00 00 00
111 000090 00 00 00 00 00 00 04 06 00 00 00 00 00 00 00 00
112 0000a0 00 00 00 74 00 00 00 74 3c e3 76 19 00 06 34 63
113 0000b0 ff ff ff ff 00 00 00 00 00 00 00 00 ff ff ff ff
114 0000c0 00 00 00 00 00 00 01 02 00 5c 00 5c ff ff ff ff
115 0000d0 3c e3 76 19 00 06 34 5a 00 0b 00 14 <here starts the MAC header>
117 Each entry starts with 0x0044000b
119 The values 0x005c at position 0x0000c8 and 0x0000ca matches the number of
120 bytes in the packet up to the next entry, which starts with 0x00440b again.
121 These are the captured and real and captured length of the packet.
123 The values 0x00000074 at positions 0x0000a0 and 0x0000a4 seems to indicate
124 the same number as positions 0x0000c8 and 0x0000ca but added with 24.
125 Perhaps we have here two layers of headers.
126 The first layer is fixed and consists of all the bytes from 0x000084 up to and
127 including 0x0000c3 which is a generic header for all packets captured from any
128 device. This header might be of fixed size 64 bytes (although the first two
129 bytes appear to be the length of that header, in big-endian format) and there
130 might be something in it which indicates the type of the next header which is
131 link type specific. Following this header there is another header for the
132 100baseT interface which in this case is 24 bytes long spanning positions
133 0x0000c4 to 0x0000db.
135 In another capture, claimed to be taken on an HP-UX 8 box, but with a
136 file header suggesting it was taken on HP-UX 10.20, the header for
137 NS_LS_DRIVER looks like:
139 000080 00 40 00 0b ff ff ff ff 00 00 00 00 00 00 00 00
140 000090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
141 0000a0 00 00 00 51 00 00 00 51 42 02 5e bf 00 0e ab 7c
142 0000b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
143 0000c0 00 02 01 00 00 3b 00 3b ff ff ff ff 42 02 5e bf
144 0000d0 00 0e 8e 44 00 0b <here starts the MAC header>
146 When someone reports that the loading of the captures breaks, we can
147 compare this header above with what he/she got to learn how to
148 distinguish between different types of link specific headers.
151 For now, the subheader for 100baseT seems to be
159 struct nettlrec_ns_ls_drv_eth_hdr {
170 * This is the size of an NS_LS_DRV_ETH header; it is *not* necessarily
171 * the same as sizeof(struct nettlrec_ns_ls_drv_eth_hdr), because it
172 * doesn't include any padding added to the structure.
174 #define NS_LS_DRV_ETH_HDR_LEN 22
176 /* header is followed by data and once again the total length (2 bytes) ! */
178 static gboolean nettl_read(wtap *wth, int *err, gchar **err_info,
179 gint64 *data_offset);
180 static gboolean nettl_seek_read(wtap *wth, gint64 seek_off,
181 union wtap_pseudo_header *pseudo_header, guchar *pd,
182 int length, int *err, gchar **err_info);
183 static int nettl_read_rec_header(wtap *wth, FILE_T fh,
184 struct wtap_pkthdr *phdr, union wtap_pseudo_header *pseudo_header,
185 int *err, gchar **err_info, gboolean *fddihack);
186 static gboolean nettl_read_rec_data(FILE_T fh, guchar *pd, int length,
187 int *err, gboolean fddihack);
188 static void nettl_close(wtap *wth);
189 static gboolean nettl_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
190 const union wtap_pseudo_header *pseudo_header, const guchar *pd, int *err);
192 int nettl_open(wtap *wth, int *err, gchar **err_info _U_)
194 struct nettl_file_hdr file_hdr;
199 /* Read in the string that should be at the start of a HP file */
200 errno = WTAP_ERR_CANT_READ;
201 bytes_read = file_read(file_hdr.magic, 1, MAGIC_SIZE, wth->fh);
202 if (bytes_read != MAGIC_SIZE) {
203 *err = file_error(wth->fh);
209 if (memcmp(file_hdr.magic, nettl_magic_hpux9, MAGIC_SIZE) &&
210 memcmp(file_hdr.magic, nettl_magic_hpux10, MAGIC_SIZE)) {
214 /* Read the rest of the file header */
215 bytes_read = file_read(file_hdr.file_name, 1, FILE_HDR_SIZE - MAGIC_SIZE,
217 if (bytes_read != FILE_HDR_SIZE - MAGIC_SIZE) {
218 *err = file_error(wth->fh);
224 /* This is an nettl file */
225 wth->file_type = WTAP_FILE_NETTL;
226 wth->capture.nettl = g_malloc(sizeof(nettl_t));
227 if (file_hdr.os_vers[2] == '1' && file_hdr.os_vers[3] == '1')
228 wth->capture.nettl->is_hpux_11 = TRUE;
230 wth->capture.nettl->is_hpux_11 = FALSE;
231 wth->subtype_read = nettl_read;
232 wth->subtype_seek_read = nettl_seek_read;
233 wth->subtype_close = nettl_close;
234 wth->snapshot_length = 0; /* not available */
236 /* read the first header to take a guess at the file encap */
237 bytes_read = file_read(dummy, 1, 4, wth->fh);
238 if (bytes_read != 4) {
241 if (bytes_read != 0) {
242 *err = WTAP_ERR_SHORT_READ;
243 g_free(wth->capture.nettl);
249 subsys = g_ntohs(dummy[1]);
251 case NETTL_SUBSYS_HPPB_FDDI :
252 case NETTL_SUBSYS_EISA_FDDI :
253 case NETTL_SUBSYS_PCI_FDDI :
254 case NETTL_SUBSYS_HSC_FDDI :
255 wth->file_encap = WTAP_ENCAP_NETTL_FDDI;
257 case NETTL_SUBSYS_TOKEN :
258 case NETTL_SUBSYS_PCI_TR :
259 wth->file_encap = WTAP_ENCAP_NETTL_TOKEN_RING;
261 case NETTL_SUBSYS_NS_LS_IP :
262 case NETTL_SUBSYS_NS_LS_LOOPBACK :
263 case NETTL_SUBSYS_NS_LS_TCP :
264 case NETTL_SUBSYS_NS_LS_UDP :
265 case NETTL_SUBSYS_NS_LS_IPV6 :
266 wth->file_encap = WTAP_ENCAP_NETTL_RAW_IP;
268 case NETTL_SUBSYS_NS_LS_ICMP :
269 wth->file_encap = WTAP_ENCAP_NETTL_RAW_ICMP;
271 case NETTL_SUBSYS_NS_LS_ICMPV6 :
272 wth->file_encap = WTAP_ENCAP_NETTL_RAW_ICMPV6;
274 case NETTL_SUBSYS_NS_LS_TELNET :
275 wth->file_encap = WTAP_ENCAP_NETTL_RAW_TELNET;
278 /* If this assumption is bad, the read will catch it */
279 wth->file_encap = WTAP_ENCAP_NETTL_ETHERNET;
282 if (file_seek(wth->fh, FILE_HDR_SIZE, SEEK_SET, err) == -1) {
283 g_free(wth->capture.nettl);
286 wth->data_offset = FILE_HDR_SIZE;
287 wth->tsprecision = WTAP_FILE_TSPREC_USEC;
292 /* Read the next packet */
293 static gboolean nettl_read(wtap *wth, int *err, gchar **err_info,
297 gboolean fddihack=FALSE;
299 /* Read record header. */
300 *data_offset = wth->data_offset;
301 ret = nettl_read_rec_header(wth, wth->fh, &wth->phdr, &wth->pseudo_header,
302 err, err_info, &fddihack);
304 /* Read error or EOF */
307 wth->data_offset += ret;
310 * If the per-file encapsulation isn't known, set it to this
311 * packet's encapsulation.
313 * If it *is* known, and it isn't this packet's encapsulation,
314 * set it to WTAP_ENCAP_PER_PACKET, as this file doesn't
315 * have a single encapsulation for all packets in the file.
317 if (wth->file_encap == WTAP_ENCAP_UNKNOWN)
318 wth->file_encap = wth->phdr.pkt_encap;
320 if (wth->file_encap != wth->phdr.pkt_encap)
321 wth->file_encap = WTAP_ENCAP_PER_PACKET;
325 * Read the packet data.
327 buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
328 if (!nettl_read_rec_data(wth->fh, buffer_start_ptr(wth->frame_buffer),
329 wth->phdr.caplen, err, fddihack))
330 return FALSE; /* Read error */
331 wth->data_offset += wth->phdr.caplen;
336 nettl_seek_read(wtap *wth, gint64 seek_off,
337 union wtap_pseudo_header *pseudo_header, guchar *pd,
338 int length, int *err, gchar **err_info)
341 struct wtap_pkthdr phdr;
342 gboolean fddihack=FALSE;
344 if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
347 /* Read record header. */
348 ret = nettl_read_rec_header(wth, wth->random_fh, &phdr, pseudo_header,
349 err, err_info, &fddihack);
351 /* Read error or EOF */
353 /* EOF means "short read" in random-access mode */
354 *err = WTAP_ERR_SHORT_READ;
360 * Read the packet data.
362 return nettl_read_rec_data(wth->random_fh, pd, length, err, fddihack);
366 nettl_read_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
367 union wtap_pseudo_header *pseudo_header, int *err,
368 gchar **err_info, gboolean *fddihack)
371 struct nettlrec_hdr rec_hdr;
373 struct nettlrec_ns_ls_drv_eth_hdr drv_eth_hdr;
374 guint16 length, caplen;
380 errno = WTAP_ERR_CANT_READ;
381 bytes_read = file_read(&rec_hdr.hdr_len, 1, sizeof rec_hdr.hdr_len, fh);
382 if (bytes_read != sizeof rec_hdr.hdr_len) {
383 *err = file_error(fh);
386 if (bytes_read != 0) {
387 *err = WTAP_ERR_SHORT_READ;
393 hdr_len = g_ntohs(rec_hdr.hdr_len);
394 if (hdr_len < NETTL_REC_HDR_LEN) {
395 *err = WTAP_ERR_BAD_RECORD;
396 *err_info = g_strdup_printf("nettl: record header length %u too short",
400 bytes_read = file_read(&rec_hdr.subsys, 1, NETTL_REC_HDR_LEN - 2, fh);
401 if (bytes_read != NETTL_REC_HDR_LEN - 2) {
402 *err = file_error(fh);
404 *err = WTAP_ERR_SHORT_READ;
407 offset += NETTL_REC_HDR_LEN - 2;
408 subsys = g_ntohs(rec_hdr.subsys);
409 hdr_len -= NETTL_REC_HDR_LEN;
410 if (file_seek(fh, hdr_len, SEEK_CUR, err) == -1)
414 if ( ( (pntohl(&rec_hdr.kind) & ~NETTL_HDR_SUBSYSTEM_BITS_MASK)
415 & (NETTL_HDR_PROCEDURE_TRACE |
416 NETTL_HDR_STATE_TRACE |
417 NETTL_HDR_ERROR_TRACE) ) != 0) {
418 /* not actually a packet trace record */
419 phdr->pkt_encap = WTAP_ENCAP_NETTL_RAW_IP;
420 length = pntohl(&rec_hdr.length);
421 caplen = pntohl(&rec_hdr.caplen);
423 } else switch (subsys) {
424 case NETTL_SUBSYS_LAN100 :
425 case NETTL_SUBSYS_EISA100BT :
426 case NETTL_SUBSYS_BASE100 :
427 case NETTL_SUBSYS_GSC100BT :
428 case NETTL_SUBSYS_PCI100BT :
429 case NETTL_SUBSYS_SPP100BT :
430 case NETTL_SUBSYS_100VG :
431 case NETTL_SUBSYS_GELAN :
432 case NETTL_SUBSYS_BTLAN :
433 case NETTL_SUBSYS_INTL100 :
434 case NETTL_SUBSYS_IGELAN :
435 case NETTL_SUBSYS_IETHER :
436 case NETTL_SUBSYS_IXGBE :
437 case NETTL_SUBSYS_IGSSN :
438 case NETTL_SUBSYS_ICXGBE :
439 case NETTL_SUBSYS_HPPB_FDDI :
440 case NETTL_SUBSYS_EISA_FDDI :
441 case NETTL_SUBSYS_PCI_FDDI :
442 case NETTL_SUBSYS_HSC_FDDI :
443 case NETTL_SUBSYS_TOKEN :
444 case NETTL_SUBSYS_PCI_TR :
445 case NETTL_SUBSYS_NS_LS_IP :
446 case NETTL_SUBSYS_NS_LS_LOOPBACK :
447 case NETTL_SUBSYS_NS_LS_TCP :
448 case NETTL_SUBSYS_NS_LS_UDP :
449 case NETTL_SUBSYS_HP_APAPORT :
450 case NETTL_SUBSYS_HP_APALACP :
451 case NETTL_SUBSYS_NS_LS_IPV6 :
452 case NETTL_SUBSYS_NS_LS_ICMPV6 :
453 case NETTL_SUBSYS_NS_LS_ICMP :
454 case NETTL_SUBSYS_NS_LS_TELNET :
455 case NETTL_SUBSYS_NS_LS_SCTP :
456 if( (subsys == NETTL_SUBSYS_NS_LS_IP)
457 || (subsys == NETTL_SUBSYS_NS_LS_LOOPBACK)
458 || (subsys == NETTL_SUBSYS_NS_LS_UDP)
459 || (subsys == NETTL_SUBSYS_NS_LS_TCP)
460 || (subsys == NETTL_SUBSYS_NS_LS_SCTP)
461 || (subsys == NETTL_SUBSYS_NS_LS_IPV6)) {
462 phdr->pkt_encap = WTAP_ENCAP_NETTL_RAW_IP;
463 } else if (subsys == NETTL_SUBSYS_NS_LS_ICMP) {
464 phdr->pkt_encap = WTAP_ENCAP_NETTL_RAW_ICMP;
465 } else if (subsys == NETTL_SUBSYS_NS_LS_ICMPV6) {
466 phdr->pkt_encap = WTAP_ENCAP_NETTL_RAW_ICMPV6;
467 } else if (subsys == NETTL_SUBSYS_NS_LS_TELNET) {
468 phdr->pkt_encap = WTAP_ENCAP_NETTL_RAW_TELNET;
469 } else if( (subsys == NETTL_SUBSYS_HPPB_FDDI)
470 || (subsys == NETTL_SUBSYS_EISA_FDDI)
471 || (subsys == NETTL_SUBSYS_PCI_FDDI)
472 || (subsys == NETTL_SUBSYS_HSC_FDDI) ) {
473 phdr->pkt_encap = WTAP_ENCAP_NETTL_FDDI;
474 } else if( (subsys == NETTL_SUBSYS_PCI_TR)
475 || (subsys == NETTL_SUBSYS_TOKEN) ) {
476 phdr->pkt_encap = WTAP_ENCAP_NETTL_TOKEN_RING;
478 phdr->pkt_encap = WTAP_ENCAP_NETTL_ETHERNET;
481 length = pntohl(&rec_hdr.length);
482 caplen = pntohl(&rec_hdr.caplen);
484 /* HPPB FDDI has different inbound vs outbound trace records */
485 if (subsys == NETTL_SUBSYS_HPPB_FDDI) {
486 if (pntohl(&rec_hdr.kind) == NETTL_HDR_PDUIN) {
487 /* inbound is very strange...
488 there are an extra 3 bytes after the DSAP and SSAP
494 /* outbound appears to have variable padding */
495 bytes_read = file_read(dummyc, 1, 9, fh);
496 if (bytes_read != 9) {
497 *err = file_error(fh);
499 *err = WTAP_ERR_SHORT_READ;
502 /* padding is usually either a total 11 or 16 bytes??? */
503 padlen = (int)dummyc[8];
504 if (file_seek(fh, padlen, SEEK_CUR, err) == -1)
509 } else if ( (subsys == NETTL_SUBSYS_PCI_FDDI)
510 || (subsys == NETTL_SUBSYS_EISA_FDDI)
511 || (subsys == NETTL_SUBSYS_HSC_FDDI) ) {
512 /* other flavor FDDI cards have an extra 3 bytes of padding */
513 if (file_seek(fh, 3, SEEK_CUR, err) == -1)
517 } else if (subsys == NETTL_SUBSYS_NS_LS_LOOPBACK) {
518 /* LOOPBACK has an extra 26 bytes of padding */
519 if (file_seek(fh, 26, SEEK_CUR, err) == -1)
523 } else if (subsys == NETTL_SUBSYS_NS_LS_SCTP) {
525 * SCTP 8 byte header that we will ignore...
526 * 32 bit integer defines format
529 * 3 = Binary (PDUs should be Binary format)
530 * 32 bit integer defines type
534 if (file_seek(fh, 8, SEEK_CUR, err) == -1)
543 case NETTL_SUBSYS_NS_LS_DRIVER :
544 /* XXX we dont know how to identify this as ethernet frames, so
545 we assumes everything is. We will crash and burn for anything else */
546 /* for encapsulated 100baseT we do this */
547 phdr->pkt_encap = WTAP_ENCAP_NETTL_ETHERNET;
548 bytes_read = file_read(&drv_eth_hdr, 1, NS_LS_DRV_ETH_HDR_LEN, fh);
549 if (bytes_read != NS_LS_DRV_ETH_HDR_LEN) {
550 *err = file_error(fh);
552 *err = WTAP_ERR_SHORT_READ;
555 offset += NS_LS_DRV_ETH_HDR_LEN;
557 length = pntohs(&drv_eth_hdr.length);
558 caplen = pntohs(&drv_eth_hdr.caplen);
560 * XXX - is there a length field that would give the length
561 * of this header, so that we don't have to check for
562 * nettl files from HP-UX 11?
564 * And what are the extra two bytes?
566 if (wth->capture.nettl->is_hpux_11) {
567 if (file_seek(fh, 2, SEEK_CUR, err) == -1) return -1;
573 case NETTL_SUBSYS_SX25L2:
574 case NETTL_SUBSYS_SX25L3:
576 * XXX - is the 24-byte padding actually a header with
577 * packet lengths, time stamps, etc., just as is the case
578 * for NETTL_SUBSYS_NS_LS_DRIVER? It might be
587 * or something such as that - if it has 4 bytes before that
588 * (making it 24 bytes), it'd be like struct
589 * nettlrec_ns_ls_drv_eth_hdr but with 2 more bytes at the end.
591 * And is "from_dce" at xxa[0] in the nettlrec_hdr structure?
593 phdr->pkt_encap = WTAP_ENCAP_NETTL_X25;
594 length = pntohl(&rec_hdr.length);
595 caplen = pntohl(&rec_hdr.caplen);
596 padlen = 24; /* sizeof (struct nettlrec_sx25l2_hdr) - NETTL_REC_HDR_LEN + 4 */
597 if (file_seek(fh, padlen, SEEK_CUR, err) == -1)
603 wth->file_encap = WTAP_ENCAP_PER_PACKET;
604 phdr->pkt_encap = WTAP_ENCAP_NETTL_UNKNOWN;
605 length = pntohl(&rec_hdr.length);
606 caplen = pntohl(&rec_hdr.caplen);
611 if (length < padlen) {
612 *err = WTAP_ERR_BAD_RECORD;
613 *err_info = g_strdup_printf("nettl: packet length %u in record header too short, less than %u",
617 phdr->len = length - padlen;
618 if (caplen < padlen) {
619 *err = WTAP_ERR_BAD_RECORD;
620 *err_info = g_strdup_printf("nettl: captured length %u in record header too short, less than %u",
624 phdr->caplen = caplen - padlen;
625 phdr->ts.secs = pntohl(&rec_hdr.sec);
626 phdr->ts.nsecs = pntohl(&rec_hdr.usec) * 1000;
628 pseudo_header->nettl.subsys = subsys;
629 pseudo_header->nettl.devid = pntohl(&rec_hdr.devid);
630 pseudo_header->nettl.kind = pntohl(&rec_hdr.kind);
631 pseudo_header->nettl.pid = pntohl(&rec_hdr.pid);
632 pseudo_header->nettl.uid = pntohs(&rec_hdr.uid);
638 nettl_read_rec_data(FILE_T fh, guchar *pd, int length, int *err, gboolean fddihack)
644 if (fddihack == TRUE) {
645 /* read in FC, dest, src, DSAP and SSAP */
646 if (file_read(pd, 1, 15, fh) == 15) {
647 if (pd[13] == 0xAA) {
648 /* it's SNAP, have to eat 3 bytes??? */
649 if (file_read(dummy, 1, 3, fh) == 3) {
651 bytes_read = file_read(p, 1, length-18, fh);
659 bytes_read = file_read(p, 1, length-15, fh);
665 bytes_read = file_read(pd, 1, length, fh);
667 if (bytes_read != length) {
668 *err = file_error(fh);
670 *err = WTAP_ERR_SHORT_READ;
676 static void nettl_close(wtap *wth)
678 g_free(wth->capture.nettl);
682 /* Returns 0 if we could write the specified encapsulation type,
683 an error indication otherwise. nettl files are WTAP_ENCAP_UNKNOWN
684 when they are first opened, so we allow that for tshark read/write.
687 int nettl_dump_can_write_encap(int encap)
691 case WTAP_ENCAP_ETHERNET:
692 case WTAP_ENCAP_FDDI_BITSWAPPED:
693 case WTAP_ENCAP_TOKEN_RING:
694 case WTAP_ENCAP_NETTL_ETHERNET:
695 case WTAP_ENCAP_NETTL_FDDI:
696 case WTAP_ENCAP_NETTL_TOKEN_RING:
697 case WTAP_ENCAP_NETTL_RAW_IP:
698 case WTAP_ENCAP_NETTL_RAW_ICMP:
699 case WTAP_ENCAP_NETTL_RAW_ICMPV6:
700 case WTAP_ENCAP_NETTL_RAW_TELNET:
702 case WTAP_ENCAP_NETTL_X25:
704 case WTAP_ENCAP_PER_PACKET:
705 case WTAP_ENCAP_UNKNOWN:
706 case WTAP_ENCAP_NETTL_UNKNOWN:
709 return WTAP_ERR_UNSUPPORTED_ENCAP;
714 /* Returns TRUE on success, FALSE on failure;
715 sets "*err" to an error code on failure */
716 gboolean nettl_dump_open(wtap_dumper *wdh, gboolean cant_seek _U_, int *err)
718 struct nettl_file_hdr file_hdr;
721 /* This is a nettl file */
722 wdh->subtype_write = nettl_dump;
723 wdh->subtype_close = NULL;
725 /* Write the file header. */
726 memset(&file_hdr,0,sizeof(file_hdr));
727 memcpy(file_hdr.magic,nettl_magic_hpux10,sizeof(file_hdr.magic));
728 g_strlcpy(file_hdr.file_name,"/tmp/wireshark.TRC000",NETTL_FILENAME_SIZE);
729 g_strlcpy(file_hdr.tz,"UTC",20);
730 g_strlcpy(file_hdr.host_name,"",9);
731 g_strlcpy(file_hdr.os_vers,"B.11.11",9);
733 g_strlcpy(file_hdr.model,"9000/800",11);
734 file_hdr.unknown=g_htons(0x406);
735 nwritten = fwrite(&file_hdr, 1, sizeof file_hdr, wdh->fh);
736 if (nwritten != sizeof(file_hdr)) {
737 if (nwritten == 0 && ferror(wdh->fh))
740 *err = WTAP_ERR_SHORT_WRITE;
743 wdh->bytes_dumped += sizeof(file_hdr);
748 /* Write a record for a packet to a dump file.
749 Returns TRUE on success, FALSE on failure. */
750 static gboolean nettl_dump(wtap_dumper *wdh,
751 const struct wtap_pkthdr *phdr,
752 const union wtap_pseudo_header *pseudo_header _U_,
753 const guchar *pd, int *err)
755 struct nettlrec_hdr rec_hdr;
759 memset(&rec_hdr,0,sizeof(rec_hdr));
760 /* HP-UX 11.X header should be 68 bytes */
761 rec_hdr.hdr_len = g_htons(sizeof(rec_hdr) + 4);
762 rec_hdr.kind = g_htonl(NETTL_HDR_PDUIN);
763 rec_hdr.sec = g_htonl(phdr->ts.secs);
764 rec_hdr.usec = g_htonl(phdr->ts.nsecs/1000);
765 rec_hdr.caplen = g_htonl(phdr->caplen);
766 rec_hdr.length = g_htonl(phdr->len);
771 switch (phdr->pkt_encap) {
773 case WTAP_ENCAP_NETTL_FDDI:
774 /* account for pad bytes */
775 rec_hdr.caplen = g_htonl(phdr->caplen + 3);
776 rec_hdr.length = g_htonl(phdr->len + 3);
777 /* fall through and fill the rest of the fields */
778 case WTAP_ENCAP_NETTL_ETHERNET:
779 case WTAP_ENCAP_NETTL_TOKEN_RING:
780 case WTAP_ENCAP_NETTL_RAW_IP:
781 case WTAP_ENCAP_NETTL_RAW_ICMP:
782 case WTAP_ENCAP_NETTL_RAW_ICMPV6:
783 case WTAP_ENCAP_NETTL_RAW_TELNET:
784 case WTAP_ENCAP_NETTL_UNKNOWN:
785 rec_hdr.subsys = g_htons(pseudo_header->nettl.subsys);
786 rec_hdr.devid = g_htonl(pseudo_header->nettl.devid);
787 rec_hdr.kind = g_htonl(pseudo_header->nettl.kind);
788 rec_hdr.pid = g_htonl(pseudo_header->nettl.pid);
789 rec_hdr.uid = g_htons(pseudo_header->nettl.uid);
792 case WTAP_ENCAP_RAW_IP:
793 rec_hdr.subsys = g_htons(NETTL_SUBSYS_NS_LS_IP);
796 case WTAP_ENCAP_ETHERNET:
797 rec_hdr.subsys = g_htons(NETTL_SUBSYS_BTLAN);
800 case WTAP_ENCAP_FDDI_BITSWAPPED:
801 rec_hdr.subsys = g_htons(NETTL_SUBSYS_PCI_FDDI);
802 /* account for pad bytes */
803 rec_hdr.caplen = g_htonl(phdr->caplen + 3);
804 rec_hdr.length = g_htonl(phdr->len + 3);
807 case WTAP_ENCAP_TOKEN_RING:
808 rec_hdr.subsys = g_htons(NETTL_SUBSYS_PCI_TR);
811 case WTAP_ENCAP_NETTL_X25:
812 rec_hdr.caplen = g_htonl(phdr->caplen + 24);
813 rec_hdr.length = g_htonl(phdr->len + 24);
814 rec_hdr.subsys = g_htons(pseudo_header->nettl.subsys);
815 rec_hdr.devid = g_htonl(pseudo_header->nettl.devid);
816 rec_hdr.kind = g_htonl(pseudo_header->nettl.kind);
817 rec_hdr.pid = g_htonl(pseudo_header->nettl.pid);
818 rec_hdr.uid = g_htons(pseudo_header->nettl.uid);
822 /* found one we don't support */
823 *err = WTAP_ERR_UNSUPPORTED_ENCAP;
827 nwritten = fwrite(&rec_hdr, 1, sizeof(rec_hdr), wdh->fh);
828 if (nwritten != sizeof(rec_hdr)) {
829 if (nwritten == 0 && ferror(wdh->fh))
832 *err = WTAP_ERR_SHORT_WRITE;
835 wdh->bytes_dumped += sizeof(rec_hdr);
837 /* Write out 4 extra bytes of unknown stuff for HP-UX11
840 memset(dummyc, 0, sizeof dummyc);
841 nwritten = fwrite(dummyc, 1, 4, wdh->fh);
843 if (nwritten == 0 && ferror(wdh->fh))
846 *err = WTAP_ERR_SHORT_WRITE;
849 wdh->bytes_dumped += 4;
851 if ((phdr->pkt_encap == WTAP_ENCAP_FDDI_BITSWAPPED) ||
852 (phdr->pkt_encap == WTAP_ENCAP_NETTL_FDDI)) {
853 /* add those weird 3 bytes of padding */
854 nwritten = fwrite(dummyc, 1, 3, wdh->fh);
856 if (nwritten == 0 && ferror(wdh->fh))
859 *err = WTAP_ERR_SHORT_WRITE;
862 wdh->bytes_dumped += 3;
865 } else if (phdr->pkt_encap == WTAP_ENCAP_NETTL_X25) {
866 nwritten = fwrite(dummyc, 1, 24, wdh->fh);
867 if (nwritten != 24) {
868 if (nwritten == 0 && ferror(wdh->fh))
871 *err = WTAP_ERR_SHORT_WRITE;
874 wdh->bytes_dumped += 24;
878 /* write actual PDU data */
880 nwritten = fwrite(pd, 1, phdr->caplen, wdh->fh);
881 if (nwritten != phdr->caplen) {
882 if (nwritten == 0 && ferror(wdh->fh))
885 *err = WTAP_ERR_SHORT_WRITE;
888 wdh->bytes_dumped += phdr->caplen;