2007-11-24 03:33:18 +00:00
|
|
|
/* commview.c
|
|
|
|
* Routines for opening CommView file format packet captures
|
2009-05-31 05:55:15 +00:00
|
|
|
* Copyright 2007, Stephen Fisher (see AUTHORS file)
|
2007-11-24 03:33:18 +00:00
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2007-11-26 05:34:07 +00:00
|
|
|
* Based on csids.c and nettl.c
|
2007-11-24 03:33:18 +00:00
|
|
|
*
|
|
|
|
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
|
|
* USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* A brief description of this file format is available at:
|
|
|
|
* http://www.tamos.com/htmlhelp/commview/logformat.htm
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "wtap.h"
|
|
|
|
#include "wtap-int.h"
|
2014-07-15 23:40:46 +00:00
|
|
|
#include <wsutil/buffer.h>
|
2007-11-24 03:33:18 +00:00
|
|
|
#include "file_wrappers.h"
|
|
|
|
#include "commview.h"
|
|
|
|
|
|
|
|
typedef struct commview_header {
|
|
|
|
guint16 data_len;
|
|
|
|
guint16 source_data_len;
|
|
|
|
guint8 version;
|
|
|
|
guint16 year;
|
|
|
|
guint8 month;
|
2014-10-07 05:01:12 +00:00
|
|
|
guint8 day;
|
2007-11-24 03:33:18 +00:00
|
|
|
guint8 hours;
|
|
|
|
guint8 minutes;
|
|
|
|
guint8 seconds;
|
|
|
|
guint32 usecs;
|
|
|
|
guint8 flags; /* Bit-field positions defined below */
|
2010-12-20 23:34:14 +00:00
|
|
|
guint8 signal_level_percent;
|
2012-10-12 20:51:04 +00:00
|
|
|
guint8 rate;
|
2007-11-24 03:33:18 +00:00
|
|
|
guint8 band;
|
|
|
|
guint8 channel;
|
2010-12-20 23:34:14 +00:00
|
|
|
guint8 direction; /* Or for WiFi, high order byte of
|
|
|
|
* packet rate. */
|
2014-10-29 23:03:08 +00:00
|
|
|
gint8 signal_level_dbm;
|
|
|
|
gint8 noise_level; /* In dBm (WiFi only) */
|
2007-11-24 03:33:18 +00:00
|
|
|
} commview_header_t;
|
|
|
|
|
|
|
|
#define COMMVIEW_HEADER_SIZE 24
|
|
|
|
|
|
|
|
/* Bit-field positions for various fields in the flags variable of the header */
|
|
|
|
#define FLAGS_MEDIUM 0x0F
|
|
|
|
#define FLAGS_DECRYPTED 0x10
|
|
|
|
#define FLAGS_BROKEN 0x20
|
|
|
|
#define FLAGS_COMPRESSED 0x40
|
|
|
|
#define FLAGS_RESERVED 0x80
|
|
|
|
|
|
|
|
/* Capture mediums as defined by the commview file format */
|
|
|
|
#define MEDIUM_ETHERNET 0
|
|
|
|
#define MEDIUM_WIFI 1
|
|
|
|
#define MEDIUM_TOKEN_RING 2
|
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean commview_read(wtap *wth, int *err, gchar **err_info,
|
|
|
|
gint64 *data_offset);
|
|
|
|
static gboolean commview_seek_read(wtap *wth, gint64 seek_off,
|
|
|
|
struct wtap_pkthdr *phdr,
|
|
|
|
Buffer *buf, int *err, gchar **err_info);
|
2011-09-01 04:14:54 +00:00
|
|
|
static gboolean commview_read_header(commview_header_t *cv_hdr, FILE_T fh,
|
2014-05-09 05:18:49 +00:00
|
|
|
int *err, gchar **err_info);
|
|
|
|
static gboolean commview_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
|
|
|
|
const guint8 *pd, int *err);
|
2007-11-24 03:33:18 +00:00
|
|
|
|
2014-10-09 23:44:15 +00:00
|
|
|
wtap_open_return_val commview_open(wtap *wth, int *err, gchar **err_info)
|
2007-11-24 03:33:18 +00:00
|
|
|
{
|
|
|
|
commview_header_t cv_hdr;
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if(!commview_read_header(&cv_hdr, wth->fh, err, err_info)) {
|
Do not call wtap_file_read_unknown_bytes() or
wtap_file_read_expected_bytes() from an open routine - open routines are
supposed to return -1 on error, 0 if the file doesn't appear to be a
file of the specified type, or 1 if the file does appear to be a file of
the specified type, but those macros will cause the caller to return
FALSE on errors (so that, even if there's an I/O error, it reports "the
file isn't a file of the specified type" rather than "we got an error
trying to read the file").
When doing reads in an open routine before we've concluded that the file
is probably of the right type, return 0, rather than -1, if we get
WTAP_ERR_SHORT_READ - if we don't have enough data to check whether a
file is of a given type, we should keep trying other types, not give up.
For reads done *after* we've concluded the file is probably of the right
type, if a read doesn't return the number of bytes we asked for, but
returns an error of 0, return WTAP_ERR_SHORT_READ - the file is
apparently cut short.
For NetMon and NetXRay/Windows Sniffer files, use a #define for the
magic number size, and use that for both magic numbers.
svn path=/trunk/; revision=46803
2012-12-27 12:19:25 +00:00
|
|
|
if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
|
|
|
return WTAP_OPEN_NOT_MINE;
|
2012-12-26 12:01:14 +00:00
|
|
|
}
|
2007-11-24 03:33:18 +00:00
|
|
|
|
|
|
|
/* If any of these fields do not match what we expect, bail out. */
|
|
|
|
if(cv_hdr.version != 0 ||
|
|
|
|
cv_hdr.year < 1970 || cv_hdr.year >= 2038 ||
|
|
|
|
cv_hdr.month < 1 || cv_hdr.month > 12 ||
|
|
|
|
cv_hdr.day < 1 || cv_hdr.day > 31 ||
|
|
|
|
cv_hdr.hours > 23 ||
|
|
|
|
cv_hdr.minutes > 59 ||
|
|
|
|
cv_hdr.seconds > 60 ||
|
2010-12-20 23:34:14 +00:00
|
|
|
cv_hdr.signal_level_percent > 100 ||
|
2007-11-24 03:33:18 +00:00
|
|
|
(cv_hdr.flags & FLAGS_RESERVED) != 0 ||
|
|
|
|
((cv_hdr.flags & FLAGS_MEDIUM) != MEDIUM_ETHERNET &&
|
|
|
|
(cv_hdr.flags & FLAGS_MEDIUM) != MEDIUM_WIFI &&
|
2010-12-20 23:34:14 +00:00
|
|
|
(cv_hdr.flags & FLAGS_MEDIUM) != MEDIUM_TOKEN_RING))
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_NOT_MINE; /* Not our kind of file */
|
2007-11-24 03:33:18 +00:00
|
|
|
|
|
|
|
/* No file header. Reset the fh to 0 so we can read the first packet */
|
2014-05-09 05:18:49 +00:00
|
|
|
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_ERROR;
|
2007-11-24 03:33:18 +00:00
|
|
|
|
|
|
|
/* Set up the pointers to the handlers for this file type */
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->subtype_read = commview_read;
|
|
|
|
wth->subtype_seek_read = commview_seek_read;
|
2007-11-26 05:34:07 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_COMMVIEW;
|
|
|
|
wth->file_encap = WTAP_ENCAP_PER_PACKET;
|
2014-09-28 18:37:06 +00:00
|
|
|
wth->file_tsprec = WTAP_TSPREC_USEC;
|
2008-10-01 13:57:41 +00:00
|
|
|
|
2014-10-09 23:44:15 +00:00
|
|
|
return WTAP_OPEN_MINE; /* Our kind of file */
|
2007-11-24 03:33:18 +00:00
|
|
|
}
|
|
|
|
|
2013-05-16 23:14:17 +00:00
|
|
|
static int
|
2013-06-17 21:18:47 +00:00
|
|
|
commview_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
|
2013-05-16 23:14:17 +00:00
|
|
|
int *err, gchar **err_info)
|
2011-09-01 04:14:54 +00:00
|
|
|
{
|
2013-05-16 23:14:17 +00:00
|
|
|
commview_header_t cv_hdr;
|
2012-10-17 20:28:22 +00:00
|
|
|
struct tm tm;
|
|
|
|
|
2013-05-16 23:14:17 +00:00
|
|
|
if(!commview_read_header(&cv_hdr, fh, err, err_info))
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2012-10-17 20:28:22 +00:00
|
|
|
|
2013-05-16 23:14:17 +00:00
|
|
|
switch(cv_hdr.flags & FLAGS_MEDIUM) {
|
2011-09-01 04:14:54 +00:00
|
|
|
|
|
|
|
case MEDIUM_ETHERNET :
|
2012-10-17 20:28:22 +00:00
|
|
|
phdr->pkt_encap = WTAP_ENCAP_ETHERNET;
|
2013-05-16 23:14:17 +00:00
|
|
|
phdr->pseudo_header.eth.fcs_len = -1; /* Unknown */
|
|
|
|
break;
|
2011-09-01 04:14:54 +00:00
|
|
|
|
|
|
|
case MEDIUM_WIFI :
|
2012-10-17 20:28:22 +00:00
|
|
|
phdr->pkt_encap = WTAP_ENCAP_IEEE_802_11_WITH_RADIO;
|
2014-10-29 23:03:08 +00:00
|
|
|
phdr->pseudo_header.ieee_802_11.presence_flags =
|
|
|
|
PHDR_802_11_HAS_CHANNEL |
|
|
|
|
PHDR_802_11_HAS_DATA_RATE |
|
|
|
|
PHDR_802_11_HAS_SIGNAL_PERCENT;
|
2013-05-16 23:14:17 +00:00
|
|
|
phdr->pseudo_header.ieee_802_11.fcs_len = -1; /* Unknown */
|
|
|
|
phdr->pseudo_header.ieee_802_11.channel = cv_hdr.channel;
|
2013-06-03 06:36:55 +00:00
|
|
|
phdr->pseudo_header.ieee_802_11.data_rate =
|
|
|
|
cv_hdr.rate | (cv_hdr.direction << 8);
|
2014-10-29 23:03:08 +00:00
|
|
|
phdr->pseudo_header.ieee_802_11.signal_percent = cv_hdr.signal_level_percent;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX - these are positive in captures I've seen; does
|
|
|
|
* that mean that they are the negative of the actual
|
|
|
|
* dBm value? (80 dBm is a bit more power than most
|
|
|
|
* countries' regulatory agencies are likely to allow
|
|
|
|
* any individual to have in their home. :-))
|
|
|
|
*
|
|
|
|
* XXX - sometimes these are 0; assume that means that no
|
|
|
|
* value is provided.
|
|
|
|
*/
|
|
|
|
if (cv_hdr.signal_level_dbm != 0) {
|
|
|
|
phdr->pseudo_header.ieee_802_11.signal_dbm = -cv_hdr.signal_level_dbm;
|
|
|
|
phdr->pseudo_header.ieee_802_11.presence_flags |=
|
|
|
|
PHDR_802_11_HAS_SIGNAL_DBM;
|
|
|
|
}
|
|
|
|
if (cv_hdr.noise_level != 0) {
|
|
|
|
phdr->pseudo_header.ieee_802_11.noise_dbm = -cv_hdr.noise_level;
|
|
|
|
phdr->pseudo_header.ieee_802_11.presence_flags |=
|
|
|
|
PHDR_802_11_HAS_NOISE_DBM;
|
|
|
|
}
|
2013-05-16 23:14:17 +00:00
|
|
|
break;
|
2011-09-01 04:14:54 +00:00
|
|
|
|
2012-10-17 20:28:22 +00:00
|
|
|
case MEDIUM_TOKEN_RING :
|
|
|
|
phdr->pkt_encap = WTAP_ENCAP_TOKEN_RING;
|
2013-05-16 23:14:17 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default :
|
|
|
|
*err = WTAP_ERR_BAD_FILE;
|
|
|
|
*err_info = g_strdup_printf("commview: unsupported encap: %u",
|
|
|
|
cv_hdr.flags & FLAGS_MEDIUM);
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2011-09-01 04:14:54 +00:00
|
|
|
}
|
2012-10-17 20:28:22 +00:00
|
|
|
|
2013-05-16 23:14:17 +00:00
|
|
|
tm.tm_year = cv_hdr.year - 1900;
|
|
|
|
tm.tm_mon = cv_hdr.month - 1;
|
|
|
|
tm.tm_mday = cv_hdr.day;
|
|
|
|
tm.tm_hour = cv_hdr.hours;
|
|
|
|
tm.tm_min = cv_hdr.minutes;
|
|
|
|
tm.tm_sec = cv_hdr.seconds;
|
|
|
|
tm.tm_isdst = -1;
|
|
|
|
|
2014-05-24 18:28:30 +00:00
|
|
|
phdr->rec_type = REC_TYPE_PACKET;
|
2013-05-16 23:14:17 +00:00
|
|
|
phdr->presence_flags = WTAP_HAS_TS;
|
|
|
|
|
|
|
|
phdr->len = cv_hdr.data_len;
|
|
|
|
phdr->caplen = cv_hdr.data_len;
|
|
|
|
|
|
|
|
phdr->ts.secs = mktime(&tm);
|
|
|
|
phdr->ts.nsecs = cv_hdr.usecs * 1000;
|
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
return wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info);
|
2011-09-01 04:14:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean
|
2014-05-09 05:18:49 +00:00
|
|
|
commview_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
|
2013-05-16 23:23:08 +00:00
|
|
|
{
|
2014-05-09 05:18:49 +00:00
|
|
|
*data_offset = file_tell(wth->fh);
|
2008-10-01 13:57:41 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
return commview_read_packet(wth->fh, &wth->phdr, wth->frame_buffer, err,
|
2013-06-17 21:18:47 +00:00
|
|
|
err_info);
|
2007-11-24 03:33:18 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
static gboolean
|
2014-05-09 05:18:49 +00:00
|
|
|
commview_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
|
2014-01-02 20:47:21 +00:00
|
|
|
Buffer *buf, int *err, gchar **err_info)
|
2007-11-24 03:33:18 +00:00
|
|
|
{
|
2014-05-09 05:18:49 +00:00
|
|
|
if(file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
|
2014-05-23 10:50:02 +00:00
|
|
|
return FALSE;
|
2008-10-01 13:57:41 +00:00
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
return commview_read_packet(wth->random_fh, phdr, buf, err, err_info);
|
2007-11-24 03:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-04-21 09:41:52 +00:00
|
|
|
commview_read_header(commview_header_t *cv_hdr, FILE_T fh, int *err,
|
|
|
|
gchar **err_info)
|
2007-11-24 03:33:18 +00:00
|
|
|
{
|
Add some higher-level file-read APIs and use them.
Add wtap_read_bytes(), which takes a FILE_T, a pointer, a byte count, an
error number pointer, and an error string pointer as arguments, and that
treats a short read of any sort, including a read that returns 0 bytes,
as a WTAP_ERR_SHORT_READ error, and that returns the error number and
string through its last two arguments.
Add wtap_read_bytes_or_eof(), which is similar, but that treats a read
that returns 0 bytes as an EOF, supplying an error number of 0 as an EOF
indication.
Use those in file readers; that simplifies the code and makes it less
likely that somebody will fail to supply the error number and error
string on a file read error.
Change-Id: Ia5dba2a6f81151e87b614461349d611cffc16210
Reviewed-on: https://code.wireshark.org/review/4512
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-10-07 01:00:57 +00:00
|
|
|
if (!wtap_read_bytes_or_eof(fh, &cv_hdr->data_len, 2, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->source_data_len, 2, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->version, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->year, 2, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->month, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->day, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->hours, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->minutes, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->seconds, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->usecs, 4, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->flags, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->signal_level_percent, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->rate, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->band, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->channel, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->direction, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->signal_level_dbm, 1, err, err_info))
|
|
|
|
return FALSE;
|
|
|
|
if (!wtap_read_bytes(fh, &cv_hdr->noise_level, 1, err, err_info))
|
|
|
|
return FALSE;
|
2007-11-24 03:33:18 +00:00
|
|
|
|
|
|
|
/* Convert multi-byte values from little endian to host endian format */
|
|
|
|
cv_hdr->data_len = GUINT16_FROM_LE(cv_hdr->data_len);
|
|
|
|
cv_hdr->source_data_len = GUINT16_FROM_LE(cv_hdr->source_data_len);
|
|
|
|
cv_hdr->year = GUINT16_FROM_LE(cv_hdr->year);
|
|
|
|
cv_hdr->usecs = GUINT32_FROM_LE(cv_hdr->usecs);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-10-01 13:57:41 +00:00
|
|
|
/* Returns 0 if we can write out the specified encapsulation type
|
2007-11-26 05:34:07 +00:00
|
|
|
* into a CommView format file. */
|
|
|
|
int commview_dump_can_write_encap(int encap)
|
|
|
|
{
|
|
|
|
switch (encap) {
|
|
|
|
|
|
|
|
case WTAP_ENCAP_ETHERNET :
|
|
|
|
case WTAP_ENCAP_IEEE_802_11 :
|
2007-11-27 05:43:29 +00:00
|
|
|
case WTAP_ENCAP_IEEE_802_11_WITH_RADIO :
|
2007-11-26 05:34:07 +00:00
|
|
|
case WTAP_ENCAP_TOKEN_RING :
|
|
|
|
case WTAP_ENCAP_PER_PACKET :
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
2014-12-17 06:40:45 +00:00
|
|
|
return WTAP_ERR_UNWRITABLE_ENCAP;
|
2007-11-26 05:34:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns TRUE on success, FALSE on failure;
|
|
|
|
sets "*err" to an error code on failure */
|
2014-05-09 05:18:49 +00:00
|
|
|
gboolean commview_dump_open(wtap_dumper *wdh, int *err _U_)
|
2007-11-26 05:34:07 +00:00
|
|
|
{
|
|
|
|
wdh->subtype_write = commview_dump;
|
|
|
|
wdh->subtype_close = NULL;
|
2008-10-01 13:57:41 +00:00
|
|
|
|
2007-11-26 05:34:07 +00:00
|
|
|
/* There is no file header to write out */
|
|
|
|
wdh->bytes_dumped = 0;
|
2008-10-01 13:57:41 +00:00
|
|
|
|
2007-11-26 05:34:07 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write a record for a packet to a dump file.
|
|
|
|
* Returns TRUE on success, FALSE on failure. */
|
2014-05-09 05:18:49 +00:00
|
|
|
static gboolean commview_dump(wtap_dumper *wdh,
|
2007-11-26 05:34:07 +00:00
|
|
|
const struct wtap_pkthdr *phdr,
|
2011-09-01 09:43:10 +00:00
|
|
|
const guint8 *pd, int *err)
|
2007-11-26 05:34:07 +00:00
|
|
|
{
|
|
|
|
commview_header_t cv_hdr;
|
2011-09-01 04:14:54 +00:00
|
|
|
struct tm *tm;
|
2007-11-26 05:34:07 +00:00
|
|
|
|
2014-05-24 18:28:30 +00:00
|
|
|
/* We can only write packet records. */
|
|
|
|
if (phdr->rec_type != REC_TYPE_PACKET) {
|
|
|
|
*err = WTAP_ERR_REC_TYPE_UNSUPPORTED;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-01-22 00:26:36 +00:00
|
|
|
/* Don't write out anything bigger than we can read.
|
|
|
|
* (The length field in packet headers is 16 bits, which
|
|
|
|
* imposes a hard limit.) */
|
|
|
|
if (phdr->caplen > 65535) {
|
|
|
|
*err = WTAP_ERR_PACKET_TOO_LARGE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-11-26 05:34:07 +00:00
|
|
|
memset(&cv_hdr, 0, sizeof(cv_hdr));
|
|
|
|
|
|
|
|
cv_hdr.data_len = GUINT16_TO_LE((guint16)phdr->caplen);
|
|
|
|
cv_hdr.source_data_len = GUINT16_TO_LE((guint16)phdr->caplen);
|
|
|
|
cv_hdr.version = 0;
|
|
|
|
|
2011-09-01 04:14:54 +00:00
|
|
|
tm = localtime(&phdr->ts.secs);
|
|
|
|
cv_hdr.year = tm->tm_year + 1900;
|
|
|
|
cv_hdr.month = tm->tm_mon + 1;
|
|
|
|
cv_hdr.day = tm->tm_mday;
|
|
|
|
cv_hdr.hours = tm->tm_hour;
|
|
|
|
cv_hdr.minutes = tm->tm_min;
|
|
|
|
cv_hdr.seconds = tm->tm_sec;
|
2007-11-26 05:34:07 +00:00
|
|
|
cv_hdr.usecs = GUINT32_TO_LE(phdr->ts.nsecs / 1000);
|
|
|
|
|
|
|
|
switch(phdr->pkt_encap) {
|
|
|
|
|
|
|
|
case WTAP_ENCAP_ETHERNET :
|
|
|
|
cv_hdr.flags |= MEDIUM_ETHERNET;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_ENCAP_IEEE_802_11 :
|
|
|
|
cv_hdr.flags |= MEDIUM_WIFI;
|
|
|
|
break;
|
|
|
|
|
2007-11-27 05:43:29 +00:00
|
|
|
case WTAP_ENCAP_IEEE_802_11_WITH_RADIO :
|
|
|
|
cv_hdr.flags |= MEDIUM_WIFI;
|
|
|
|
|
2014-10-29 23:03:08 +00:00
|
|
|
cv_hdr.channel =
|
|
|
|
(phdr->pseudo_header.ieee_802_11.presence_flags & PHDR_802_11_HAS_CHANNEL) ?
|
|
|
|
phdr->pseudo_header.ieee_802_11.channel :
|
|
|
|
0;
|
|
|
|
cv_hdr.rate =
|
|
|
|
(phdr->pseudo_header.ieee_802_11.presence_flags & PHDR_802_11_HAS_DATA_RATE) ?
|
|
|
|
(guint8)(phdr->pseudo_header.ieee_802_11.data_rate & 0xFF) :
|
|
|
|
0;
|
|
|
|
cv_hdr.direction =
|
|
|
|
(phdr->pseudo_header.ieee_802_11.presence_flags & PHDR_802_11_HAS_DATA_RATE) ?
|
|
|
|
(guint8)((phdr->pseudo_header.ieee_802_11.data_rate >> 8) & 0xFF) :
|
|
|
|
0;
|
|
|
|
cv_hdr.signal_level_percent =
|
|
|
|
(phdr->pseudo_header.ieee_802_11.presence_flags & PHDR_802_11_HAS_SIGNAL_PERCENT) ?
|
|
|
|
phdr->pseudo_header.ieee_802_11.signal_percent :
|
|
|
|
0;
|
|
|
|
cv_hdr.signal_level_dbm =
|
|
|
|
(phdr->pseudo_header.ieee_802_11.presence_flags & PHDR_802_11_HAS_SIGNAL_DBM) ?
|
|
|
|
-phdr->pseudo_header.ieee_802_11.signal_dbm :
|
|
|
|
0;
|
|
|
|
cv_hdr.noise_level =
|
|
|
|
(phdr->pseudo_header.ieee_802_11.presence_flags & PHDR_802_11_HAS_NOISE_DBM) ?
|
|
|
|
-phdr->pseudo_header.ieee_802_11.noise_dbm :
|
|
|
|
0;
|
2007-11-27 05:43:29 +00:00
|
|
|
break;
|
|
|
|
|
2007-11-26 05:34:07 +00:00
|
|
|
case WTAP_ENCAP_TOKEN_RING :
|
|
|
|
cv_hdr.flags |= MEDIUM_TOKEN_RING;
|
2011-03-27 13:15:14 +00:00
|
|
|
break;
|
2007-11-26 05:34:07 +00:00
|
|
|
|
|
|
|
default :
|
2014-12-17 06:40:45 +00:00
|
|
|
*err = WTAP_ERR_UNWRITABLE_ENCAP;
|
2007-11-26 05:34:07 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.data_len, 2, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.source_data_len, 2, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.version, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.year, 2, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.month, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.day, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.hours, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.minutes, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.seconds, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.usecs, 4, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.flags, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.signal_level_percent, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.rate, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.band, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.channel, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.direction, 1, err))
|
2010-06-06 22:19:30 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.signal_level_dbm, 2, err))
|
2010-12-20 23:34:14 +00:00
|
|
|
return FALSE;
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, &cv_hdr.noise_level, 2, err))
|
2007-11-26 05:34:07 +00:00
|
|
|
return FALSE;
|
|
|
|
wdh->bytes_dumped += COMMVIEW_HEADER_SIZE;
|
|
|
|
|
2014-05-09 05:18:49 +00:00
|
|
|
if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err))
|
2007-11-26 05:34:07 +00:00
|
|
|
return FALSE;
|
|
|
|
wdh->bytes_dumped += phdr->caplen;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|