+/* +------------------------------------+
+ * | Inspire Internet Relay Chat Daemon |
+ * +------------------------------------+
+ *
+ * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ * E-mail:
+ * <brain@chatspike.net>
+ * <Craig@chatspike.net>
+ *
+ * Written by Craig Edwards, Craig McLure, and others.
+ * This program is free but copyrighted software; see
+ * the file COPYING for details.
+ *
+ * ---------------------------------------------------
+ */
+
#include <connection.h>
#include <unistd.h>
#include <fcntl.h>
#include <deque>
#include "inspircd.h"
#include "modules.h"
+#include "inspstring.h"
using namespace std;
extern int MODCOUNT;
-
+extern time_t TIME;
connection::connection()
{
setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,(const char*)&on,sizeof(on));
linger.l_onoff = 1;
- linger.l_linger = 0;
+ linger.l_linger = 1;
setsockopt(fd,SOL_SOCKET,SO_LINGER,(const char*)&linger,sizeof(linger));
// attempt to increase socket sendq and recvq as high as its possible
// targethost has been turned into an ip...
// we dont want this as the server name.
connector.SetServerName(servername);
- sprintf(connect,"S %s %s %d %d :%s",getservername().c_str(),password,myport,GetRevision(),getserverdesc().c_str());
+ snprintf(connect,MAXBUF,"S %s %s %d %d :%s",getservername().c_str(),password,myport,GetRevision(),getserverdesc().c_str());
connector.SetState(STATE_NOAUTH_OUTBOUND);
connector.SetHostAndPort(targethost, port);
this->connectors.push_back(connector);
// targethost has been turned into an ip...
// we dont want this as the server name.
connector.SetServerName(servername);
- sprintf(connect,"- %d %s :%s",cookie,getservername().c_str(),getserverdesc().c_str());
+ snprintf(connect,MAXBUF,"- %d %s :%s",cookie,getservername().c_str(),getserverdesc().c_str());
connector.SetState(STATE_NOAUTH_OUTBOUND);
connector.SetHostAndPort(targethost, port);
connector.SetState(STATE_CONNECTED);
if (!strchr(message,'\n'))
{
- strncat(message,"\n",MAXBUF);
+ strlcat(message,"\n",MAXBUF);
}
if (cn)
{
log(DEBUG,"Main route to %s is down, seeking alternative",host);
// fix: can only route one hop to avoid a loop
- if (strncat(message,"R ",2))
+ if (strlcat(message,"R ",2))
{
// this route is down, we must re-route the packet through an available point in the mesh.
for (int k = 0; k < this->connectors.size(); k++)
if (strlen(sanitized))
{
messages.push_back(sanitized);
- strncpy(host,this->connectors[i].GetServerName().c_str(),160);
+ strlcpy(host,this->connectors[i].GetServerName().c_str(),160);
log(DEBUG,"main: Connection::RecvPacket() got '%s' from %s",sanitized,host);
}
long connection::GenKey()
{
- srand(time(NULL));
return (random()*time(NULL));
}