@@ -743,6 +743,12 @@ sf_write_header(pcap_t *p, FILE *fp, int linktype, int snaplen)
743743 */
744744void
745745pcap_dump (u_char * user , const struct pcap_pkthdr * h , const u_char * sp )
746+ {
747+ (void )pcap_dump1 (user , h , sp );
748+ }
749+
750+ int
751+ pcap_dump1 (u_char * user , const struct pcap_pkthdr * h , const u_char * sp )
746752{
747753 register FILE * f ;
748754 struct pcap_sf_pkthdr sf_hdr ;
@@ -756,9 +762,14 @@ pcap_dump(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
756762 sf_hdr .ts .tv_usec = (bpf_int32 )h -> ts .tv_usec ;
757763 sf_hdr .caplen = h -> caplen ;
758764 sf_hdr .len = h -> len ;
759- /* XXX we should check the return status */
760- (void )fwrite (& sf_hdr , sizeof (sf_hdr ), 1 , f );
761- (void )fwrite (sp , h -> caplen , 1 , f );
765+ if (fwrite (& sf_hdr , 1 , sizeof (sf_hdr ), f ) != sizeof (sf_hdr )) {
766+ return (-1 );
767+ }
768+ if (fwrite (sp , 1 , h -> caplen , f ) != h -> caplen ) {
769+ return (-1 );
770+ }
771+
772+ return (0 );
762773}
763774
764775static pcap_dumper_t *
@@ -1154,11 +1165,14 @@ pcap_dump_flush(pcap_dumper_t *p)
11541165void
11551166pcap_dump_close (pcap_dumper_t * p )
11561167{
1168+ (void )pcap_dump_close1 (p );
1169+ }
11571170
1158- #ifdef notyet
1159- if (ferror ((FILE * )p ))
1160- return - an - error ;
1161- /* XXX should check return from fclose() too */
1162- #endif
1163- (void )fclose ((FILE * )p );
1171+ int
1172+ pcap_dump_close1 (pcap_dumper_t * p )
1173+ {
1174+ if (fclose ((FILE * )p ) == EOF ) {
1175+ return (-1 );
1176+ }
1177+ return (0 );
11641178}
0 commit comments