net.h 5.1 KB

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