Intercept.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2015 ZeroTier, Inc.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * --
  19. *
  20. * ZeroTier may be used and distributed under the terms of the GPLv3, which
  21. * are available at: http://www.gnu.org/licenses/gpl-3.0.html
  22. *
  23. * If you would like to embed ZeroTier into a commercial application or
  24. * redistribute it in a modified binary form, please contact ZeroTier Networks
  25. * LLC. Start here: http://www.zerotier.com/
  26. */
  27. #ifndef _INTERCEPT_H
  28. #define _INTERCEPT_H 1
  29. #include <sys/socket.h>
  30. #if defined(__linux__)
  31. #define ACCEPT4_SIG int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags
  32. #define SYSCALL_SIG long number, ...
  33. #endif
  34. #define CLOSE_SIG int fd
  35. #define READ_SIG int __fd, void *__buf, size_t __nbytes
  36. #define BIND_SIG int sockfd, const struct sockaddr *addr, socklen_t addrlen
  37. #define CONNECT_SIG int __fd, const struct sockaddr * __addr, socklen_t __len
  38. #define WRITE_SIG int __fd, const void *__buf, size_t __n
  39. #define LISTEN_SIG int sockfd, int backlog
  40. #define SOCKET_SIG int socket_family, int socket_type, int protocol
  41. #define ACCEPT_SIG int sockfd, struct sockaddr *addr, socklen_t *addrlen
  42. #define SHUTDOWN_SIG int socket, int how
  43. #define CONNECT_SOCKARG struct sockaddr *
  44. #define IOCTL_SIG int __fd, unsigned long int __request, ...
  45. #define FCNTL_SIG int __fd, int __cmd, ...
  46. #define DAEMON_SIG int nochdir, int noclose
  47. #define SETSOCKOPT_SIG int socket, int level, int option_name, const void *option_value, socklen_t option_len
  48. #define GETSOCKOPT_SIG int sockfd, int level, int optname, void *optval, socklen_t *optlen
  49. #define CLONE_SIG int (*fn)(void *), void *child_stack, int flags, void *arg, ...
  50. #define GETSOCKNAME_SIG int sockfd, struct sockaddr *addr, socklen_t *addrlen
  51. #define DUP2_SIG int oldfd, int newfd
  52. #define DUP3_SIG int oldfd, int newfd, int flags
  53. #if defined(__linux__)
  54. int accept4(ACCEPT4_SIG);
  55. long syscall(SYSCALL_SIG);
  56. #endif
  57. void my_init(void);
  58. int connect(CONNECT_SIG);
  59. int bind(BIND_SIG);
  60. int accept(ACCEPT_SIG);
  61. int listen(LISTEN_SIG);
  62. int socket(SOCKET_SIG);
  63. int setsockopt(SETSOCKOPT_SIG);
  64. int getsockopt(GETSOCKOPT_SIG);
  65. int close(CLOSE_SIG);
  66. int clone(CLONE_SIG);
  67. int dup2(DUP2_SIG);
  68. int dup3(DUP3_SIG);
  69. int getsockname(GETSOCKNAME_SIG);
  70. #if defined(__linux__)
  71. static int (*realaccept4)(ACCEPT4_SIG) = 0;
  72. static long (*realsyscall)(SYSCALL_SIG) = 0;
  73. #endif
  74. static int (*realconnect)(CONNECT_SIG) = 0;
  75. static int (*realbind)(BIND_SIG) = 0;
  76. static int (*realaccept)(ACCEPT_SIG) = 0;
  77. static int (*reallisten)(LISTEN_SIG) = 0;
  78. static int (*realsocket)(SOCKET_SIG) = 0;
  79. static int (*realsetsockopt)(SETSOCKOPT_SIG) = 0;
  80. static int (*realgetsockopt)(GETSOCKOPT_SIG) = 0;
  81. static int (*realclose)(CLOSE_SIG) = 0;
  82. static int (*realgetsockname)(GETSOCKNAME_SIG) = 0;
  83. #endif