Deleted Added
full compact
savefile.c (39291) savefile.c (56889)
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[] =
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[] =
33 "@(#) $Header: savefile.c,v 1.37 97/10/15 21:58:58 leres Exp $ (LBL)";
33 "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.38 1999/11/21 01:11:58 assar Exp $ (LBL)";
34#endif
35
36#include <sys/types.h>
37#include <sys/time.h>
38
39#include <errno.h>
40#include <memory.h>
41#include <stdio.h>

--- 147 unchanged lines hidden (view full) ---

189/*
190 * Read sf_readfile and return the next packet. Return the header in hdr
191 * and the contents in buf. Return 0 on success, SFERR_EOF if there were
192 * no more packets, and SFERR_TRUNC if a partial packet was encountered.
193 */
194static int
195sf_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char *buf, int buflen)
196{
34#endif
35
36#include <sys/types.h>
37#include <sys/time.h>
38
39#include <errno.h>
40#include <memory.h>
41#include <stdio.h>

--- 147 unchanged lines hidden (view full) ---

189/*
190 * Read sf_readfile and return the next packet. Return the header in hdr
191 * and the contents in buf. Return 0 on success, SFERR_EOF if there were
192 * no more packets, and SFERR_TRUNC if a partial packet was encountered.
193 */
194static int
195sf_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char *buf, int buflen)
196{
197 struct pcap_sf_pkthdr sf_hdr;
197 FILE *fp = p->sf.rfile;
198
199 /* read the stamp */
198 FILE *fp = p->sf.rfile;
199
200 /* read the stamp */
200 if (fread((char *)hdr, sizeof(struct pcap_pkthdr), 1, fp) != 1) {
201 if (fread(&sf_hdr, sizeof(struct pcap_sf_pkthdr), 1, fp) != 1) {
201 /* probably an EOF, though could be a truncated packet */
202 return (1);
203 }
204
205 if (p->sf.swapped) {
206 /* these were written in opposite byte order */
202 /* probably an EOF, though could be a truncated packet */
203 return (1);
204 }
205
206 if (p->sf.swapped) {
207 /* these were written in opposite byte order */
207 hdr->caplen = SWAPLONG(hdr->caplen);
208 hdr->len = SWAPLONG(hdr->len);
209 hdr->ts.tv_sec = SWAPLONG(hdr->ts.tv_sec);
210 hdr->ts.tv_usec = SWAPLONG(hdr->ts.tv_usec);
208 hdr->caplen = SWAPLONG(sf_hdr.caplen);
209 hdr->len = SWAPLONG(sf_hdr.len);
210 hdr->ts.tv_sec = SWAPLONG(sf_hdr.ts.tv_sec);
211 hdr->ts.tv_usec = SWAPLONG(sf_hdr.ts.tv_usec);
212 } else {
213 hdr->caplen = sf_hdr.caplen;
214 hdr->len = sf_hdr.len;
215 hdr->ts.tv_sec = sf_hdr.ts.tv_sec;
216 hdr->ts.tv_usec = sf_hdr.ts.tv_usec;
211 }
212 /*
213 * We interchanged the caplen and len fields at version 2.3,
214 * in order to match the bpf header layout. But unfortunately
215 * some files were written with version 2.3 in their headers
216 * but without the interchanged fields.
217 */
218 if (p->sf.version_minor < 3 ||

--- 87 unchanged lines hidden (view full) ---

306
307/*
308 * Output a packet to the initialized dump file.
309 */
310void
311pcap_dump(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
312{
313 register FILE *f;
217 }
218 /*
219 * We interchanged the caplen and len fields at version 2.3,
220 * in order to match the bpf header layout. But unfortunately
221 * some files were written with version 2.3 in their headers
222 * but without the interchanged fields.
223 */
224 if (p->sf.version_minor < 3 ||

--- 87 unchanged lines hidden (view full) ---

312
313/*
314 * Output a packet to the initialized dump file.
315 */
316void
317pcap_dump(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
318{
319 register FILE *f;
320 struct pcap_sf_pkthdr sf_hdr;
314
315 f = (FILE *)user;
321
322 f = (FILE *)user;
323 sf_hdr.ts.tv_sec = h->ts.tv_sec;
324 sf_hdr.ts.tv_usec = h->ts.tv_usec;
325 sf_hdr.caplen = h->caplen;
326 sf_hdr.len = h->len;
316 /* XXX we should check the return status */
327 /* XXX we should check the return status */
317 (void)fwrite((char *)h, sizeof(*h), 1, f);
328 (void)fwrite(&sf_hdr, sizeof(sf_hdr), 1, f);
318 (void)fwrite((char *)sp, h->caplen, 1, f);
319}
320
321/*
322 * Initialize so that sf_write() will output to the file named 'fname'.
323 */
324pcap_dumper_t *
325pcap_dump_open(pcap_t *p, const char *fname)

--- 27 unchanged lines hidden ---
329 (void)fwrite((char *)sp, h->caplen, 1, f);
330}
331
332/*
333 * Initialize so that sf_write() will output to the file named 'fname'.
334 */
335pcap_dumper_t *
336pcap_dump_open(pcap_t *p, const char *fname)

--- 27 unchanged lines hidden ---