1/*
2 * Copyright (c) 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
--- 16 unchanged lines hidden (view full) ---
25 * Used to save the received packet headers, after filtering, to
26 * a file, and then read them later.
27 * The first record in the file contains saved values for the machine
28 * dependent values so we can print the dump file on any architecture.
29 */
30
31#ifndef lint
32static const char rcsid[] _U_ =
33 "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.126.2.13 2005/08/29 21:05:45 guy Exp $ (LBL)";
34#endif
35
36#ifdef HAVE_CONFIG_H
37#include "config.h"
38#endif
39
40#include <errno.h>
41#include <memory.h>
--- 383 unchanged lines hidden (view full) ---
425 * like interface index, interface name
426 * before standard Ethernet, PPP, Frelay & C-HDLC Frames
427 */
428#define LINKTYPE_JUNIPER_ETHER 178
429#define LINKTYPE_JUNIPER_PPP 179
430#define LINKTYPE_JUNIPER_FRELAY 180
431#define LINKTYPE_JUNIPER_CHDLC 181
432
433static struct linktype_map {
434 int dlt;
435 int linktype;
436} map[] = {
437 /*
438 * These DLT_* codes have LINKTYPE_* codes with values identical
439 * to the values of the corresponding DLT_* code.
440 */
--- 189 unchanged lines hidden (view full) ---
630 { DLT_LINUX_LAPD, LINKTYPE_LINUX_LAPD },
631
632 /* Juniper meta-information before Ether, PPP, Frame Relay, C-HDLC Frames */
633 { DLT_JUNIPER_ETHER, LINKTYPE_JUNIPER_ETHER },
634 { DLT_JUNIPER_PPP, LINKTYPE_JUNIPER_PPP },
635 { DLT_JUNIPER_FRELAY, LINKTYPE_JUNIPER_FRELAY },
636 { DLT_JUNIPER_CHDLC, LINKTYPE_JUNIPER_CHDLC },
637
638
639 { -1, -1 }
640};
641
642static int
643dlt_to_linktype(int dlt)
644{
645 int i;
646
--- 218 unchanged lines hidden (view full) ---
865 p->sf.hdrsize = sizeof(struct pcap_sf_pkthdr);
866 if (hdr.version_major < PCAP_VERSION_MAJOR) {
867 snprintf(errbuf, PCAP_ERRBUF_SIZE, "archaic file format");
868 goto bad;
869 }
870 p->tzoff = hdr.thiszone;
871 p->snapshot = hdr.snaplen;
872 p->linktype = linktype_to_dlt(hdr.linktype);
873 p->sf.rfile = fp;
874#ifndef WIN32
875 p->bufsize = hdr.snaplen;
876#else
877 /* Allocate the space for pcap_pkthdr as well. It will be used by pcap_read_ex */
878 p->bufsize = hdr.snaplen+sizeof(struct pcap_pkthdr);
879#endif
880
--- 291 unchanged lines hidden (view full) ---
1172
1173 f = (FILE *)user;
1174 sf_hdr.ts.tv_sec = h->ts.tv_sec;
1175 sf_hdr.ts.tv_usec = h->ts.tv_usec;
1176 sf_hdr.caplen = h->caplen;
1177 sf_hdr.len = h->len;
1178 /* XXX we should check the return status */
1179 (void)fwrite(&sf_hdr, sizeof(sf_hdr), 1, f);
1180 (void)fwrite((char *)sp, h->caplen, 1, f);
1181}
1182
1183static pcap_dumper_t *
1184pcap_setup_dump(pcap_t *p, int linktype, FILE *f, const char *fname)
1185{
1186
1187#if defined(WIN32) || defined(MSDOS)
1188 /*
--- 108 unchanged lines hidden ---
2 * Copyright (c) 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
--- 16 unchanged lines hidden (view full) ---
25 * Used to save the received packet headers, after filtering, to
26 * a file, and then read them later.
27 * The first record in the file contains saved values for the machine
28 * dependent values so we can print the dump file on any architecture.
29 */
30
31#ifndef lint
32static const char rcsid[] _U_ =
33 "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.126.2.13 2005/08/29 21:05:45 guy Exp $ (LBL)";
34#endif
35
36#ifdef HAVE_CONFIG_H
37#include "config.h"
38#endif
39
40#include <errno.h>
41#include <memory.h>
--- 383 unchanged lines hidden (view full) ---
425 * like interface index, interface name
426 * before standard Ethernet, PPP, Frelay & C-HDLC Frames
427 */
428#define LINKTYPE_JUNIPER_ETHER 178
429#define LINKTYPE_JUNIPER_PPP 179
430#define LINKTYPE_JUNIPER_FRELAY 180
431#define LINKTYPE_JUNIPER_CHDLC 181
432
433static struct linktype_map {
434 int dlt;
435 int linktype;
436} map[] = {
437 /*
438 * These DLT_* codes have LINKTYPE_* codes with values identical
439 * to the values of the corresponding DLT_* code.
440 */
--- 189 unchanged lines hidden (view full) ---
630 { DLT_LINUX_LAPD, LINKTYPE_LINUX_LAPD },
631
632 /* Juniper meta-information before Ether, PPP, Frame Relay, C-HDLC Frames */
633 { DLT_JUNIPER_ETHER, LINKTYPE_JUNIPER_ETHER },
634 { DLT_JUNIPER_PPP, LINKTYPE_JUNIPER_PPP },
635 { DLT_JUNIPER_FRELAY, LINKTYPE_JUNIPER_FRELAY },
636 { DLT_JUNIPER_CHDLC, LINKTYPE_JUNIPER_CHDLC },
637
638
639 { -1, -1 }
640};
641
642static int
643dlt_to_linktype(int dlt)
644{
645 int i;
646
--- 218 unchanged lines hidden (view full) ---
865 p->sf.hdrsize = sizeof(struct pcap_sf_pkthdr);
866 if (hdr.version_major < PCAP_VERSION_MAJOR) {
867 snprintf(errbuf, PCAP_ERRBUF_SIZE, "archaic file format");
868 goto bad;
869 }
870 p->tzoff = hdr.thiszone;
871 p->snapshot = hdr.snaplen;
872 p->linktype = linktype_to_dlt(hdr.linktype);
873 p->sf.rfile = fp;
874#ifndef WIN32
875 p->bufsize = hdr.snaplen;
876#else
877 /* Allocate the space for pcap_pkthdr as well. It will be used by pcap_read_ex */
878 p->bufsize = hdr.snaplen+sizeof(struct pcap_pkthdr);
879#endif
880
--- 291 unchanged lines hidden (view full) ---
1172
1173 f = (FILE *)user;
1174 sf_hdr.ts.tv_sec = h->ts.tv_sec;
1175 sf_hdr.ts.tv_usec = h->ts.tv_usec;
1176 sf_hdr.caplen = h->caplen;
1177 sf_hdr.len = h->len;
1178 /* XXX we should check the return status */
1179 (void)fwrite(&sf_hdr, sizeof(sf_hdr), 1, f);
1180 (void)fwrite((char *)sp, h->caplen, 1, f);
1181}
1182
1183static pcap_dumper_t *
1184pcap_setup_dump(pcap_t *p, int linktype, FILE *f, const char *fname)
1185{
1186
1187#if defined(WIN32) || defined(MSDOS)
1188 /*
--- 108 unchanged lines hidden ---