Jump to content

c++ telnet server


Recommended Posts

Ok i am trying to make a telnet server, i hav started in using winsock2 in c++ this is my code

#include <winsock2.h>
#include <conio.h>
#include <iostream>


using namespace std;

UINT ServerThread(LPVOID);

int main(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

cout << "Press ESCAPE to terminate program\r\n";
switch (ServerThread(0)) {
case 1:
cout << "WSAStartup failed!" << endl;
nRetCode = 2;
case 2:
cout << "INVALID_PORT thrown." << endl;
nRetCode = 2;
case 3:
cout << "Cannot Bind to Socket." << endl;
nRetCode = 2;
case 4:
cout << "Can't start Listener." << endl;
nRetCode = 2;
}
return nRetCode;
}

UINT ServerThread(LPVOID pParam)
{
cout << "Starting up TCP server\r\n";


SOCKET server;


WSADATA wsaData;


sockaddr_in local;


int wsaret=WSAStartup(0x101,&wsaData);


if(wsaret!=0)
{
return 1;
}


local.sin_family=AF_INET;
local.sin_addr.s_addr=INADDR_ANY;
local.sin_port=htons((u_short)3000);


server=socket(AF_INET,SOCK_STREAM,0);


if(server==INVALID_SOCKET)
{
return 2;
}


if(bind(server,(sockaddr*)&local,sizeof(local))!=0)
{
return 3;
}


if(listen(server,10)!=0)
{
return 4;
}


SOCKET client;
sockaddr_in from;
int fromlen=sizeof(from);

while(true)
{
char temp[512];


client=accept(server,
(struct sockaddr*)&from,&fromlen);

sprintf(temp,"welcome to my console\n");



send(client,temp,strlen(temp),0);
cout << "Connection from " << inet_ntoa(from.sin_addr) <<"\r\n";
cout << "connection opened";



}


cout << "closing socket";
closesocket(server);


WSACleanup();

return 0;
}

simply what i want to do is be able to ask for a user and password and if it passes be able to have the client send text to the server for processing and sending responses back

so if you guys know how to recv data from telnet will you please help !!!

Link to comment
Share on other sites


Telnet is very simple, and well documented i.e. RFC854

There's TONS of sample code out there doing exactly this as well a many complete apps that do just this, a search should turns up tons of results (tons more places to search e.g. sourceforge).

People have been moving away from telnet in the past few years because of the inherent lack of security (login/password sent in plain text -- much like ftp). It still gets used as it's one of those "lowest common denominator" protocols (well supported on any platform)

Link to comment
Share on other sites

idc what langauge its written in or if its a premade script if i cant get this working idc but all i really need right now is a script that allows telnet logon and itdisplayas a welcome message like so

server:: welcome to blahblah

server:: username:

client:: login user try

server:: [check if correct and respond]

server:: [if correct]

server:: pass:

client:: passhere

server:: [checks again]

server:: correct login access

server:: welcome you logged in correctly

i must not be getting something i tryed using this but it jsut displays "-1"

	char *msg = temp;
int len, bytes_sent;
len = strlen(msg);
bytes_sent = send(server, msg, len, 0);

cout << bytes_sent;

Edited by ryuko
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...