|
Suddenly I want to make something that can be connected to telnet and play. But I found that telnet connection is no problem. But the control data sent by telnet has not been understood. That is, the NVT format (I understand it this way). The first few characters returned by telnet were control characters in NVT format. However, the content of these control characters has not been understood. There is no such thing as NVT specifications on the Internet.
#include <stdlib.h>
#include <stdio.h>
#include <WINSOCK2.H>
#include <process.h>
void main ()
{
SOCKET test;
int a = 0;
char buff [1024];
char orda [10];
WORD wVersion = MAKEWORD (2,0); // Define version
struct sockaddr_in ip_addr; // IP address
char addr [32] = "192.168.1.1"; // The entered IP address
WSADATA wsData;
Ranch
int nResult = WSAStartup (wVersion,&wsData);
memset (buff, 0, sizeof (buff));
memset (orda, 0, sizeof (orda));
// memset (addr, 0,32);
if (nResult! = 0)
{
printf ("WINSOCK EEROR\n");
system ("pause");
}
// printf ("Enter IP address:");
// gets (addr); // Enter the target machine address
// printf ("\n");
test = socket (AF_INET, SOCK_STREAM, 0); // Create a socket
if (test == INVALID_SOCKET)
{
exit (0);
}
ip_addr.sin_family = AF_INET;
ip_addr.sin_port = htons (23); // Port
ip_addr.sin_addr.S_un.S_addr = inet_addr (addr); // Address format conversion, connection address
a = connect (test, (struct sockaddr *)&ip_addr, sizeof (struct sockaddr_in)); // connect the target address
a = WSAGetLastError ();
if (0! = a)
{
printf ("Connection error!\n");
exit (0);
}
do
{
a = recv (test, buff, sizeof (buff), 0);
printf ("% s", buff);
memset (buff, 0, sizeof (buff));
gets (orda);
* (orda + strlen (orda)) = 13;
send (test, orda, strlen (orda) + 1, MSG_DONTROUTE);
memset (orda, 0, sizeof (orda));
memset (buff, 0, sizeof (buff));
Ranch
} while (1);
}
In this way, you can connect. You can also receive data. But the control characters in front of the data have not been understood. If you connect to it, telnet will immediately send back ff fd 01 ff fd 21 ff fb 03 |
|