#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/utsname.h>
-#include <errno.h>
-#include <vector>
#include "inspircd.h"
#include "modules.h"
extern int MODCOUNT;
-#define STATE_CLEAR 1
-#define STATE_WAIT_FOR_ACK 2
-
packet::packet()
{
srand(time(NULL));
{
key = GenKey();
fd = 0;
- state = STATE_CLEAR;
- buffer.clear();
}
this->port = p;
- setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,(const char*)&on,sizeof(on));
- linger.l_onoff = 1;
- linger.l_linger = 0;
- setsockopt(fd,SOL_SOCKET,SO_LINGER,(const char*)&linger,sizeof(linger));
+ setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,(const char*)&on,sizeof(on));
+ linger.l_onoff = 1;
+ linger.l_linger = 0;
+ setsockopt(fd,SOL_SOCKET,SO_LINGER,(const char*)&linger,sizeof(linger));
- buffer.clear();
-
return true;
}
+
bool connection::BeginLink(char* targethost, int port, char* password)
{
char connect[MAXBUF];
// returns false if the packet could not be sent (e.g. target host down)
if (sendto(this->fd,&p,sizeof(p),0,(sockaddr*)&host_address,sizeof(host_address))<0)
{
- log(DEBUG,"sendto() failed for Connection::SendPacket() with a packet of size %d: %s",sizeof(p),strerror(errno));
+ log(DEBUG,"sendto() failed for Connection::SendPacket() with a packet of size %d",sizeof(p));
return false;
}
-
- this->state = STATE_CLEAR;
return true;
+
}
bool connection::SendSYN(char* host, int port)
{
return false;
}
+ return true;
}
host_address.sin_family=AF_INET;
host_address_size=sizeof(host_address);
- //int recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen);
if (recvfrom(fd,&p,sizeof(p),0,(sockaddr*)&host_address,&host_address_size)<0)
{
return false;
}
- log(DEBUG,"connection::RecvPacket(): received packet type %d '%s' from '%s'",p.type,p.data,inet_ntoa(host_address.sin_addr));
+ log(DEBUG,"connection::RecvPacket(): received packet type %d '%s'",p.type,p.data);
if (p.type == PT_SYN_ONLY)
{
strcpy(message,p.data);
strcpy(host,inet_ntoa(host_address.sin_addr));
prt = ntohs(host_address.sin_port);
- this->state = STATE_CLEAR;
return false;
}
strcpy(message,p.data);
strcpy(host,inet_ntoa(host_address.sin_addr));
theirkey = p.key;
- prt = ntohs(host_address.sin_port); // the port we received it on
- SendACK(host,prt,p.id);
+ prt = ntohs(host_address.sin_port);
+ SendACK(host,this->port,p.id);
return true;
}