Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #define _GNU_SOURCE
  2. #include <stdlib.h>
  3. #include <dlfcn.h>
  4. #include <sys/types.h>
  5. #include <sys/socket.h>
  6. #include <netinet/tcp.h>
  7. #include <netinet/in.h>
  8.  
  9. static size_t tcp_nodelay_count;
  10. static size_t tcp_nodelay_errors;
  11.  
  12. int (*socket_orig)(int domain, int type, int protocol) = NULL;
  13.  
  14. __attribute__((constructor)) static void socket_init(void)
  15. {
  16. socket_orig = dlsym(RTLD_NEXT, "socket");
  17. }
  18.  
  19. int socket(int domain, int type, int protocol)
  20. {
  21. int fd = socket_orig(domain, type, protocol);
  22. if (fd < 0) {
  23. return fd;
  24. }
  25. if (type == SOCK_STREAM) {
  26. int one = 1;
  27.  
  28. ++tcp_nodelay_count;
  29. if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one))) {
  30. ++tcp_nodelay_errors;
  31. }
  32. }
  33. return fd;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement