/* pdumpq - Pcap Dump for Linux/Netfilter QUEUE * * Copyright (C) 2001 Ian Jones * * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include /* write pcap header and packet */ /* returns 1 for success 0 for failure */ int dump_pkt (ipq_packet_msg_t * m, FILE * out) { struct pcap_pkthdr ph; struct timeval tv; struct timezone tz; /* locally generated?, no timestamp */ if (!m->timestamp_sec) { memset (&tz, 0, sizeof (tz)); gettimeofday (&tv, &tz); ph.ts.tv_sec = tv.tv_sec; ph.ts.tv_usec = tv.tv_usec; } else { ph.ts.tv_sec = m->timestamp_sec; ph.ts.tv_usec = m->timestamp_usec; } ph.caplen = m->data_len; ph.len = m->data_len; if (fwrite (&ph, sizeof ph, 1, out) && fwrite (m->payload, m->data_len, 1, out)) { fflush (out); return 1; } return 0; } /* every pcap dump stream will begin with this */ /* returns 1 for success 0 for failure */ int write_file_header (FILE * out) { int write; struct pcap_file_header fh = { TCPDUMP_MAGIC, PCAP_VERSION_MAJOR, PCAP_VERSION_MINOR, gmt2local (0), 0, 65535, DLT_RAW }; write = fwrite (&fh, sizeof (struct pcap_file_header), 1, out); fflush (out); return write; }