what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

pcat.c

pcat.c
Posted Oct 25, 2001
Authored by Chris Gragsone

Pcat is a utility which concatenates several libpcap (tcpdump) files into one.

tags | tool, sniffer
SHA-256 | f933c3a300b9e61426387c45f2ebabcc1ef48caf708a04bb6ff007d1343dfc30

pcat.c

Change Mirror Download
/* inspired by delta-sys
* written by maetrics
* moral support by deathcubek and wigginx
* GomiSquad (c) 2001
*
* gcc -O -Wall -o pcat pcat.c -lpcap
*
* basically this concatonates pcap files
* pcat pcap_file1 pcap_file2 pcap_file3 ... pcap_fileN > pcap_newfile
*
* warning: if not redirected, output will be displayed on the terminal
* in raw binary. This can corrupt the display in the same way the
* "cat /dev/urandom" will.
*/

#include <stdio.h>
#include <pcap.h>
#include <stdlib.h>
#include <net/bpf.h>

int pcap_io(char *, char *);

/* main()
* visibility: public
* arguments: <int> number of arguments, <char **> pointer array of arguments
* calls:
* pcap.h: pcap_dump_close(), pcap_dump_open(), pcap_file(),
* pcap_open_dead()
* stdio.h: fflush(), fprintf()
* stdlib.h: exit()
* returns: <int> exit status: (0) success, (-1) argument failure,
* (-2) file error, (-3) other
*
* outline:
* open a dummy device to create an important pointer
* open standard out as the save file
* loop through arguments
* -pass each argument to a helper function
* close all files and exit
*/
int main(int argc, char **argv) {
int i=0;
int linktype=DLT_EN10MB;
int snaplen=1514;
char *fname="-";
char *user=NULL;
pcap_t *p=NULL;
pcap_dumper_t *pd=NULL;

if(argc < 2) {
fprintf(stderr, "args\n");
exit(-1);
}

p=pcap_open_dead(linktype, snaplen);

if(p == NULL) {
fprintf(stderr, "open dead\n");
exit(-2);
}

pd=pcap_dump_open(p, fname);
user=(char *)pd;

if(pd == NULL) {
fprintf(stderr, "dump open\n");
exit(-2);
}

fflush(pcap_file(p));

for(i=1; i < argc; i++) {
if(!pcap_io(argv[i], user)) {
exit(-3);
}

fflush(pcap_file(p));
}

pcap_dump_close(pd);
pcap_close(p);
exit(0);
}

/* pcap_io()
* visibility: private
* arguments: <char> input file name, <char> output FILE pointer (pcap kludge)
* calls:
* pcap.h: pcap_close(), pcap_dump(), pcap_loop(), pcap_open_offline()
* stdio.h: fprintf()
* returns: <int> boolean exit status: (0) failure, (1) success
*
* outline:
* open input file
* read each packet from input file
* write each packet to output file
* close input file
*/
int pcap_io(char *fname, char *user) {
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t *p=NULL;
int cnt=-1;
pcap_handler callback=pcap_dump;

p=pcap_open_offline(fname, errbuf);

if(p == NULL) {
fprintf(stderr, "open_offline: %s\n", fname);
fprintf(stderr, "errbuf: %s\n", errbuf);
return 0;
}

pcap_loop(p, cnt, callback, user);
pcap_close(p);
return 1;
}

Login or Register to add favorites

File Archive:

April 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Apr 1st
    10 Files
  • 2
    Apr 2nd
    26 Files
  • 3
    Apr 3rd
    40 Files
  • 4
    Apr 4th
    6 Files
  • 5
    Apr 5th
    26 Files
  • 6
    Apr 6th
    0 Files
  • 7
    Apr 7th
    0 Files
  • 8
    Apr 8th
    22 Files
  • 9
    Apr 9th
    14 Files
  • 10
    Apr 10th
    10 Files
  • 11
    Apr 11th
    13 Files
  • 12
    Apr 12th
    14 Files
  • 13
    Apr 13th
    0 Files
  • 14
    Apr 14th
    0 Files
  • 15
    Apr 15th
    30 Files
  • 16
    Apr 16th
    10 Files
  • 17
    Apr 17th
    22 Files
  • 18
    Apr 18th
    45 Files
  • 19
    Apr 19th
    8 Files
  • 20
    Apr 20th
    0 Files
  • 21
    Apr 21st
    0 Files
  • 22
    Apr 22nd
    11 Files
  • 23
    Apr 23rd
    68 Files
  • 24
    Apr 24th
    23 Files
  • 25
    Apr 25th
    0 Files
  • 26
    Apr 26th
    0 Files
  • 27
    Apr 27th
    0 Files
  • 28
    Apr 28th
    0 Files
  • 29
    Apr 29th
    0 Files
  • 30
    Apr 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close