mirror of
https://github.com/adulau/ssldump.git
synced 2024-11-07 12:06:27 +00:00
Merge pull request #58 from wllm-rbnt/dev
Add support for pcap output to FIFO
This commit is contained in:
commit
deb2566496
1 changed files with 19 additions and 14 deletions
|
@ -219,25 +219,30 @@ logpkt_pcap_open_fd(int fd) {
|
||||||
pcap_file_hdr_t hdr;
|
pcap_file_hdr_t hdr;
|
||||||
off_t sz;
|
off_t sz;
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
sz = lseek(fd, 0, SEEK_END);
|
if(fstat(fd, &st))
|
||||||
if (sz == -1)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (sz > 0) {
|
if(!S_ISFIFO(st.st_mode)) {
|
||||||
if (lseek(fd, 0, SEEK_SET) == -1)
|
sz = lseek(fd, 0, SEEK_END);
|
||||||
|
if (sz == -1)
|
||||||
return -1;
|
return -1;
|
||||||
n = read(fd, &hdr, sizeof(pcap_file_hdr_t));
|
|
||||||
if (n != sizeof(pcap_file_hdr_t))
|
|
||||||
return -1;
|
|
||||||
if (hdr.magic_number == PCAP_MAGIC)
|
|
||||||
return lseek(fd, 0, SEEK_END) == -1 ? -1 : 0;
|
|
||||||
if (lseek(fd, 0, SEEK_SET) == -1)
|
|
||||||
return -1;
|
|
||||||
if (ftruncate(fd, 0) == -1)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (sz > 0) {
|
||||||
|
if (lseek(fd, 0, SEEK_SET) == -1)
|
||||||
|
return -1;
|
||||||
|
n = read(fd, &hdr, sizeof(pcap_file_hdr_t));
|
||||||
|
if (n != sizeof(pcap_file_hdr_t))
|
||||||
|
return -1;
|
||||||
|
if (hdr.magic_number == PCAP_MAGIC)
|
||||||
|
return lseek(fd, 0, SEEK_END) == -1 ? -1 : 0;
|
||||||
|
if (lseek(fd, 0, SEEK_SET) == -1)
|
||||||
|
return -1;
|
||||||
|
if (ftruncate(fd, 0) == -1)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
return logpkt_write_global_pcap_hdr(fd);
|
return logpkt_write_global_pcap_hdr(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue