/*
* Copyright (C)2026 kimapr
*
* This file is part of fcnatfw.
*
* fcnatfw is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* fcnatfw is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see .
*
*/
#include
#include
#include
typedef int (*Ftype_socket)(int, int, int);
int socket(int domain, int type, int protocol) {
static Ftype_socket real_socket = NULL;
if (!real_socket)
real_socket = dlsym(RTLD_NEXT, "socket");
int sock = real_socket(domain, type, protocol);
if (sock < 0 || !(domain == AF_INET || domain == AF_INET6))
return sock;
int optval = 1;
setsockopt(sock, SOL_SOCKET,
#ifdef SO_REUSEPORT_LB
SO_REUSEPORT_LB
#else
#ifdef SO_REUSEPORT
SO_REUSEPORT
#else
#error SO_REUSEPORT is required for operation. Your platform is not supported
#endif
#endif
, &optval, sizeof(optval));
return sock;
}