extern InspIRCd* ServerInstance;
extern ServerConfig* Config;
extern time_t TIME;
+extern Server* MyServer;
InspSocket* socket_ref[MAX_DESCRIPTORS];
+
InspSocket::InspSocket()
{
this->state = I_DISCONNECTED;
}
}
-InspSocket::InspSocket(const std::string &ahost, int aport, bool listening, unsigned long maxtime) : fd(-1)
+InspSocket::InspSocket(const std::string &ipaddr, int aport, bool listening, unsigned long maxtime) : fd(-1)
{
- strlcpy(host,ahost.c_str(),MAXBUF);
+ strlcpy(host,ipaddr.c_str(),MAXBUF);
this->ClosePending = false;
if (listening) {
if ((this->fd = OpenTCPSocket()) == ERROR)
}
else
{
- if (!BindSocket(this->fd,this->client,this->server,aport,(char*)ahost.c_str()))
+ if (!BindSocket(this->fd,this->client,this->server,aport,(char*)ipaddr.c_str()))
{
log(DEBUG,"BindSocket() error %s",strerror(errno));
this->Close();
}
else
{
- strlcpy(this->host,ahost.c_str(),MAXBUF);
+ strlcpy(this->host,ipaddr.c_str(),MAXBUF);
this->port = aport;
if (insp_aton(host,&addy) < 1)
{
- log(DEBUG,"Attempting to resolve %s",this->host);
- /* Its not an ip, spawn the resolver */
-
- /* TODO: Implement resolver with new Resolver class */
-
- timeout_end = time(NULL) + maxtime;
- timeout = false;
- this->state = I_RESOLVING;
- socket_ref[this->fd] = this;
+ log(DEBUG,"You cannot pass hostnames to InspSocket, resolve them first with Resolver!");
+ this->Close();
+ this->fd = -1;
+ this->state = I_ERROR;
+ this->OnError(I_ERR_RESOLVE);
+ this->ClosePending = true;
+ return;
}
else
{
setsockopt(nfd,SOL_SOCKET,SO_RCVBUF,(const void *)&recvbuf,sizeof(sendbuf));
}
-bool InspSocket::DoResolve()
-{
- log(DEBUG,"In DoResolve(), trying to resolve IP");
-
- log(DEBUG,"No result for socket yet!");
- return true;
-}
-
/* Most irc servers require you to specify the ip you want to bind to.
* If you dont specify an IP, they rather dumbly bind to the first IP
* of the box (e.g. INADDR_ANY). In InspIRCd, we scan thought the IP
if ((IP != "*") && (IP != "127.0.0.1") && (IP != ""))
{
insp_sockaddr s;
- char resolved_addr[MAXBUF];
-
- if (insp_aton(IP.c_str(),&n) < 1)
- {
- /* If they gave a hostname, bind to the IP it resolves to */
- log(DEBUG,"Resolving host %s",IP.c_str());
- if (CleanAndResolve(resolved_addr, IP.c_str(), true, 1))
- {
- log(DEBUG,"Resolved host %s to %s",IP.c_str(),resolved_addr);
- IP = resolved_addr;
- }
- }
if (insp_aton(IP.c_str(),&n) > 0)
{
return false;
}
- if (!this->BindAddr())
- return false;
+ if ((strstr(this->IP,"::ffff:") != (char*)&this->IP) && (strstr(this->IP,"::FFFF:") != (char*)&this->IP))
+ {
+ if (!this->BindAddr())
+ return false;
+ }
log(DEBUG,"Part 2 DoConnect() %s",this->IP);
insp_aton(this->IP,&addy);
#ifdef IPV6
addr.sin6_family = AF_FAMILY;
- memcpy(&addy, &addr.sin6_addr, sizeof(insp_inaddr));
+ memcpy(&addr.sin6_addr, &addy, sizeof(insp_inaddr));
addr.sin6_port = htons(this->port);
#else
addr.sin_family = AF_FAMILY;
return true;
}
- if (((this->state == I_RESOLVING) || (this->state == I_CONNECTING)) && (current > timeout_end))
+ if ((this->state == I_CONNECTING) && (current > timeout_end))
{
log(DEBUG,"Timed out, current=%lu timeout_end=%lu");
// for non-listening sockets, the timeout can occur
switch (this->state)
{
- case I_RESOLVING:
- log(DEBUG,"State = I_RESOLVING, calling DoResolve()");
- return this->DoResolve();
- break;
case I_CONNECTING:
log(DEBUG,"State = I_CONNECTING");
this->SetState(I_CONNECTED);