swap back socket address when reply by sendmsg
[hband-ld-preload-libs.git] / src / alarmwrite.c
blob33c48cb5589031b38ea5d007f8dfbcbd98676602
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <dlfcn.h>
4 #include <unistd.h>
6 ssize_t write(int fd, const void *buf, size_t count)
8 int (*real_write)(int fd, const void *buf, size_t count) = NULL;
9 int real_write_return;
10 int alarm_sec = 2;
12 if (real_write == NULL) {
13 void *handle = dlopen(/* "/lib/libc.so.6" */ "/lib/i386-linux-gnu/libc.so.6", RTLD_LAZY);
14 if (handle == NULL) {
15 fprintf(stderr, "dlopen: %s\n", dlerror());
16 exit(1);
18 real_write = dlsym(handle, "write");
19 if (real_write == NULL) {
20 fprintf(stderr, "dlsym: %s\n", dlerror());
21 exit(1);
25 alarm(alarm_sec);
26 real_write_return = real_write(fd, buf, count);
27 alarm(0);
28 return real_write_return;
31 // Fordítás: gcc -s -x c alarmwrite.c -fPIC -shared -o alarmwrite.so
32 // Futtatás: LD_PRELOAD=./alarmwrite.so x2vnc host:display