I'm having a strange problem with telnet prompt lines not printing in this program I've written. The data from the server are received and seem to be in the output buffer, but they won't print unless a newline is appended or something else is printed afterwards.
Program output:
Code:
DEBUG - RAW: 57 65 6c 63 6f 6d 65 20 74 6f 20 4d 69 63 72 6f 73 6f 66 74 20 54 65 6c 6e 65 74 20 53 65 72 76 69 63 65 20
d a
Welcome to Microsoft Telnet Service
DEBUG - RAW: a d 6c 6f 67 69 6e 3a 20
The last data received reads "\n\rlogin: ", and it's what's not printing out. I'm wondering if it has something to do with the oddly ordered \n \r pair? I've tried parsing out the carriage returns just in case the problem had something to do with that, but to no effect. On the off chance that it's relevant, I'm compiling and running the program in Cygwin.
Printing functions:
Code:
int Telnet::read_data()
{
memset(szRaw, 0, sizeof(char)*bufsize);
int cLen = recv(hSock, szRaw, bufsize, 0);
if(cLen == -1)
{
char msg[512];
sprintf(msg, "Recv error: %s\nMsg: %s\n", strerror( errno ), szRaw);
throw TelnetError(msg);
}
else if(cLen == 0)
throw TelnetError("Connection closed.");
#ifdef debug
printf("\nDEBUG - RAW: ");
for(int i=0;i<cLen;i++)
printf("%x ", szRaw[i]);
printf("\n");
#endif
process_data(cLen);
printf("%s", szProcessed);
return cLen;
}
void Telnet::process_data(size_t cLen)
{
char *pB = szProcessed;
memset(szProcessed, 0, sizeof(char)* bufsize);
unsigned char cmd = 0, opt = 0;
for(int i = 0; i < cLen; i++)
{
if(szRaw[i]!=IAC)
{
*pB++=szRaw[i];
continue;
}
i++;
cmd = szRaw[i];
switch(cmd)
{
case WILL:
case WONT:
case DO:
case DONT:
i++;
opt = szRaw[i];
/* Call callback function associated with command*/
CallCbf(cmd, opt);
break;
case SB:
i++;
opt = szRaw[i];
//CallCbf(cmd, opt);
while(szRaw[i]!=SE) i++;
break;
default:
CallCbf(cmd, 0);
break;
}
}
}