ryuko Posted April 19, 2009 Posted April 19, 2009 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 backso if you guys know how to recv data from telnet will you please help !!!
CoffeeFiend Posted April 19, 2009 Posted April 19, 2009 Telnet is very simple, and well documented i.e. RFC854There'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)
ryuko Posted April 19, 2009 Author Posted April 19, 2009 (edited) 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 soserver:: welcome to blahblahserver:: username:client:: login user tryserver:: [check if correct and respond]server:: [if correct] server:: pass:client:: passhereserver:: [checks again]server:: correct login access server:: welcome you logged in correctlyi 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 April 19, 2009 by ryuko
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now