#include <cerrno>
#include <csignal>
-#include <cstdio> // snprintf
#include <cstring> // strerror
#include <unistd.h> // close
//-----------------------------------------------------------------------------
int CONFIGPROTO::Prepare()
{
-int res;
-struct sockaddr_in listenAddr;
-
sigset_t sigmask, oldmask;
sigemptyset(&sigmask);
sigaddset(&sigmask, SIGINT);
if (listenSocket < 0)
{
- errorStr = "Create NET_CONFIGURATOR socket failed.";
+ errorStr = "Create socket failed.";
logger("Cannot create a socket: %s", strerror(errno));
return -1;
}
+struct sockaddr_in listenAddr;
listenAddr.sin_family = PF_INET;
listenAddr.sin_port = htons(port);
listenAddr.sin_addr.s_addr = inet_addr("0.0.0.0");
return -1;
}
-res = bind(listenSocket, (struct sockaddr*)&listenAddr, sizeof(listenAddr));
-
-if (res == -1)
+if (bind(listenSocket, (struct sockaddr*)&listenAddr, sizeof(listenAddr)) == -1)
{
errorStr = "Bind admin socket failed";
logger("Cannot bind the socket: %s", strerror(errno));
return -1;
}
-res = listen(listenSocket, 0);
-if (res == -1)
+if (listen(listenSocket, 0) == -1)
{
errorStr = "Listen admin socket failed";
logger("Cannot listen the socket: %s", strerror(errno));
int CONFIGPROTO::Stop()
{
nonstop = false;
+shutdown(listenSocket, SHUT_RDWR);
close(listenSocket);
//TODO: Idiotism
-int sock;
struct sockaddr_in addr;
-socklen_t addrLen;
addr.sin_family = PF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
-addrLen = sizeof(addr);
-sock = socket(PF_INET, SOCK_STREAM, 0);
+socklen_t addrLen = sizeof(addr);
+int sock = socket(PF_INET, SOCK_STREAM, 0);
connect(sock, (sockaddr*)&addr, addrLen);
+shutdown(sock, SHUT_RDWR);
close(sock);
//Idiotism end
return 0;
//-----------------------------------------------------------------------------
void CONFIGPROTO::Run()
{
-state = confHdr;
-
while (nonstop)
{
state = confHdr;
{
if (RecvHdr(outerSocket) < 0)
{
+ shutdown(outerSocket, SHUT_RDWR);
close(outerSocket);
continue;
}
{
if (SendHdrAnswer(outerSocket, ans_ok) < 0)
{
+ shutdown(outerSocket, SHUT_RDWR);
close(outerSocket);
continue;
}
if (RecvLogin(outerSocket) < 0)
{
+ shutdown(outerSocket, SHUT_RDWR);
close(outerSocket);
continue;
}
{
if (SendLoginAnswer(outerSocket) < 0)
{
+ shutdown(outerSocket, SHUT_RDWR);
close(outerSocket);
continue;
}
if (RecvLoginS(outerSocket) < 0)
{
+ shutdown(outerSocket, SHUT_RDWR);
close(outerSocket);
continue;
}
{
if (SendLoginSAnswer(outerSocket, ans_ok) < 0)
{
+ shutdown(outerSocket, SHUT_RDWR);
close(outerSocket);
continue;
}
if (RecvData(outerSocket) < 0)
{
+ shutdown(outerSocket, SHUT_RDWR);
close(outerSocket);
continue;
}
{
if (SendLoginSAnswer(outerSocket, ans_err) < 0)
{
+ shutdown(outerSocket, SHUT_RDWR);
close(outerSocket);
continue;
}
WriteLogAccessFailed(adminIP);
if (SendHdrAnswer(outerSocket, ans_err) < 0)
{
+ shutdown(outerSocket, SHUT_RDWR);
close(outerSocket);
continue;
}
WriteLogAccessFailed(adminIP);
}
printfd(__FILE__, "Successfull connection from %s\n", inet_ntostring(outerAddr.sin_addr.s_addr).c_str());
+ shutdown(outerSocket, SHUT_RDWR);
close(outerSocket);
}
}