mirror of
https://github.com/pavel-odintsov/fastnetmon
synced 2024-05-27 13:06:13 +02:00
Unified getsockopt between platforms
This commit is contained in:
parent
0ec5123b67
commit
c5fbbc22b8
|
@ -2522,13 +2522,10 @@ void start_netflow_collector(std::string netflow_host, unsigned int netflow_port
|
|||
|
||||
int reuse_port_optval = 1;
|
||||
|
||||
#ifdef _WIN32
|
||||
// Windows uses char* as 4rd argument: https://learn.microsoft.com/en-gb/windows/win32/api/winsock/nf-winsock-getsockopt and we need to add explicit cast
|
||||
// I prefer not to expand this logic to other platforms without testing
|
||||
// Windows uses char* as 4rd argument: https://learn.microsoft.com/en-gb/windows/win32/api/winsock/nf-winsock-getsockopt and we need to add explicit cast
|
||||
// Linux uses void* https://linux.die.net/man/2/setsockopt
|
||||
// So I think char* works for both platforms
|
||||
auto set_reuse_port_res = setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, (char*)&reuse_port_optval, sizeof(reuse_port_optval));
|
||||
#else
|
||||
auto set_reuse_port_res = setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, &reuse_port_optval, sizeof(reuse_port_optval));
|
||||
#endif
|
||||
|
||||
if (set_reuse_port_res != 0) {
|
||||
logger << log4cpp::Priority::ERROR << "Cannot enable reuse port mode";
|
||||
|
|
|
@ -248,13 +248,11 @@ void start_sflow_collector(std::string interface_for_binding, unsigned int sflow
|
|||
socklen_t value_length = sizeof(receive_buffer);
|
||||
|
||||
// Get current read buffer size
|
||||
#ifdef _WIN32
|
||||
|
||||
// Windows uses char* as 4rd argument: https://learn.microsoft.com/en-gb/windows/win32/api/winsock/nf-winsock-getsockopt and we need to add explicit cast
|
||||
// I prefer not to expand this logic to other platforms without testing
|
||||
// Linux uses void* https://linux.die.net/man/2/setsockopt
|
||||
// So I think char* works for both platforms
|
||||
int get_buffer_size_res = getsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, (char*)&receive_buffer, &value_length);
|
||||
#else
|
||||
int get_buffer_size_res = getsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &receive_buffer, &value_length);
|
||||
#endif
|
||||
|
||||
if (get_buffer_size_res != 0) {
|
||||
logger << log4cpp::Priority::ERROR << "Cannot retrieve default receive buffer size for sFlow";
|
||||
|
|
Loading…
Reference in New Issue