Update recyclix.c
[hband-ld-preload-libs.git] / src / tcpmaxrt.c
blobe8af6853204f2dfcd6fbbcb8307671a43413c5ae
1 // gcc tcpmaxrt.c -fPIC -shared -ldl -o tcpmaxrt.so
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <dlfcn.h>
6 #include <sys/types.h>
7 #include <sys/socket.h>
8 #include <linux/tcp.h>
11 int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen)
14 int (*real_setsockopt)(int sockfd, int level, int optname, const void *optval, socklen_t optlen) = NULL;
15 int real_setsockopt_return;
16 int i1 = 1;
18 if (real_setsockopt == NULL) {
19 void *handle = dlopen("/lib/libc.so.6", RTLD_LAZY);
20 if (handle == NULL) {
21 fprintf(stderr, "dlopen: %s\n", dlerror());
22 exit(1);
24 real_setsockopt = dlsym(handle, "setsockopt");
25 if (real_setsockopt == NULL) {
26 fprintf(stderr, "dlsym: %s\n", dlerror());
27 exit(1);
31 fprintf(stderr, "setsockopt: optname=%d optval=%d\n", optname, optval);
32 fflush(stderr);
34 real_setsockopt_return = real_setsockopt(sockfd, level, optname, optval, optlen);
35 fprintf(stderr, "setsockopt %d\n",
36 real_setsockopt(sockfd, level, TCP_, (const void *)&i1, optlen)
38 fflush(stderr);
40 return real_setsockopt_return;