Skip to content

Commit

Permalink
pcap-file: limit setvbuf to linux
Browse files Browse the repository at this point in the history
As it fails to work correctly on FreeBSD and OpenBSD.

On FreeBSD, these are the errors:

Info: pcap: Pcap-file will use 4096 buffer size [PcapFileGlobalInit:source-pcap-file.c:159]
Error: pcap: failed to get first packet timestamp. pcap_next_ex(): -2 [PeekFirstPacketTimestamp:source-pcap-file-helper.c:186]
Warning: pcap: Failed to init pcap file input.pcap, skipping [ReceivePcapFileThreadInit:source-pcap-file.c:299]
Error: pcap: pcap file reader thread failed to initialize [ReceivePcapFileLoop:source-pcap-file.c:185]
  • Loading branch information
victorjulien committed Aug 30, 2024
1 parent 688bd53 commit cff82f1
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
;;
*-*-linux*)
# Always compile with -fPIC on Linux for shared library support.
CFLAGS="${CFLAGS} -fPIC"
CFLAGS="${CFLAGS} -fPIC -DOS_LINUX"
RUST_LDADD="-ldl -lrt -lm"
can_build_shared_library="yes"
AC_DEFINE([SYSTEMD_NOTIFY], [1], [make Suricata notify systemd on startup])
Expand Down
2 changes: 1 addition & 1 deletion src/source-pcap-file-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ TmEcode InitPcapFile(PcapFileFileVars *pfv)
SCReturnInt(TM_ECODE_FAILED);
}

#if defined(HAVE_SETVBUF) && !defined(OS_WIN32)
#if defined(HAVE_SETVBUF) && defined(OS_LINUX)
if (pcap_g.read_buffer_size > 0) {
errno = 0;
if (setvbuf(pcap_file(pfv->pcap_handle), pfv->buffer, _IOFBF, pcap_g.read_buffer_size) <
Expand Down
2 changes: 1 addition & 1 deletion src/source-pcap-file-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ typedef struct PcapFileFileVars_

/** flex array member for the libc io read buffer. Size controlled by
* PcapFileGlobalVars::read_buffer_size. */
#if defined(HAVE_SETVBUF) && !defined(OS_WIN32)
#if defined(HAVE_SETVBUF) && defined(OS_LINUX)
char buffer[];
#endif
} PcapFileFileVars;
Expand Down
2 changes: 1 addition & 1 deletion src/source-pcap-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void PcapFileGlobalInit(void)
memset(&pcap_g, 0x00, sizeof(pcap_g));
SC_ATOMIC_INIT(pcap_g.invalid_checksums);

#if defined(HAVE_SETVBUF) && !defined(OS_WIN32)
#if defined(HAVE_SETVBUF) && defined(OS_LINUX)
pcap_g.read_buffer_size = PCAP_FILE_BUFFER_SIZE_DEFAULT;

const char *str = NULL;
Expand Down

0 comments on commit cff82f1

Please sign in to comment.