libpcap problem (hdr.len vs tcpdump file size)?

From: D (c00l_79_at_yahoo.com)
Date: 10/27/03

  • Next message: Neil: "What to backup for LVM?"
    Date: 26 Oct 2003 16:16:55 -0800
    
    

    Hi,

    I'm trying to use libpcap to output tpcdump raw data that I've
    captured in a file.
    here's the info of the tcpdump file:
    -rw-r--r-- 1 david david 1042 Oct 26 01:36 tcpdump.out

    now, when I use my code to capture the packets in that file and
    directly printing them out, the output of this code is somehow larger
    than the actual dump file.
    Here's my (C++) code:

    -------------
    #include <iostream>
    #include <netinet/in.h>
    #include <linux/inet.h>
    #include <netinet/if_ether.h>
    #include <pcap.h>
    #include <fstream>

    int main(){

            using namespace std;
            ofstream fout;
            fout.open("pcaptest.out");
            char errbuf[PCAP_ERRBUF_SIZE];
           pcap_t *descr= pcap_open_offline("/home/david/tcpdump.out",
    errbuf);
            const u_char * packet;
            struct pcap_pkthdr hdr;

            packet = pcap_next(descr, &hdr);
            while (packet){

                    unsigned packetSize= hdr.len;
                    for (unsigned i=0; i< packetSize;i++){
                            fout<<packet[i];
                    }

                    packet = pcap_next(descr, &hdr);

            }

            return 0;
    }
    --------------------------------

    and here's the info on the output file:
    -rw-r--r-- 1 david david 1508 Oct 26 01:36 pcaptest.out

    How come the size of the output file does not match the actual dump
    file at all? And furthermore, how come the it's larger in size?

    any help/comment is appreciated.

    thanks in advanced!
    -D


  • Next message: Neil: "What to backup for LVM?"

    Relevant Pages

    • libpcap problem (hdr.len vs tcpdump file size)?
      ... I'm trying to use libpcap to output tpcdump raw data that I've ... here's the info of the tcpdump file: ... when I use my code to capture the packets in that file and ... than the actual dump file. ...
      (comp.os.linux.networking)
    • libpcap problem (hdr.len vs tcpdump file size)?
      ... I'm trying to use libpcap to output tpcdump raw data that I've ... here's the info of the tcpdump file: ... when I use my code to capture the packets in that file and ... than the actual dump file. ...
      (comp.os.linux.networking)
    • libpcap problem (hdr.len vs tcpdump file size)?
      ... I'm trying to use libpcap to output tpcdump raw data that I've ... here's the info of the tcpdump file: ... when I use my code to capture the packets in that file and ... than the actual dump file. ...
      (comp.os.linux.development.apps)
    • libpcap problem (hdr.len vs tcpdump file size)?
      ... I'm trying to use libpcap to output tpcdump raw data that I've ... here's the info of the tcpdump file: ... when I use my code to capture the packets in that file and ... than the actual dump file. ...
      (comp.os.linux.development.apps)
    • libpcap problem (hdr.len vs tcpdump file size)?
      ... I'm trying to use libpcap to output tpcdump raw data that I've ... here's the info of the tcpdump file: ... when I use my code to capture the packets in that file and ... than the actual dump file. ...
      (comp.os.linux.development.system)