4 * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
6 * Enhancements by Mark C. Brown <mbrown@hp.com>
7 * Copyright (C) 2003, 2005 Hewlett-Packard Development Company, L.P.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 #include "file_wrappers.h"
31 #include <wsutil/buffer.h>
34 /* HP nettl file header */
36 /* Magic number size */
40 static const guint8 nettl_magic_hpux9[MAGIC_SIZE] = {
41 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xD0, 0x00
43 /* HP-UX 10.x and 11.x */
44 static const guint8 nettl_magic_hpux10[MAGIC_SIZE] = {
45 0x54, 0x52, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80
48 #define FILE_HDR_SIZE 128
49 #define NETTL_FILENAME_SIZE 56
51 struct nettl_file_hdr {
52 guint8 magic[MAGIC_SIZE];
53 gchar file_name[NETTL_FILENAME_SIZE];
60 guint16 unknown; /* just padding to 128 bytes? */
63 /* HP nettl record header */
64 /* see /usr/include/sys/netdiag1.h for hints */
82 * This is what we treat as the minimum size of a record header.
83 * It is *not* necessarily the same as sizeof(struct nettlrec_hdr),
84 * because it doesn't include any padding added to the structure.
86 #define NETTL_REC_HDR_LEN 64
88 /* HP nettl record header for the SX25L2 subsystem - The FCS is not included
90 struct nettlrec_sx25l2_hdr {
103 The following shows what the header and subheader looks like for NS_LS_DRIVER
104 The capture was taken on HPUX11 and for a 100baseT interface.
106 000080 00 44 00 0b 00 00 00 02 00 00 00 00 20 00 00 00
107 000090 00 00 00 00 00 00 04 06 00 00 00 00 00 00 00 00
108 0000a0 00 00 00 74 00 00 00 74 3c e3 76 19 00 06 34 63
109 0000b0 ff ff ff ff 00 00 00 00 00 00 00 00 ff ff ff ff
110 0000c0 00 00 00 00 00 00 01 02 00 5c 00 5c ff ff ff ff
111 0000d0 3c e3 76 19 00 06 34 5a 00 0b 00 14 <here starts the MAC header>
113 Each entry starts with 0x0044000b
115 The values 0x005c at position 0x0000c8 and 0x0000ca matches the number of
116 bytes in the packet up to the next entry, which starts with 0x00440b again.
117 These are the captured and real and captured length of the packet.
119 The values 0x00000074 at positions 0x0000a0 and 0x0000a4 seems to indicate
120 the same number as positions 0x0000c8 and 0x0000ca but added with 24.
121 Perhaps we have here two layers of headers.
122 The first layer is fixed and consists of all the bytes from 0x000084 up to and
123 including 0x0000c3 which is a generic header for all packets captured from any
124 device. This header might be of fixed size 64 bytes (although the first two
125 bytes appear to be the length of that header, in big-endian format) and there
126 might be something in it which indicates the type of the next header which is
127 link type specific. Following this header there is another header for the
128 100baseT interface which in this case is 24 bytes long spanning positions
129 0x0000c4 to 0x0000db.
131 In another capture, claimed to be taken on an HP-UX 8 box, but with a
132 file header suggesting it was taken on HP-UX 10.20, the header for
133 NS_LS_DRIVER looks like:
135 000080 00 40 00 0b ff ff ff ff 00 00 00 00 00 00 00 00
136 000090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
137 0000a0 00 00 00 51 00 00 00 51 42 02 5e bf 00 0e ab 7c
138 0000b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
139 0000c0 00 02 01 00 00 3b 00 3b ff ff ff ff 42 02 5e bf
140 0000d0 00 0e 8e 44 00 0b <here starts the MAC header>
142 When someone reports that the loading of the captures breaks, we can
143 compare this header above with what he/she got to learn how to
144 distinguish between different types of link specific headers.
147 For now, the subheader for 100baseT seems to be
155 struct nettlrec_ns_ls_drv_eth_hdr {
166 * This is the size of an NS_LS_DRV_ETH header; it is *not* necessarily
167 * the same as sizeof(struct nettlrec_ns_ls_drv_eth_hdr), because it
168 * doesn't include any padding added to the structure.
170 #define NS_LS_DRV_ETH_HDR_LEN 22
172 /* 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 struct wtap_pkthdr *phdr, Buffer *buf,
182 int *err, gchar **err_info);
183 static gboolean nettl_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
184 Buffer *buf, int *err, gchar **err_info);
185 static gboolean nettl_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
186 const guint8 *pd, int *err);
188 int nettl_open(wtap *wth, int *err, gchar **err_info)
190 struct nettl_file_hdr file_hdr;
195 memset(&file_hdr, 0, sizeof(file_hdr));
197 /* Read in the string that should be at the start of a HP file */
198 if (!wtap_read_bytes(wth->fh, file_hdr.magic, MAGIC_SIZE, err, err_info)) {
199 if (*err != WTAP_ERR_SHORT_READ)
204 if (memcmp(file_hdr.magic, nettl_magic_hpux9, MAGIC_SIZE) &&
205 memcmp(file_hdr.magic, nettl_magic_hpux10, MAGIC_SIZE)) {
209 /* Read the rest of the file header */
210 if (!wtap_read_bytes(wth->fh, file_hdr.file_name, FILE_HDR_SIZE - MAGIC_SIZE,
214 /* This is an nettl file */
215 wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_NETTL;
216 nettl = g_new(nettl_t,1);
217 wth->priv = (void *)nettl;
218 if (file_hdr.os_vers[2] == '1' && file_hdr.os_vers[3] == '1')
219 nettl->is_hpux_11 = TRUE;
221 nettl->is_hpux_11 = FALSE;
222 wth->subtype_read = nettl_read;
223 wth->subtype_seek_read = nettl_seek_read;
224 wth->snapshot_length = 0; /* not available */
226 /* read the first header to take a guess at the file encap */
227 if (!wtap_read_bytes_or_eof(wth->fh, dummy, 4, err, err_info)) {
229 /* EOF, so no records */
235 subsys = g_ntohs(dummy[1]);
237 case NETTL_SUBSYS_HPPB_FDDI :
238 case NETTL_SUBSYS_EISA_FDDI :
239 case NETTL_SUBSYS_PCI_FDDI :
240 case NETTL_SUBSYS_HSC_FDDI :
241 wth->file_encap = WTAP_ENCAP_NETTL_FDDI;
243 case NETTL_SUBSYS_TOKEN :
244 case NETTL_SUBSYS_PCI_TR :
245 wth->file_encap = WTAP_ENCAP_NETTL_TOKEN_RING;
247 case NETTL_SUBSYS_NS_LS_IP :
248 case NETTL_SUBSYS_NS_LS_LOOPBACK :
249 case NETTL_SUBSYS_NS_LS_TCP :
250 case NETTL_SUBSYS_NS_LS_UDP :
251 case NETTL_SUBSYS_NS_LS_IPV6 :
252 wth->file_encap = WTAP_ENCAP_NETTL_RAW_IP;
254 case NETTL_SUBSYS_NS_LS_ICMP :
255 wth->file_encap = WTAP_ENCAP_NETTL_RAW_ICMP;
257 case NETTL_SUBSYS_NS_LS_ICMPV6 :
258 wth->file_encap = WTAP_ENCAP_NETTL_RAW_ICMPV6;
260 case NETTL_SUBSYS_NS_LS_TELNET :
261 wth->file_encap = WTAP_ENCAP_NETTL_RAW_TELNET;
264 /* If this assumption is bad, the read will catch it */
265 wth->file_encap = WTAP_ENCAP_NETTL_ETHERNET;
268 if (file_seek(wth->fh, FILE_HDR_SIZE, SEEK_SET, err) == -1) {
271 wth->file_tsprec = WTAP_TSPREC_USEC;
276 /* Read the next packet */
277 static gboolean nettl_read(wtap *wth, int *err, gchar **err_info,
281 *data_offset = file_tell(wth->fh);
282 if (!nettl_read_rec(wth, wth->fh, &wth->phdr, wth->frame_buffer,
284 /* Read error or EOF */
289 * If the per-file encapsulation isn't known, set it to this
290 * packet's encapsulation.
292 * If it *is* known, and it isn't this packet's encapsulation,
293 * set it to WTAP_ENCAP_PER_PACKET, as this file doesn't
294 * have a single encapsulation for all packets in the file.
296 if (wth->file_encap == WTAP_ENCAP_UNKNOWN)
297 wth->file_encap = wth->phdr.pkt_encap;
299 if (wth->file_encap != wth->phdr.pkt_encap)
300 wth->file_encap = WTAP_ENCAP_PER_PACKET;
307 nettl_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
308 Buffer *buf, int *err, gchar **err_info)
310 if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
314 if (!nettl_read_rec(wth, wth->random_fh, phdr, buf, err, err_info)) {
315 /* Read error or EOF */
317 /* EOF means "short read" in random-access mode */
318 *err = WTAP_ERR_SHORT_READ;
326 nettl_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
327 int *err, gchar **err_info)
329 union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
330 nettl_t *nettl = (nettl_t *)wth->priv;
331 gboolean fddihack = FALSE;
332 struct nettlrec_hdr rec_hdr;
334 struct nettlrec_ns_ls_drv_eth_hdr drv_eth_hdr;
335 guint32 length, caplen;
343 if (!wtap_read_bytes_or_eof(fh, &rec_hdr.hdr_len, sizeof rec_hdr.hdr_len,
346 hdr_len = g_ntohs(rec_hdr.hdr_len);
347 if (hdr_len < NETTL_REC_HDR_LEN) {
348 *err = WTAP_ERR_BAD_FILE;
349 *err_info = g_strdup_printf("nettl: record header length %u too short",
353 if (!wtap_read_bytes(fh, &rec_hdr.subsys, NETTL_REC_HDR_LEN - 2,
356 subsys = g_ntohs(rec_hdr.subsys);
357 hdr_len -= NETTL_REC_HDR_LEN;
358 if (file_seek(fh, hdr_len, SEEK_CUR, err) == -1)
361 if ( (pntoh32(&rec_hdr.kind) & NETTL_HDR_PDU_MASK) == 0 ) {
362 /* not actually a data packet (PDU) trace record */
363 phdr->pkt_encap = WTAP_ENCAP_NETTL_RAW_IP;
364 length = pntoh32(&rec_hdr.length);
365 caplen = pntoh32(&rec_hdr.caplen);
367 } else switch (subsys) {
368 case NETTL_SUBSYS_LAN100 :
369 case NETTL_SUBSYS_EISA100BT :
370 case NETTL_SUBSYS_BASE100 :
371 case NETTL_SUBSYS_GSC100BT :
372 case NETTL_SUBSYS_PCI100BT :
373 case NETTL_SUBSYS_SPP100BT :
374 case NETTL_SUBSYS_100VG :
375 case NETTL_SUBSYS_GELAN :
376 case NETTL_SUBSYS_BTLAN :
377 case NETTL_SUBSYS_INTL100 :
378 case NETTL_SUBSYS_IGELAN :
379 case NETTL_SUBSYS_IETHER :
380 case NETTL_SUBSYS_IXGBE :
381 case NETTL_SUBSYS_HSSN :
382 case NETTL_SUBSYS_IGSSN :
383 case NETTL_SUBSYS_ICXGBE :
384 case NETTL_SUBSYS_IEXGBE :
385 case NETTL_SUBSYS_IOCXGBE :
386 case NETTL_SUBSYS_IQXGBE :
387 case NETTL_SUBSYS_HPPB_FDDI :
388 case NETTL_SUBSYS_EISA_FDDI :
389 case NETTL_SUBSYS_PCI_FDDI :
390 case NETTL_SUBSYS_HSC_FDDI :
391 case NETTL_SUBSYS_TOKEN :
392 case NETTL_SUBSYS_PCI_TR :
393 case NETTL_SUBSYS_NS_LS_IP :
394 case NETTL_SUBSYS_NS_LS_LOOPBACK :
395 case NETTL_SUBSYS_NS_LS_TCP :
396 case NETTL_SUBSYS_NS_LS_UDP :
397 case NETTL_SUBSYS_HP_APAPORT :
398 case NETTL_SUBSYS_HP_APALACP :
399 case NETTL_SUBSYS_NS_LS_IPV6 :
400 case NETTL_SUBSYS_NS_LS_ICMPV6 :
401 case NETTL_SUBSYS_NS_LS_ICMP :
402 case NETTL_SUBSYS_NS_LS_TELNET :
403 case NETTL_SUBSYS_NS_LS_SCTP :
404 if( (subsys == NETTL_SUBSYS_NS_LS_IP)
405 || (subsys == NETTL_SUBSYS_NS_LS_LOOPBACK)
406 || (subsys == NETTL_SUBSYS_NS_LS_UDP)
407 || (subsys == NETTL_SUBSYS_NS_LS_TCP)
408 || (subsys == NETTL_SUBSYS_NS_LS_SCTP)
409 || (subsys == NETTL_SUBSYS_NS_LS_IPV6)) {
410 phdr->pkt_encap = WTAP_ENCAP_NETTL_RAW_IP;
411 } else if (subsys == NETTL_SUBSYS_NS_LS_ICMP) {
412 phdr->pkt_encap = WTAP_ENCAP_NETTL_RAW_ICMP;
413 } else if (subsys == NETTL_SUBSYS_NS_LS_ICMPV6) {
414 phdr->pkt_encap = WTAP_ENCAP_NETTL_RAW_ICMPV6;
415 } else if (subsys == NETTL_SUBSYS_NS_LS_TELNET) {
416 phdr->pkt_encap = WTAP_ENCAP_NETTL_RAW_TELNET;
417 } else if( (subsys == NETTL_SUBSYS_HPPB_FDDI)
418 || (subsys == NETTL_SUBSYS_EISA_FDDI)
419 || (subsys == NETTL_SUBSYS_PCI_FDDI)
420 || (subsys == NETTL_SUBSYS_HSC_FDDI) ) {
421 phdr->pkt_encap = WTAP_ENCAP_NETTL_FDDI;
422 } else if( (subsys == NETTL_SUBSYS_PCI_TR)
423 || (subsys == NETTL_SUBSYS_TOKEN) ) {
424 phdr->pkt_encap = WTAP_ENCAP_NETTL_TOKEN_RING;
426 phdr->pkt_encap = WTAP_ENCAP_NETTL_ETHERNET;
429 length = pntoh32(&rec_hdr.length);
430 caplen = pntoh32(&rec_hdr.caplen);
432 /* HPPB FDDI has different inbound vs outbound trace records */
433 if (subsys == NETTL_SUBSYS_HPPB_FDDI) {
434 if (pntoh32(&rec_hdr.kind) == NETTL_HDR_PDUIN) {
435 /* inbound is very strange...
436 there are an extra 3 bytes after the DSAP and SSAP
442 /* outbound appears to have variable padding */
443 if (!wtap_read_bytes(fh, dummyc, 9, err, err_info))
445 /* padding is usually either a total 11 or 16 bytes??? */
446 padlen = (int)dummyc[8];
447 if (file_seek(fh, padlen, SEEK_CUR, err) == -1)
451 } else if ( (subsys == NETTL_SUBSYS_PCI_FDDI)
452 || (subsys == NETTL_SUBSYS_EISA_FDDI)
453 || (subsys == NETTL_SUBSYS_HSC_FDDI) ) {
454 /* other flavor FDDI cards have an extra 3 bytes of padding */
455 if (file_seek(fh, 3, SEEK_CUR, err) == -1)
458 } else if (subsys == NETTL_SUBSYS_NS_LS_LOOPBACK) {
459 /* LOOPBACK has an extra 26 bytes of padding */
460 if (file_seek(fh, 26, SEEK_CUR, err) == -1)
463 } else if (subsys == NETTL_SUBSYS_NS_LS_SCTP) {
465 * SCTP 8 byte header that we will ignore...
466 * 32 bit integer defines format
469 * 3 = Binary (PDUs should be Binary format)
470 * 32 bit integer defines type
474 if (file_seek(fh, 8, SEEK_CUR, err) == -1)
482 case NETTL_SUBSYS_NS_LS_DRIVER :
483 /* XXX we don't know how to identify this as ethernet frames, so
484 we assume everything is. We will crash and burn for anything else */
485 /* for encapsulated 100baseT we do this */
486 phdr->pkt_encap = WTAP_ENCAP_NETTL_ETHERNET;
487 if (!wtap_read_bytes(fh, &drv_eth_hdr, NS_LS_DRV_ETH_HDR_LEN,
491 length = pntoh16(&drv_eth_hdr.length);
492 caplen = pntoh16(&drv_eth_hdr.caplen);
494 * XXX - is there a length field that would give the length
495 * of this header, so that we don't have to check for
496 * nettl files from HP-UX 11?
498 * And what are the extra two bytes?
500 if (nettl->is_hpux_11) {
501 if (file_seek(fh, 2, SEEK_CUR, err) == -1) return FALSE;
506 case NETTL_SUBSYS_SX25L2:
507 case NETTL_SUBSYS_SX25L3:
509 * XXX - is the 24-byte padding actually a header with
510 * packet lengths, time stamps, etc., just as is the case
511 * for NETTL_SUBSYS_NS_LS_DRIVER? It might be
520 * or something such as that - if it has 4 bytes before that
521 * (making it 24 bytes), it'd be like struct
522 * nettlrec_ns_ls_drv_eth_hdr but with 2 more bytes at the end.
524 * And is "from_dce" at xxa[0] in the nettlrec_hdr structure?
526 phdr->pkt_encap = WTAP_ENCAP_NETTL_X25;
527 length = pntoh32(&rec_hdr.length);
528 caplen = pntoh32(&rec_hdr.caplen);
529 padlen = 24; /* sizeof (struct nettlrec_sx25l2_hdr) - NETTL_REC_HDR_LEN + 4 */
530 if (file_seek(fh, padlen, SEEK_CUR, err) == -1)
535 /* We're going to assume it's ethernet if we don't recognize the
536 subsystem -- We'll probably spew junks and core if it isn't... */
537 wth->file_encap = WTAP_ENCAP_PER_PACKET;
538 phdr->pkt_encap = WTAP_ENCAP_NETTL_ETHERNET;
539 length = pntoh32(&rec_hdr.length);
540 caplen = pntoh32(&rec_hdr.caplen);
545 if (length < padlen) {
546 *err = WTAP_ERR_BAD_FILE;
547 *err_info = g_strdup_printf("nettl: packet length %u in record header too short, less than %u",
551 phdr->rec_type = REC_TYPE_PACKET;
552 phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
553 phdr->len = length - padlen;
554 if (caplen < padlen) {
555 *err = WTAP_ERR_BAD_FILE;
556 *err_info = g_strdup_printf("nettl: captured length %u in record header too short, less than %u",
560 datalen = caplen - padlen;
561 phdr->caplen = datalen;
562 phdr->ts.secs = pntoh32(&rec_hdr.sec);
563 phdr->ts.nsecs = pntoh32(&rec_hdr.usec) * 1000;
565 pseudo_header->nettl.subsys = subsys;
566 pseudo_header->nettl.devid = pntoh32(&rec_hdr.devid);
567 pseudo_header->nettl.kind = pntoh32(&rec_hdr.kind);
568 pseudo_header->nettl.pid = pntoh32(&rec_hdr.pid);
569 pseudo_header->nettl.uid = pntoh16(&rec_hdr.uid);
571 if (phdr->caplen > WTAP_MAX_PACKET_SIZE) {
573 * Probably a corrupt capture file; don't blow up trying
574 * to allocate space for an immensely-large packet.
576 *err = WTAP_ERR_BAD_FILE;
577 *err_info = g_strdup_printf("nettl: File has %u-byte packet, bigger than maximum of %u",
578 phdr->caplen, WTAP_MAX_PACKET_SIZE);
583 * Read the packet data.
585 ws_buffer_assure_space(buf, datalen);
586 pd = ws_buffer_start_ptr(buf);
588 /* read in FC, dest, src, DSAP and SSAP */
590 if (bytes_to_read > datalen)
591 bytes_to_read = datalen;
592 if (!wtap_read_bytes(fh, pd, bytes_to_read, err, err_info))
594 datalen -= bytes_to_read;
596 /* There's nothing past the FC, dest, src, DSAP and SSAP */
599 if (pd[13] == 0xAA) {
600 /* it's SNAP, have to eat 3 bytes??? */
602 if (bytes_to_read > datalen)
603 bytes_to_read = datalen;
604 if (!file_skip(fh, bytes_to_read, err))
606 datalen -= bytes_to_read;
608 /* There's nothing past the FC, dest, src, DSAP, SSAP, and 3 bytes to eat */
612 if (!wtap_read_bytes(fh, pd + 15, datalen, err, err_info))
615 if (!wtap_read_bytes(fh, pd, datalen, err, err_info))
622 /* Returns 0 if we could write the specified encapsulation type,
623 an error indication otherwise. nettl files are WTAP_ENCAP_UNKNOWN
624 when they are first opened, so we allow that for tshark read/write.
627 int nettl_dump_can_write_encap(int encap)
631 case WTAP_ENCAP_ETHERNET:
632 case WTAP_ENCAP_FDDI_BITSWAPPED:
633 case WTAP_ENCAP_TOKEN_RING:
634 case WTAP_ENCAP_NETTL_ETHERNET:
635 case WTAP_ENCAP_NETTL_FDDI:
636 case WTAP_ENCAP_NETTL_TOKEN_RING:
637 case WTAP_ENCAP_NETTL_RAW_IP:
638 case WTAP_ENCAP_NETTL_RAW_ICMP:
639 case WTAP_ENCAP_NETTL_RAW_ICMPV6:
640 case WTAP_ENCAP_NETTL_RAW_TELNET:
642 case WTAP_ENCAP_NETTL_X25:
644 case WTAP_ENCAP_PER_PACKET:
645 case WTAP_ENCAP_UNKNOWN:
646 case WTAP_ENCAP_NETTL_UNKNOWN:
649 return WTAP_ERR_UNSUPPORTED_ENCAP;
654 /* Returns TRUE on success, FALSE on failure;
655 sets "*err" to an error code on failure */
656 gboolean nettl_dump_open(wtap_dumper *wdh, int *err)
658 struct nettl_file_hdr file_hdr;
660 /* This is a nettl file */
661 wdh->subtype_write = nettl_dump;
662 wdh->subtype_close = NULL;
664 /* Write the file header. */
665 memset(&file_hdr,0,sizeof(file_hdr));
666 memcpy(file_hdr.magic,nettl_magic_hpux10,sizeof(file_hdr.magic));
667 g_strlcpy(file_hdr.file_name,"/tmp/wireshark.TRC000",NETTL_FILENAME_SIZE);
668 g_strlcpy(file_hdr.tz,"UTC",20);
669 g_strlcpy(file_hdr.host_name,"",9);
670 g_strlcpy(file_hdr.os_vers,"B.11.11",9);
672 g_strlcpy(file_hdr.model,"9000/800",11);
673 file_hdr.unknown=g_htons(0x406);
674 if (!wtap_dump_file_write(wdh, &file_hdr, sizeof file_hdr, err))
676 wdh->bytes_dumped += sizeof(file_hdr);
681 /* Write a record for a packet to a dump file.
682 Returns TRUE on success, FALSE on failure. */
683 static gboolean nettl_dump(wtap_dumper *wdh,
684 const struct wtap_pkthdr *phdr,
685 const guint8 *pd, int *err)
687 const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
688 struct nettlrec_hdr rec_hdr;
691 /* We can only write packet records. */
692 if (phdr->rec_type != REC_TYPE_PACKET) {
693 *err = WTAP_ERR_REC_TYPE_UNSUPPORTED;
697 /* Don't write anything we're not willing to read. */
698 if (phdr->caplen > WTAP_MAX_PACKET_SIZE) {
699 *err = WTAP_ERR_PACKET_TOO_LARGE;
703 memset(&rec_hdr,0,sizeof(rec_hdr));
704 /* HP-UX 11.X header should be 68 bytes */
705 rec_hdr.hdr_len = g_htons(sizeof(rec_hdr) + 4);
706 rec_hdr.kind = g_htonl(NETTL_HDR_PDUIN);
707 rec_hdr.sec = g_htonl(phdr->ts.secs);
708 rec_hdr.usec = g_htonl(phdr->ts.nsecs/1000);
709 rec_hdr.caplen = g_htonl(phdr->caplen);
710 rec_hdr.length = g_htonl(phdr->len);
715 switch (phdr->pkt_encap) {
717 case WTAP_ENCAP_NETTL_FDDI:
718 /* account for pad bytes */
719 rec_hdr.caplen = g_htonl(phdr->caplen + 3);
720 rec_hdr.length = g_htonl(phdr->len + 3);
721 /* fall through and fill the rest of the fields */
722 case WTAP_ENCAP_NETTL_ETHERNET:
723 case WTAP_ENCAP_NETTL_TOKEN_RING:
724 case WTAP_ENCAP_NETTL_RAW_IP:
725 case WTAP_ENCAP_NETTL_RAW_ICMP:
726 case WTAP_ENCAP_NETTL_RAW_ICMPV6:
727 case WTAP_ENCAP_NETTL_RAW_TELNET:
728 case WTAP_ENCAP_NETTL_UNKNOWN:
729 rec_hdr.subsys = g_htons(pseudo_header->nettl.subsys);
730 rec_hdr.devid = g_htonl(pseudo_header->nettl.devid);
731 rec_hdr.kind = g_htonl(pseudo_header->nettl.kind);
732 rec_hdr.pid = g_htonl(pseudo_header->nettl.pid);
733 rec_hdr.uid = g_htons(pseudo_header->nettl.uid);
736 case WTAP_ENCAP_RAW_IP:
737 rec_hdr.subsys = g_htons(NETTL_SUBSYS_NS_LS_IP);
740 case WTAP_ENCAP_ETHERNET:
741 rec_hdr.subsys = g_htons(NETTL_SUBSYS_BTLAN);
744 case WTAP_ENCAP_FDDI_BITSWAPPED:
745 rec_hdr.subsys = g_htons(NETTL_SUBSYS_PCI_FDDI);
746 /* account for pad bytes */
747 rec_hdr.caplen = g_htonl(phdr->caplen + 3);
748 rec_hdr.length = g_htonl(phdr->len + 3);
751 case WTAP_ENCAP_TOKEN_RING:
752 rec_hdr.subsys = g_htons(NETTL_SUBSYS_PCI_TR);
755 case WTAP_ENCAP_NETTL_X25:
756 rec_hdr.caplen = g_htonl(phdr->caplen + 24);
757 rec_hdr.length = g_htonl(phdr->len + 24);
758 rec_hdr.subsys = g_htons(pseudo_header->nettl.subsys);
759 rec_hdr.devid = g_htonl(pseudo_header->nettl.devid);
760 rec_hdr.kind = g_htonl(pseudo_header->nettl.kind);
761 rec_hdr.pid = g_htonl(pseudo_header->nettl.pid);
762 rec_hdr.uid = g_htons(pseudo_header->nettl.uid);
766 /* found one we don't support */
767 *err = WTAP_ERR_UNSUPPORTED_ENCAP;
771 if (!wtap_dump_file_write(wdh, &rec_hdr, sizeof(rec_hdr), err))
773 wdh->bytes_dumped += sizeof(rec_hdr);
775 /* Write out 4 extra bytes of unknown stuff for HP-UX11
778 memset(dummyc, 0, sizeof dummyc);
779 if (!wtap_dump_file_write(wdh, dummyc, 4, err))
781 wdh->bytes_dumped += 4;
783 if ((phdr->pkt_encap == WTAP_ENCAP_FDDI_BITSWAPPED) ||
784 (phdr->pkt_encap == WTAP_ENCAP_NETTL_FDDI)) {
785 /* add those weird 3 bytes of padding */
786 if (!wtap_dump_file_write(wdh, dummyc, 3, err))
788 wdh->bytes_dumped += 3;
791 } else if (phdr->pkt_encap == WTAP_ENCAP_NETTL_X25) {
792 if (!wtap_dump_file_write(wdh, dummyc, 24, err))
794 wdh->bytes_dumped += 24;
798 /* write actual PDU data */
800 if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err))
802 wdh->bytes_dumped += phdr->caplen;