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:

November 2024

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

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close