2003-01-26 23:53:03 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2003-02-02 16:43:53 +00:00
|
|
|
#include "inspircd_config.h"
|
2003-01-26 23:53:03 +00:00
|
|
|
#include "base.h"
|
|
|
|
#include <string>
|
2003-07-22 21:56:38 +00:00
|
|
|
#include <map>
|
2003-02-02 16:43:53 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#ifndef __CONNECTION_H__
|
|
|
|
#define __CONNECTION_H__
|
|
|
|
|
|
|
|
#define PT_SYN_ONLY 0
|
|
|
|
#define PT_ACK_ONLY 1
|
|
|
|
#define PT_SYN_WITH_DATA 2
|
2004-04-01 20:21:06 +00:00
|
|
|
#define PT_KEY_EXCHANGE 3
|
2003-02-02 16:43:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
class packet : public classbase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
long key;
|
|
|
|
short int id;
|
|
|
|
short int type;
|
|
|
|
char data[MAXBUF];
|
|
|
|
|
|
|
|
packet();
|
|
|
|
~packet();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-01-26 23:53:03 +00:00
|
|
|
class connection : public classbase
|
|
|
|
{
|
|
|
|
public:
|
2003-02-02 16:43:53 +00:00
|
|
|
long key;
|
2003-01-26 23:53:03 +00:00
|
|
|
int fd; // file descriptor
|
|
|
|
char host[256]; // hostname
|
|
|
|
long ip; // ipv4 address
|
|
|
|
char inbuf[MAXBUF]; // recvQ
|
|
|
|
long bytes_in;
|
|
|
|
long bytes_out;
|
|
|
|
long cmds_in;
|
|
|
|
long cmds_out;
|
|
|
|
bool haspassed;
|
|
|
|
int port;
|
|
|
|
int registered;
|
|
|
|
time_t lastping;
|
|
|
|
time_t signon;
|
|
|
|
time_t idle_lastmsg;
|
|
|
|
time_t nping;
|
2004-04-01 20:21:06 +00:00
|
|
|
char internal_addr[1024];
|
2003-02-02 16:43:53 +00:00
|
|
|
|
|
|
|
connection();
|
2003-02-07 21:15:27 +00:00
|
|
|
bool CreateListener(char* host, int p);
|
2003-02-02 16:43:53 +00:00
|
|
|
bool BeginLink(char* targethost, int port, char* password);
|
|
|
|
void TerminateLink(char* targethost);
|
2004-04-01 20:21:06 +00:00
|
|
|
bool SendPacket(char *message, char* host, int port, long ourkey);
|
|
|
|
bool RecvPacket(char *message, char* host, int &prt, long &theirkey);
|
2003-02-02 16:43:53 +00:00
|
|
|
bool SendSYN(char* host, int port);
|
|
|
|
bool SendACK(char* host, int port, int reply_id);
|
|
|
|
long GenKey();
|
2003-01-26 23:53:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|