net.h 4.6 KB

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