| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- #ifndef _NET_H
- #define _NET_H
- #ifdef HAVE_CONFIG_H
- # include "config.h"
- #endif
- #include "types.h"
- #include <netinet/in.h>
- #include <sys/socket.h>
- #include <setjmp.h>
- #ifdef HAVE_OPENSSL_SSL_H
- # ifdef USE_SSL
- # include <openssl/ssl.h>
- # include <openssl/rand.h>
- # include <openssl/err.h>
- # undef HAVE_SSL
- # endif /* USE_SSL */
- /* #define HAVE_SSL 1 */
- #endif /* HAVE_OPENSSL_SSL_H */
- /*
- * Enable IPv6 debugging?
- */
- #define DEBUG_IPV6 1
- #define HAVE_IPV6 1
- /* IPv6 sanity checks. */
- #ifdef USE_IPV6
- # ifndef HAVE_IPV6
- # undef USE_IPV6
- # endif
- # ifndef HAVE_GETHOSTBYNAME2
- # ifndef HAVE_GETIPNODEBYNAME
- # undef USE_IPV6
- # endif
- # endif
- #endif
- #define SGRAB 2010 /* How much data to allow through sockets. */
- enum {
- EGG_OPTION_SET = 1, /* Set option(s). */
- EGG_OPTION_UNSET = 2 /* Unset option(s). */
- };
- /* Socket flags:
- */
- #define SOCK_UNUSED BIT0 /* empty socket */
- #define SOCK_BINARY BIT1 /* do not buffer input */
- #define SOCK_LISTEN BIT2 /* listening port */
- #define SOCK_CONNECT BIT3 /* connection attempt */
- #define SOCK_NONSOCK BIT4 /* used for file i/o on debug */
- #define SOCK_STRONGCONN BIT5 /* don't report success until sure */
- #define SOCK_EOFD BIT6 /* it EOF'd recently during a write */
- #define SOCK_PROXYWAIT BIT7 /* waiting for SOCKS traversal */
- #define SOCK_PASS BIT8 /* passed on; only notify in case of traffic */
- #define SOCK_VIRTUAL BIT9 /* not-connected socket (dont read it!) */
- #define SOCK_BUFFER BIT10 /* buffer data; don't notify dcc funcs */
- /* Flags to sock_has_data
- */
- enum {
- SOCK_DATA_OUTGOING, /* Data in out-queue? */
- SOCK_DATA_INCOMING /* Data in in-queue? */
- };
- #define iptolong(a) (0xffffffff & \
- (long) (htonl((unsigned long) a)))
- #define CONNECT_SSL 1
- #define ACCEPT_SSL 2
- #ifdef USE_IPV6
- #define SIZEOF_SOCKADDR(so) ((so).sa.sa_family == AF_INET6 ? sizeof(so.sin6) : sizeof(so.sin))
- #else
- #define SIZEOF_SOCKADDR(so) (sizeof(so.sin))
- #endif /* USE_IPV6 */
- #if !defined(IN6_IS_ADDR_V4MAPPED)
- # define IN6_IS_ADDR_V4MAPPED(a) \
- ((((u_int32_t *) (a))[0] == 0) && (((u_int32_t *) (a))[1] == 0) && \
- (((u_int32_t *) (a))[2] == htonl (0xffff)))
- #endif /* !defined(IN6_IS_ADDR_V4MAPPED) */
- union sockaddr_union {
- struct sockaddr sa;
- struct sockaddr_in sin;
- #ifdef USE_IPV6
- struct sockaddr_in6 sin6;
- #endif /* USE_IPV6 */
- };
- /* This is used by the net module to keep track of sockets and what's
- * queued on them
- */
- typedef struct {
- size_t outbuflen; /* Outbuf could be binary data */
- size_t inbuflen; /* Inbuf could be binary data */
- #ifdef USE_IPV6
- unsigned int af;
- #endif /* USE_IPV6 */
- int encstatus; /* encrypted botlink */
- int oseed; /* botlink out seed */
- int iseed; /* botlink in seed */
- int sock;
- int gz; /* gzip compression */
- #ifdef HAVE_SSL
- SSL *ssl;
- #endif /* HAVE_SSL */
- char *inbuf;
- char *outbuf;
- char *host;
- port_t port;
- short flags;
- char okey[33]; /* botlink enckey: out */
- char ikey[33]; /* botlink enckey: in */
- } sock_list;
- # define killsock(x) real_killsock((x),__FILE__,__LINE__)
- unsigned long my_atoul(char *);
- #ifdef HAVE_SSL
- int ssl_cleanup();
- int ssl_link(int, int);
- #endif /* HAVE_SSL */
- char *myipstr(int);
- IP getmyip();
- void cache_my_ip();
- void setsock(int, int);
- int allocsock(int, int);
- #ifdef USE_IPV6
- #define getsock(opt, af) real_getsock(opt, af, __FILE__, __LINE__)
- int real_getsock(int, int, char *, int);
- #else
- #define getsock(opt) real_getsock(opt, __FILE__, __LINE__)
- int real_getsock(int, char *, int);
- #endif /* USE_IPV6 */
- int sockprotocol(int);
- int hostprotocol(char *);
- char *hostnamefromip(IP);
- void real_killsock(int, const char *, int);
- int answer(int, char *, IP *, port_t *, int);
- int findanyidx(register int);
- int open_listen(port_t *);
- int open_listen_by_af(port_t *, int);
- #ifdef USE_IPV6
- int open_address_listen(IP, int, port_t *);
- #else
- int open_address_listen(IP, port_t *);
- #endif /* USE_IPV6 */
- int open_telnet(char *, port_t);
- int open_telnet_dcc(int, char *, char *);
- int open_telnet_raw(int, char *, port_t);
- void tputs(int, char *, size_t);
- void dequeue_sockets();
- int sockgets(char *, int *);
- void tell_netdebug(int);
- char *iptostr(IP);
- int sock_has_data(int, int);
- int sockoptions(int sock, int operation, int sock_options);
- int flush_inbuf(int idx);
- extern union sockaddr_union cached_myip4_so;
- #ifdef USE_IPV6
- extern union sockaddr_union cached_myip6_so;
- extern unsigned long notalloc;
- #endif /* USE_IPV6 */
- extern char firewall[], botuser[];
- extern int resolve_timeout, MAXSOCKS, identd_hack;
- extern port_t firewallport;
- extern jmp_buf alarmret;
- extern sock_list *socklist;
- #endif /* !_NET_H */
|