const union wtap_pseudo_header *pseudo_header, const guchar *pd, int *err);
static gboolean ngsniffer_dump_close(wtap_dumper *wdh, int *err);
static int SnifferDecompress( unsigned char * inbuf, size_t inlen,
- unsigned char * outbuf, size_t outlen, int *err );
+ unsigned char * outbuf, size_t outlen, int *err );
static gint64 ng_file_read(void *buffer, size_t elementsize, size_t numelements,
wtap *wth, gboolean is_random, int *err);
static int read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream,
static gint64 ng_file_seek_seq(wtap *wth, gint64 offset, int whence, int *err);
static gint64 ng_file_seek_rand(wtap *wth, gint64 offset, int whence, int *err);
-int ngsniffer_open(wtap *wth, int *err, gchar **err_info)
+int
+ngsniffer_open(wtap *wth, int *err, gchar **err_info)
{
int bytes_read;
char magic[sizeof ngsniffer_magic];
}
/* Read the next packet */
-static gboolean ngsniffer_read(wtap *wth, int *err, gchar **err_info,
- gint64 *data_offset)
+static gboolean
+ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
{
ngsniffer_t *ngsniffer;
int ret;
return TRUE;
}
-static gboolean ngsniffer_seek_read(wtap *wth, gint64 seek_off,
+static gboolean
+ngsniffer_seek_read(wtap *wth, gint64 seek_off,
union wtap_pseudo_header *pseudo_header, guchar *pd, int packet_size,
int *err, gchar **err_info _U_)
{
return TRUE;
}
-static int ngsniffer_read_rec_header(wtap *wth, gboolean is_random,
- guint16 *typep, guint16 *lengthp, int *err)
+static int
+ngsniffer_read_rec_header(wtap *wth, gboolean is_random, guint16 *typep,
+ guint16 *lengthp, int *err)
{
gint64 bytes_read;
char record_type[2];
return 1; /* success */
}
-static gboolean ngsniffer_read_frame2(wtap *wth, gboolean is_random,
- struct frame2_rec *frame2, int *err)
+static gboolean
+ngsniffer_read_frame2(wtap *wth, gboolean is_random, struct frame2_rec *frame2,
+ int *err)
{
gint64 bytes_read;
return TRUE;
}
-static void set_pseudo_header_frame2(wtap *wth,
- union wtap_pseudo_header *pseudo_header, struct frame2_rec *frame2)
+static void
+set_pseudo_header_frame2(wtap *wth, union wtap_pseudo_header *pseudo_header,
+ struct frame2_rec *frame2)
{
/*
* In one PPP "Internetwork analyzer" capture:
}
}
-static gboolean ngsniffer_read_frame4(wtap *wth, gboolean is_random,
- struct frame4_rec *frame4, int *err)
+static gboolean
+ngsniffer_read_frame4(wtap *wth, gboolean is_random, struct frame4_rec *frame4,
+ int *err)
{
gint64 bytes_read;
return TRUE;
}
-static void set_pseudo_header_frame4(union wtap_pseudo_header *pseudo_header,
+static void
+set_pseudo_header_frame4(union wtap_pseudo_header *pseudo_header,
struct frame4_rec *frame4)
{
guint32 StatusWord;
pseudo_header->atm.aal5t_chksum = pntohl(&frame4->atm_info.Trailer.aal5t_chksum);
}
-static gboolean ngsniffer_read_frame6(wtap *wth, gboolean is_random,
- struct frame6_rec *frame6, int *err)
+static gboolean
+ngsniffer_read_frame6(wtap *wth, gboolean is_random, struct frame6_rec *frame6,
+ int *err)
{
gint64 bytes_read;
return TRUE;
}
-static void set_pseudo_header_frame6(wtap *wth,
- union wtap_pseudo_header *pseudo_header,
- struct frame6_rec *frame6 _U_)
+static void
+set_pseudo_header_frame6(wtap *wth, union wtap_pseudo_header *pseudo_header,
+ struct frame6_rec *frame6 _U_)
{
/* XXX - Once the frame format is divined, something will most likely go here */
}
}
-static gboolean ngsniffer_read_rec_data(wtap *wth, gboolean is_random,
- guchar *pd, size_t length, int *err)
+static gboolean
+ngsniffer_read_rec_data(wtap *wth, gboolean is_random, guchar *pd,
+ size_t length, int *err)
{
gint64 bytes_read;
* have type 7 records? If so, is there some other field that will
* tell us what type of capture it is?)
*/
-static int infer_pkt_encap(const guint8 *pd, int len)
+static int
+infer_pkt_encap(const guint8 *pd, int len)
{
int i;
return WTAP_ENCAP_LAPB;
}
-static int fix_pseudo_header(int encap, const guint8 *pd, int len,
+static int
+fix_pseudo_header(int encap, const guint8 *pd, int len,
union wtap_pseudo_header *pseudo_header)
{
switch (encap) {
/* Throw away the buffers used by the sequential I/O stream, but not
those used by the random I/O stream. */
-static void ngsniffer_sequential_close(wtap *wth)
+static void
+ngsniffer_sequential_close(wtap *wth)
{
ngsniffer_t *ngsniffer;
}
}
-static void free_blob(gpointer data, gpointer user_data _U_)
+static void
+free_blob(gpointer data, gpointer user_data _U_)
{
g_free(data);
}
private data structures. (If there's a "sequential_close" routine
for a capture file type, it'll be called before the "close" routine
is called, so we don't have to free the sequential buffer here.) */
-static void ngsniffer_close(wtap *wth)
+static void
+ngsniffer_close(wtap *wth)
{
ngsniffer_t *ngsniffer;
/* Returns 0 if we could write the specified encapsulation type,
an error indication otherwise. */
-int ngsniffer_dump_can_write_encap(int encap)
+int
+ngsniffer_dump_can_write_encap(int encap)
{
/* Per-packet encapsulations aren't supported. */
if (encap == WTAP_ENCAP_PER_PACKET)
/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
failure */
-gboolean ngsniffer_dump_open(wtap_dumper *wdh, gboolean cant_seek _U_, int *err)
+gboolean
+ngsniffer_dump_open(wtap_dumper *wdh, gboolean cant_seek _U_, int *err)
{
ngsniffer_dump_t *ngsniffer;
char buf[6] = {REC_VERS, 0x00, 0x12, 0x00, 0x00, 0x00}; /* version record */
/* Write the file header. */
if (!wtap_dump_file_write(wdh, ngsniffer_magic, sizeof ngsniffer_magic,
- err))
+ err))
return FALSE;
if (!wtap_dump_file_write(wdh, buf, 6, err))
return FALSE;
/* Write a record for a packet to a dump file.
Returns TRUE on success, FALSE on failure. */
-static gboolean ngsniffer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
+static gboolean
+ngsniffer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
const union wtap_pseudo_header *pseudo_header, const guchar *pd, int *err)
{
ngsniffer_dump_t *ngsniffer = (ngsniffer_dump_t *)wdh->priv;
tsecs -= rec_hdr.time_day * 86400; /* time within day */
/* Convert to picoseconds */
t = tsecs*G_GINT64_CONSTANT(1000000000000U) +
- phdr->ts.nsecs*G_GINT64_CONSTANT(1000U);
+ phdr->ts.nsecs*G_GINT64_CONSTANT(1000U);
/* Convert to units of timeunit = 1 */
t /= Psec[1];
t_low = (guint16)((t >> 0) & 0xFFFF);
/* Finish writing to a dump file.
Returns TRUE on success, FALSE on failure. */
-static gboolean ngsniffer_dump_close(wtap_dumper *wdh, int *err)
+static gboolean
+ngsniffer_dump_close(wtap_dumper *wdh, int *err)
{
/* EOF record */
char buf[6] = {REC_EOF, 0x00, 0x00, 0x00, 0x00, 0x00};
/*
SnifferDecompress() decompresses a blob of compressed data from a
- Sniffer(R) capture file.
+ Sniffer(R) capture file.
This function is Copyright (c) 1999-2999 Tim Farley
Parameters
inbuf - buffer of compressed bytes from file, not including
- the preceding length word
+ the preceding length word
inlen - length of inbuf in bytes (max 64k)
outbuf - decompressed contents, could contain a partial Sniffer
- record at the end.
+ record at the end.
outlen - length of outbuf.
Return value is the number of bytes in outbuf on return.
*/
static int
-SnifferDecompress( unsigned char * inbuf, size_t inlen,
- unsigned char * outbuf, size_t outlen, int *err )
+SnifferDecompress(unsigned char *inbuf, size_t inlen, unsigned char *outbuf,
+ size_t outlen, int *err)
{
unsigned char * pin = inbuf;
unsigned char * pout = outbuf;
unsigned int bit_value = 0; /* cache the last 16 coding bits we retrieved */
unsigned int code_type; /* encoding type, from high 4 bits of byte */
unsigned int code_low; /* other 4 bits from encoding byte */
- int length; /* length of RLE sequence or repeated string */
- int offset; /* offset of string to repeat */
+ int length; /* length of RLE sequence or repeated string */
+ int offset; /* offset of string to repeat */
if (inlen > G_MAXUINT16) {
return ( -1 );
* uncompressed data from any blob?
*/
#define OUTBUF_SIZE 65536
+#define INBUF_SIZE 65536
/* Information about a compressed blob; we save the offset in the
underlying compressed file, and the offset in the uncompressed data
blob->blob_comp_offset = comp_stream->comp_offset;
blob->blob_uncomp_offset = comp_stream->uncomp_offset;
ngsniffer->last_blob = g_list_append(ngsniffer->last_blob,
- blob);
+ blob);
}
}
unsigned short blob_len;
gint16 blob_len_host;
gboolean uncompressed;
- unsigned char file_inbuf[65536];
+ unsigned char *file_inbuf;
int out_len;
/* Read one 16-bit word which is length of next compressed blob */
uncompressed = FALSE;
}
+ file_inbuf = g_malloc(INBUF_SIZE);
+
/* Read the blob */
errno = WTAP_ERR_CANT_READ;
read_len = file_read(file_inbuf, 1, in_len, infile);
if ((size_t) in_len != read_len) {
*err = file_error(infile);
+ g_free(file_inbuf);
return -1;
}
comp_stream->comp_offset += in_len;
/* Decompress the blob */
out_len = SnifferDecompress(file_inbuf, in_len,
comp_stream->buf, OUTBUF_SIZE, err);
- if (out_len < 0)
+ if (out_len < 0) {
+ g_free(file_inbuf);
return -1;
+ }
}
+
+ g_free(file_inbuf);
comp_stream->nextout = 0;
comp_stream->nbytes = out_len;
return 0;
ng_file_seek_seq(wtap *wth, gint64 offset, int whence, int *err)
{
gint64 delta;
- char buf[65536];
+ char *buf;
long amount_to_read;
ngsniffer_t *ngsniffer;
g_assert(delta >= 0);
/* Ok, now read and discard "delta" bytes. */
+ buf = g_malloc(INBUF_SIZE);
while (delta != 0) {
amount_to_read = (long) delta;
+
if ((unsigned long)amount_to_read > sizeof buf)
amount_to_read = sizeof buf;
- if (ng_file_read(buf, 1, amount_to_read, wth, FALSE, err) < 0)
+
+ if (ng_file_read(buf, 1, amount_to_read, wth, FALSE, err) < 0) {
+ g_free(buf);
return -1; /* error */
+ }
+
delta -= amount_to_read;
}
+
+ g_free(buf);
return offset;
}