void ArrangeReply(char *strOption,char* m_strResp)
{
//::MessageBox(NULL,"ArrangeReply1","",MB_OK);
unsigned char Verb;
unsigned char Option;
unsigned char Modifier;
unsigned char ch;
BOOL bDefined = FALSE;
int unsignedsites = 0;
Verb=strOption[1];
Option=strOption[2];
switch(Option)
{
case 1: // Echo
case 3: // Suppress Go-Ahead
bDefined = TRUE;
break;
}
m_strResp[unsignedsites]=IAC;
unsignedsites+=1;
if(bDefined == TRUE)
{
switch(Verb)
{
case DO:
ch = WILL;
m_strResp[unsignedsites]= ch;
unsignedsites+=1;
m_strResp[unsignedsites]= Option;
unsignedsites+=1;
break;
case DONT:
ch = WONT;
m_strResp[unsignedsites]= ch;
unsignedsites+=1;
m_strResp[unsignedsites]= Option;
unsignedsites+=1;
break;
case WILL:
ch = DO;
m_strResp[unsignedsites]= ch;
unsignedsites+=1;
m_strResp[unsignedsites]= Option;
unsignedsites+=1;
break;
case WONT:
ch = DONT;
m_strResp[unsignedsites]= ch;
unsignedsites+=1;
m_strResp[unsignedsites]= Option;
unsignedsites+=1;
break;
case SB:
Modifier = strOption[3];
if(Modifier == SEND)
{
ch = SB;
m_strResp[unsignedsites]= ch;
unsignedsites+=1;
m_strResp[unsignedsites]= Option;
unsignedsites+=1;
m_strResp[unsignedsites]= IS;
unsignedsites+=1;
m_strResp[unsignedsites]= IAC;
unsignedsites+=1;
m_strResp[unsignedsites]= SE;
unsignedsites+=1;
}
break;
}
}
else
{
switch(Verb)
{
case DO:
ch = WONT;
m_strResp[unsignedsites]= ch;
unsignedsites+=1;
m_strResp[unsignedsites]= Option;
unsignedsites+=1;
break;
case DONT:
ch = WONT;
m_strResp[unsignedsites]= ch;
unsignedsites+=1;
m_strResp[unsignedsites]= Option;
unsignedsites+=1;
break;
case WILL:
ch = DONT;
m_strResp[unsignedsites]= ch;
unsignedsites+=1;
m_strResp[unsignedsites]= Option;
unsignedsites+=1;
break;
case WONT:
ch = DONT;
m_strResp[unsignedsites]= ch;
unsignedsites+=1;
m_strResp[unsignedsites]= Option;
unsignedsites+=1;
break;
}
}
// ::MessageBox(NULL,"ArrangeReply2","",MB_OK);
}
void CloseTelnet(SOCKET *s)
{
if(*s != INVALID_SOCKET)
{
int mark=closesocket(*s);
if (mark==SOCKET_ERROR)
{
return ;
}
WSACleanup();
*s = INVALID_SOCKET;
return ;
}
}
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define BUFSIZE 1024
#define BUFSIZE1 2048
//telnet特殊标址
const unsigned char IAC = 255;
const unsigned char DO = 253;
const unsigned char DONT = 254;
const unsigned char WILL = 251;
const unsigned char WONT = 252;
const unsigned char SB = 250;
const unsigned char SE = 240;
const unsigned char IS = '0';
const unsigned char SEND = '1';
const unsigned char INFO = '2';
const unsigned char VAR = '0';
const unsigned char VALUE = '1';
const unsigned char ESC = '2';
const unsigned char USERVAR = '3';
看看上面代吗,大家帮帮我,要死了