20 lines
492 B
C
20 lines
492 B
C
#include <sys/socket.h>
|
|
#include <stdlib.h>
|
|
#include <dlfcn.h>
|
|
|
|
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, SO_REUSEPORT, &optval, sizeof(optval));
|
|
return sock;
|
|
}
|