socket_wrapper: fix PCAP support broken by aaea68791cfea45c6fa69abc93ad6d0e832d0283
[ira/wip.git] / lib / socket_wrapper / socket_wrapper.c
index 9d619769507792cef1984f36b20e67539180dd93..1e3927705b215ba85bccd05522f4c70540ca9c00 100644 (file)
@@ -899,7 +899,10 @@ static int swrap_get_pcap_fd(const char *fname)
                file_hdr.frame_max_len  = SWRAP_FRAME_LENGTH_MAX;
                file_hdr.link_type      = 0x0065; /* 101 RAW IP */
 
-               write(fd, &file_hdr, sizeof(file_hdr));
+               if (write(fd, &file_hdr, sizeof(file_hdr)) != sizeof(file_hdr)) {
+                       close(fd);
+                       fd = -1;
+               }
                return fd;
        }
 
@@ -1190,7 +1193,10 @@ static void swrap_dump_packet(struct socket_info *si,
 
        fd = swrap_get_pcap_fd(file_name);
        if (fd != -1) {
-               write(fd, packet, packet_len);
+               if (write(fd, packet, packet_len) != packet_len) {
+                       free(packet);
+                       return;
+               }
        }
 
        free(packet);