diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2004-04-01 20:21:06 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2004-04-01 20:21:06 +0000 |
commit | 0ae832406f989194761528a1b8d49aa115c7fb3b (patch) | |
tree | 9cab633f2546a86e687fdefda75ab1bc24c17be3 /src/connection.cpp | |
parent | 62d4c43612c617eafd1a11fdf7d1778b64682812 (diff) |
Fixed <link> tags
Stability fixes/bounds checks
UDP tunneling working for server->server
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@350 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/connection.cpp')
-rw-r--r-- | src/connection.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/connection.cpp b/src/connection.cpp index 33eb405ad..eb0af9833 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -86,8 +86,7 @@ bool connection::BeginLink(char* targethost, int port, char* password) { sprintf(connect,"S %s %s :%s",getservername().c_str(),password,getserverdesc().c_str()); this->haspassed = false; - this->SendPacket(connect, targethost, port); - return true; + return this->SendPacket(connect, targethost, port, 0); } return false; } @@ -99,7 +98,7 @@ void connection::TerminateLink(char* targethost) // host: in dot notation a.b.c.d // port: host byte order -bool connection::SendPacket(char *message, char* host, int port) +bool connection::SendPacket(char *message, char* host, int port, long ourkey) { sockaddr_in host_address; in_addr addy; @@ -115,14 +114,17 @@ bool connection::SendPacket(char *message, char* host, int port) strcpy(p.data,message); p.type = PT_SYN_WITH_DATA; - p.key = key; + p.key = ourkey; + + FOREACH_MOD OnPacketTransmit(p.data); - FOREACH_MOD OnPacketTransmit(p.data); + log(DEBUG,"main: Connection::SendPacket() sent '%s' to %s:%d",p.data,host,port); // returns false if the packet could not be sent (e.g. target host down) - if (sendto(fd,&p,sizeof(p),0,(sockaddr*)&host_address,sizeof(host_address))<0) + 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",sizeof(p)); return false; } return true; @@ -213,7 +215,7 @@ long connection::GenKey() // host: in dot notation a.b.c.d // port: host byte order -bool connection::RecvPacket(char *message, char* host, int &prt) +bool connection::RecvPacket(char *message, char* host, int &prt, long &theirkey) { // returns false if no packet waiting for receive, e.g. EAGAIN or ECONNRESET sockaddr_in host_address; @@ -230,6 +232,8 @@ bool connection::RecvPacket(char *message, char* host, int &prt) return false; } + log(DEBUG,"connection::RecvPacket(): received packet type %d '%s'",p.type,p.data); + if (p.type == PT_SYN_ONLY) { strcpy(message,p.data); @@ -251,10 +255,13 @@ bool connection::RecvPacket(char *message, char* host, int &prt) { strcpy(message,p.data); strcpy(host,inet_ntoa(host_address.sin_addr)); + theirkey = p.key; prt = ntohs(host_address.sin_port); SendACK(host,this->port,p.id); + return true; } + log(DEBUG,"connection::RecvPacket(): Invalid packet type %d (protocol error)",p.type); return true; } |