2
0

proxy.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*************************************************************************
  2. *
  3. * Copyright (C) 2018-2025 Ruilin Peng (Nick) <[email protected]>.
  4. *
  5. * smartdns 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. * smartdns 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. #ifndef SMART_DNS_PROXY_H
  19. #define SMART_DNS_PROXY_H
  20. #include <sys/socket.h>
  21. #include <sys/types.h>
  22. #define PROXY_MAX_IPLEN 256
  23. #define PROXY_MAX_NAMELEN 128
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif /*__cplusplus */
  27. typedef enum {
  28. PROXY_SOCKS5,
  29. PROXY_HTTP,
  30. PROXY_TYPE_END,
  31. } proxy_type_t;
  32. typedef enum {
  33. PROXY_HANDSHAKE_ERR = -1,
  34. PROXY_HANDSHAKE_OK = 0,
  35. PROXY_HANDSHAKE_CONNECTED = 1,
  36. PROXY_HANDSHAKE_WANT_READ = 2,
  37. PROXY_HANDSHAKE_WANT_WRITE = 3,
  38. } proxy_handshake_state;
  39. struct proxy_info {
  40. proxy_type_t type;
  41. char server[PROXY_MAX_IPLEN];
  42. unsigned short port;
  43. int use_domain;
  44. char username[PROXY_MAX_NAMELEN];
  45. char password[PROXY_MAX_NAMELEN];
  46. };
  47. struct proxy_conn;
  48. int proxy_init(void);
  49. void proxy_exit(void);
  50. int proxy_add(const char *proxy_name, struct proxy_info *info);
  51. int proxy_remove(const char *proxy_name);
  52. struct proxy_conn *proxy_conn_new(const char *proxy_name, const char *host, int port, int is_udp, int non_block);
  53. int proxy_conn_get_fd(struct proxy_conn *proxy_conn);
  54. int proxy_conn_get_udpfd(struct proxy_conn *proxy_conn);
  55. int proxy_conn_is_udp(struct proxy_conn *proxy_conn);
  56. void proxy_conn_free(struct proxy_conn *proxy_conn);
  57. int proxy_conn_connect(struct proxy_conn *proxy_conn);
  58. int proxy_conn_sendto(struct proxy_conn *proxy_conn, const void *buf, size_t len, int flags,
  59. const struct sockaddr *dest_addr, socklen_t addrlen);
  60. int proxy_conn_recvfrom(struct proxy_conn *proxy_conn, void *buf, size_t len, int flags, struct sockaddr *src_addr,
  61. socklen_t *addrlen);
  62. proxy_handshake_state proxy_conn_handshake(struct proxy_conn *proxy_conn);
  63. #ifdef __cplusplus
  64. }
  65. #endif /*__cplusplus */
  66. #endif