Good Day!!
I am creating a program to send and receive input from a telnet session in C/C++.
I create the pipes, can send and receive and look for an "ack" string and "nak" string ok.
Now I want to look for multiple naks strings coming in from the input pipe. Any suggestions ??
Here is my function to send and receive one
ack and one nak string. I want to expand the nak to more that one nak string.
Thanks and have a great day
I am creating a program to send and receive input from a telnet session in C/C++.
I create the pipes, can send and receive and look for an "ack" string and "nak" string ok.
Now I want to look for multiple naks strings coming in from the input pipe. Any suggestions ??
Here is my function to send and receive one
ack and one nak string. I want to expand the nak to more that one nak string.
Code:
int SendReceive(const char *cmd, const char *ack, const char *nak, int timeout, int printonly)
{
int ai, ni, r;
char c;
char cmd1[MAXINPUT];
r = 0;
if (cmd && strlen(cmd))
{
if (printonly)
{
if (cmd[0] == '\020')
cout << "^P" << cmd + 1; // NB: true ^P turns on printing on DOS
else cout << cmd;
return -1;
}cout << cmd << endl; //Uncomment this line to see traffic
write(fdwr, cmd, strlen(cmd)); // June 07,2004
}
if (ack != NULL)
{
alarm(timeout);
alarmed = 0;
ai = 0;
ni = 0;
while (!alarmed)
{
if (read(fdrd, &c, 1) < 0)
{
if (errno == EINTR) continue;
if (errno == EAGAIN) continue;
break;
}
if (ack[ai] == c) ai++;
else ai = 0;
if (ack[ai] == '\0')
{
r = -1;
break;
}
if (nak)
{
if (nak[ni] == c) ni++;
else ni = 0;
if (nak[ni] == '\0'){cout << "break2" << endl; break;}
}
}
if (alarmed)
syslog(LOG_INFO, "Timeout while waiting for command response.");
else if (nak && nak[ni] == '\0')
syslog(LOG_INFO, "Negative command response.");
else if (!r)
syslog(LOG_INFO, "Unspecified error while waiting for command response.");
unalarm();
}
else r = -1;
return r;
}
Thanks and have a great day