net.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #ifndef _NET_H
  2. #define _NET_H
  3. #ifdef HAVE_CONFIG_H
  4. # include "config.h"
  5. #endif
  6. #include "types.h"
  7. #include <netinet/in.h>
  8. #include <sys/socket.h>
  9. #include <setjmp.h>
  10. #ifdef HAVE_OPENSSL_SSL_H
  11. # ifdef USE_SSL
  12. # include <openssl/ssl.h>
  13. # include <openssl/rand.h>
  14. # include <openssl/err.h>
  15. # undef HAVE_SSL
  16. # endif /* USE_SSL */
  17. /* #define HAVE_SSL 1 */
  18. #endif /* HAVE_OPENSSL_SSL_H */
  19. #define SGRAB 2010 /* How much data to allow through sockets. */
  20. enum {
  21. EGG_OPTION_SET = 1, /* Set option(s). */
  22. EGG_OPTION_UNSET = 2 /* Unset option(s). */
  23. };
  24. /* Socket flags:
  25. */
  26. #define SOCK_UNUSED BIT0 /* empty socket */
  27. #define SOCK_BINARY BIT1 /* do not buffer input */
  28. #define SOCK_LISTEN BIT2 /* listening port */
  29. #define SOCK_CONNECT BIT3 /* connection attempt */
  30. #define SOCK_NONSOCK BIT4 /* used for file i/o on debug */
  31. #define SOCK_STRONGCONN BIT5 /* don't report success until sure */
  32. #define SOCK_EOFD BIT6 /* it EOF'd recently during a write */
  33. #define SOCK_PROXYWAIT BIT7 /* waiting for SOCKS traversal */
  34. #define SOCK_PASS BIT8 /* passed on; only notify in case of traffic */
  35. #define SOCK_VIRTUAL BIT9 /* not-connected socket (dont read it!) */
  36. #define SOCK_BUFFER BIT10 /* buffer data; don't notify dcc funcs */
  37. /* Flags to sock_has_data
  38. */
  39. enum {
  40. SOCK_DATA_OUTGOING, /* Data in out-queue? */
  41. SOCK_DATA_INCOMING /* Data in in-queue? */
  42. };
  43. #define iptolong(a) (0xffffffff & \
  44. (long) (htonl((unsigned long) a)))
  45. #define CONNECT_SSL 1
  46. #define ACCEPT_SSL 2
  47. #ifdef USE_IPV6
  48. #define SIZEOF_SOCKADDR(so) ((so).sa.sa_family == AF_INET6 ? sizeof(so.sin6) : sizeof(so.sin))
  49. #else
  50. #define SIZEOF_SOCKADDR(so) (sizeof(so.sin))
  51. #endif /* USE_IPV6 */
  52. #if !defined(IN6_IS_ADDR_V4MAPPED)
  53. # define IN6_IS_ADDR_V4MAPPED(a) \
  54. ((((u_int32_t *) (a))[0] == 0) && (((u_int32_t *) (a))[1] == 0) && \
  55. (((u_int32_t *) (a))[2] == htonl (0xffff)))
  56. #endif /* !defined(IN6_IS_ADDR_V4MAPPED) */
  57. union sockaddr_union { /* replaced by sockname_t */
  58. struct sockaddr sa;
  59. struct sockaddr_in sin;
  60. #ifdef USE_IPV6
  61. struct sockaddr_in6 sin6;
  62. #endif /* USE_IPV6 */
  63. };
  64. /* This is used by the net module to keep track of sockets and what's
  65. * queued on them
  66. */
  67. typedef struct {
  68. size_t outbuflen; /* Outbuf could be binary data */
  69. size_t inbuflen; /* Inbuf could be binary data */
  70. #ifdef USE_IPV6
  71. unsigned int af;
  72. #endif /* USE_IPV6 */
  73. int sock;
  74. int encstatus; /* encrypted botlink */
  75. int oseed; /* botlink out seed */
  76. int iseed; /* botlink in seed */
  77. int gz; /* gzip compression */
  78. int enclink; /* new encrypted botlink */
  79. #ifdef HAVE_SSL
  80. SSL *ssl;
  81. #endif /* HAVE_SSL */
  82. char *inbuf;
  83. char *outbuf;
  84. char *host;
  85. port_t port;
  86. short flags;
  87. char okey[33]; /* botlink enckey: out */
  88. char ikey[33]; /* botlink enckey: in */
  89. } sock_list;
  90. # define killsock(x) real_killsock((x),__FILE__,__LINE__)
  91. unsigned long my_atoul(char *);
  92. #ifdef HAVE_SSL
  93. int ssl_cleanup();
  94. int ssl_link(int, int);
  95. #endif /* HAVE_SSL */
  96. char *myipstr(int);
  97. in_addr_t getmyip();
  98. void cache_my_ip();
  99. void setsock(int, int);
  100. int allocsock(int, int);
  101. #ifdef USE_IPV6
  102. #define getsock(opt, af) real_getsock(opt, af, __FILE__, __LINE__)
  103. int real_getsock(int, int, char *, int);
  104. #else
  105. #define getsock(opt) real_getsock(opt, __FILE__, __LINE__)
  106. int real_getsock(int, char *, int);
  107. #endif /* USE_IPV6 */
  108. int sockprotocol(int);
  109. void real_killsock(int, const char *, int);
  110. int answer(int, char *, in_addr_t *, port_t *, int);
  111. int findanysnum(register int);
  112. int open_listen(port_t *);
  113. int open_listen_by_af(port_t *, int);
  114. #ifdef USE_IPV6
  115. int open_address_listen(in_addr_t, int, port_t *);
  116. #else
  117. int open_address_listen(in_addr_t, port_t *);
  118. #endif /* USE_IPV6 */
  119. int open_telnet(const char *, port_t, bool);
  120. int open_telnet_dcc(int, char *, char *);
  121. int open_telnet_raw(int, const char *, port_t, bool);
  122. void tputs(int, char *, size_t);
  123. void dequeue_sockets();
  124. int sockgets(char *, int *);
  125. void tell_netdebug(int);
  126. char *iptostr(in_addr_t);
  127. bool sock_has_data(int, int);
  128. int sockoptions(int sock, int operation, int sock_options);
  129. void init_net(void);
  130. int sock_read(FILE *, bool);
  131. void sock_write(FILE *, int);
  132. extern union sockaddr_union cached_myip4_so;
  133. #ifdef USE_IPV6
  134. extern union sockaddr_union cached_myip6_so;
  135. extern unsigned long notalloc;
  136. #endif /* USE_IPV6 */
  137. extern char firewall[], botuser[];
  138. extern int resolve_timeout, MAXSOCKS, socks_total;
  139. extern bool identd_hack, cached_ip;
  140. extern port_t firewallport;
  141. extern jmp_buf alarmret;
  142. extern sock_list *socklist;
  143. #endif /* !_NET_H */