diff options
author | Guy Harris <guy@alum.mit.edu> | 1999-10-18 01:51:34 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 1999-10-18 01:51:34 +0000 |
commit | dbd1955d62538097dcad85350f60f40849402190 (patch) | |
tree | 8a47a962a70fa20b6a2bc6460536ebe8f06f4003 /wiretap/nettl.c | |
parent | a0120ff1826a31acfa7f7bd22fb774d2626cac4f (diff) |
Olivier Abad's patches to add:
more display filters for X.25;
no LCN in X.25 RESTART / DIAGNOSTIC / REGISTRATION packets;
support for nettl file format (nettl is a trace tool for HP-UX).
For now, it only supports traces for X.25 interfaces (tested
with HP-UX 10.20).
svn path=/trunk/; revision=879
Diffstat (limited to 'wiretap/nettl.c')
-rw-r--r-- | wiretap/nettl.c | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/wiretap/nettl.c b/wiretap/nettl.c new file mode 100644 index 0000000000..e2cf17f88b --- /dev/null +++ b/wiretap/nettl.c @@ -0,0 +1,147 @@ +/* nettl.c + * + * Wiretap Library + * Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu> + * + * 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 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdlib.h> +#include <errno.h> +#include <time.h> +#include "wtap.h" +#include "file.h" +#include "buffer.h" +#include "nettl.h" + +static char nettl_magic[5] = { + 0x54, 0x52, 0x00, 0x64, 0x00 +}; + +/* HP nettl record header - The FCS is not included in the file. */ +struct nettlrec_hdr { + char xxa[12]; + char from_dce; + char xxb[55]; + guint16 length; + guint16 length2; /* don't know which one is captured length / real length */ + char xxc[4]; + char sec[4]; + char usec[4]; + char xxd[4]; +}; + +/* header is followed by data and once again the total length (2 bytes) ! */ + +static int nettl_read(wtap *wth, int *err); + +int nettl_open(wtap *wth, int *err) +{ + char magic[5]; + int bytes_read; + + /* Read in the string that should be at the start of a HP file */ + file_seek(wth->fh, 0, SEEK_SET); + errno = WTAP_ERR_CANT_READ; + bytes_read = file_read(magic, 1, 5, wth->fh); + if (bytes_read != 5) { + if (file_error(wth->fh)) { + *err = errno; + return -1; + } + return 0; + } + + if (memcmp(magic, nettl_magic, 5)) { + return 0; + } + + file_seek(wth->fh, 0x80, SEEK_SET); + wth->data_offset = 0x80; + + /* This is an nettl file */ + wth->file_type = WTAP_FILE_NETTL; + wth->capture.nettl = g_malloc(sizeof(nettl_t)); + wth->subtype_read = nettl_read; + wth->snapshot_length = 16384; /* not available in header, only in frame */ + + wth->capture.nettl->start = 0; + + wth->file_encap = WTAP_ENCAP_LAPB; + + return 1; +} + +/* Read the next packet */ +static int nettl_read(wtap *wth, int *err) +{ + int bytes_read; + struct nettlrec_hdr hdr; + guint16 length; + int data_offset; + + /* Read record header. */ + errno = WTAP_ERR_CANT_READ; + bytes_read = file_read(&hdr, 1, sizeof hdr, wth->fh); + if (bytes_read != sizeof hdr) { + if (file_error(wth->fh)) { + *err = errno; + return -1; + } + if (bytes_read != 0) { + *err = WTAP_ERR_SHORT_READ; + return -1; + } + return 0; + } + wth->data_offset += sizeof hdr; + length = pntohs(&hdr.length); + if (length <= 0) return 0; + + wth->phdr.len = length; + wth->phdr.caplen = length; + + wth->phdr.ts.tv_sec = pntohl(&hdr.sec); + wth->phdr.ts.tv_usec = pntohl(&hdr.usec); + if (wth->capture.nettl->start == 0) + wth->capture.nettl->start = wth->phdr.ts.tv_sec; + wth->phdr.pseudo_header.x25.flags = (hdr.from_dce & 0x20 ? 0x80 : 0x00); + + /* + * Read the packet data. + */ + buffer_assure_space(wth->frame_buffer, length); + data_offset = wth->data_offset; + errno = WTAP_ERR_CANT_READ; + bytes_read = file_read(buffer_start_ptr(wth->frame_buffer), 1, + length, wth->fh); + + if (bytes_read != length) { + if (file_error(wth->fh)) + *err = errno; + else + *err = WTAP_ERR_SHORT_READ; + return -1; + } + wth->data_offset += length; + + wth->phdr.pkt_encap = wth->file_encap; + + return data_offset; +} |