net.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 2011 /* 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 0x0001 /* empty socket */
  43. #define SOCK_BINARY 0x0002 /* do not buffer input */
  44. #define SOCK_LISTEN 0x0004 /* listening port */
  45. #define SOCK_CONNECT 0x0008 /* connection attempt */
  46. #define SOCK_NONSOCK 0x0010 /* used for file i/o on debug */
  47. #define SOCK_STRONGCONN 0x0020 /* don't report success until sure */
  48. #define SOCK_EOFD 0x0040 /* it EOF'd recently during a write */
  49. #define SOCK_PROXYWAIT 0x0080 /* waiting for SOCKS traversal */
  50. #define SOCK_PASS 0x0100 /* passed on; only notify in case
  51. of traffic */
  52. #define SOCK_VIRTUAL 0x0200 /* not-connected socket (dont read it!) */
  53. #define SOCK_BUFFER 0x0400 /* buffer data; don't notify dcc funcs */
  54. /* Flags to sock_has_data
  55. */
  56. enum {
  57. SOCK_DATA_OUTGOING, /* Data in out-queue? */
  58. SOCK_DATA_INCOMING /* Data in in-queue? */
  59. };
  60. #define iptolong(a) (0xffffffff & \
  61. (long) (htonl((unsigned long) a)))
  62. #define CONNECT_SSL 1
  63. #define ACCEPT_SSL 2
  64. #ifdef USE_IPV6
  65. #define SIZEOF_SOCKADDR(so) ((so).sa.sa_family == AF_INET6 ? sizeof(so.sin6) : sizeof(so.sin))
  66. #else
  67. #define SIZEOF_SOCKADDR(so) (sizeof(so.sin))
  68. #endif /* USE_IPV6 */
  69. #if !defined(IN6_IS_ADDR_V4MAPPED)
  70. # define IN6_IS_ADDR_V4MAPPED(a) \
  71. ((((u_int32_t *) (a))[0] == 0) && (((u_int32_t *) (a))[1] == 0) && \
  72. (((u_int32_t *) (a))[2] == htonl (0xffff)))
  73. #endif /* !defined(IN6_IS_ADDR_V4MAPPED) */
  74. union sockaddr_union {
  75. struct sockaddr sa;
  76. struct sockaddr_in sin;
  77. #ifdef USE_IPV6
  78. struct sockaddr_in6 sin6;
  79. #endif /* USE_IPV6 */
  80. };
  81. /* This is used by the net module to keep track of sockets and what's
  82. * queued on them
  83. */
  84. typedef struct {
  85. int sock;
  86. short flags;
  87. char *inbuf;
  88. char *outbuf;
  89. unsigned long outbuflen; /* Outbuf could be binary data */
  90. int encstatus; /* encrypted botlink */
  91. int oseed; /* botlink out seed */
  92. int iseed; /* botlink in seed */
  93. char okey[33]; /* botlink enckey: out */
  94. char ikey[33]; /* botlink enckey: in */
  95. int gz; /* gzip compression */
  96. unsigned long inbuflen; /* Inbuf could be binary data */
  97. #ifdef USE_IPV6
  98. unsigned int af;
  99. #endif /* USE_IPV6 */
  100. #ifdef HAVE_SSL
  101. SSL *ssl;
  102. #endif /* HAVE_SSL */
  103. } sock_list;
  104. # define killsock(x) real_killsock((x),__FILE__,__LINE__)
  105. IP my_atoul(char *);
  106. #ifdef HAVE_SSL
  107. int ssl_cleanup();
  108. #endif /* HAVE_SSL */
  109. int ssl_link(int, int);
  110. char *myipstr(int);
  111. IP getmyip();
  112. void cache_my_ip();
  113. void neterror(char *);
  114. void setsock(int, int);
  115. int allocsock(int, int);
  116. #ifdef USE_IPV6
  117. int getsock(int, int);
  118. #else
  119. int getsock(int);
  120. #endif /* USE_IPV6 */
  121. int sockprotocol(int);
  122. int hostprotocol(char *);
  123. char *hostnamefromip(unsigned long);
  124. void dropssl(int);
  125. void real_killsock(int, const char *, int);
  126. int answer(int, char *, unsigned long *, unsigned short *, int);
  127. int findanyidx(register int);
  128. inline int open_listen(int *);
  129. inline int open_listen_by_af(int *, int);
  130. #ifdef USE_IPV6
  131. int open_address_listen(IP, int, int *);
  132. #else
  133. int open_address_listen(IP, int *);
  134. #endif /* USE_IPV6 */
  135. int open_telnet(char *, int);
  136. int open_telnet_dcc(int, char *, char *);
  137. int open_telnet_raw(int, char *, int);
  138. void tputs(int, char *, unsigned int);
  139. void dequeue_sockets();
  140. int sockgets(char *, int *);
  141. void tell_netdebug(int);
  142. int sanitycheck_dcc(char *, char *, char *, char *);
  143. int hostsanitycheck_dcc(char *, char *, IP, char *, char *);
  144. char *iptostr(IP);
  145. int sock_has_data(int, int);
  146. int sockoptions(int sock, int operation, int sock_options);
  147. int flush_inbuf(int idx);
  148. extern union sockaddr_union cached_myip4_so;
  149. #ifdef USE_IPV6
  150. extern union sockaddr_union cached_myip6_so;
  151. extern unsigned long notalloc;
  152. #endif /* USE_IPV6 */
  153. extern char firewall[], botuser[];
  154. extern int firewallport, resolve_timeout, MAXSOCKS;
  155. extern jmp_buf alarmret;
  156. extern sock_list *socklist;
  157. #endif /* !_NET_H */