diff options
author | Guy Harris <guy@alum.mit.edu> | 1999-08-18 04:41:20 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 1999-08-18 04:41:20 +0000 |
commit | 28809e20028e495ac737d6232449e28c00f86c0d (patch) | |
tree | 1b0ba7d109189bab7ee7bae2e025ef017d489a4d /wiretap/libpcap.c | |
parent | df490a7085f382fbf4867fe9811af2653af91c17 (diff) |
Make "wtap_dump()" and "wtap_dump_close()" return error codes, and check
for errors when closing a file to which we've written packets (we don't
bother checking if we're giving up on a capture).
Add some more error checks in Wiretap.
Make a single list of all Wiretap error codes, giving them all different
values (some can be returned by more than one routine, so they shouldn't
be per-routine).
svn path=/trunk/; revision=510
Diffstat (limited to 'wiretap/libpcap.c')
-rw-r--r-- | wiretap/libpcap.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/wiretap/libpcap.c b/wiretap/libpcap.c index c44eeee62e..59e87f9954 100644 --- a/wiretap/libpcap.c +++ b/wiretap/libpcap.c @@ -1,6 +1,6 @@ /* libpcap.c * - * $Id: libpcap.c,v 1.7 1999/08/18 04:17:35 guy Exp $ + * $Id: libpcap.c,v 1.8 1999/08/18 04:41:19 guy Exp $ * * Wiretap Library * Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu> @@ -72,8 +72,8 @@ struct pcaprec_hdr { static int libpcap_read(wtap *wth); static int libpcap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, - const u_char *pd); -static int libpcap_dump_close(wtap_dumper *wdh); + const u_char *pd, int *err); +static int libpcap_dump_close(wtap_dumper *wdh, int *err); static const int pcap_encap[] = { WTAP_ENCAP_NONE, /* no encapsulation */ @@ -298,7 +298,7 @@ int libpcap_dump_open(wtap_dumper *wdh, int *err) /* Write a record for a packet to a dump file. Returns 1 on success, 0 on failure. */ static int libpcap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, - const u_char *pd) + const u_char *pd, int *err) { struct pcaprec_hdr rec_hdr; int nwritten; @@ -308,17 +308,28 @@ static int libpcap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, rec_hdr.incl_len = phdr->caplen; rec_hdr.orig_len = phdr->len; nwritten = fwrite(&rec_hdr, 1, sizeof rec_hdr, wdh->fh); - if (nwritten != sizeof rec_hdr) - return 0; /* failed (XXX - save reason why) */ + if (nwritten != sizeof rec_hdr) { + if (nwritten < 0) + *err = errno; + else + *err = WTAP_ERR_SHORT_WRITE; + return 0; + } nwritten = fwrite(pd, 1, phdr->caplen, wdh->fh); - if (nwritten != phdr->caplen) - return 0; /* failed (XXX - save reason why) */ + if (nwritten != phdr->caplen) { + if (nwritten < 0) + *err = errno; + else + *err = WTAP_ERR_SHORT_WRITE; + return 0; + } return 1; } -/* Close a dump file. +/* Finish writing to a dump file. Returns 1 on success, 0 on failure. */ -static int libpcap_dump_close(wtap_dumper *wdh) +static int libpcap_dump_close(wtap_dumper *wdh, int *err) { + /* Nothing to do here. */ return 1; } |