#include "CmdLineOptions.hpp" #include "Thread.hpp" #include "GnuStr.hpp" #include #include #include #include #include #include #include #include classConnectionThread : public Thread{ public: ConnectionThread(int csd){ clientsd = csd; } ~ConnectionThread(void){} virtual void Run( void ); private: int clientsd; int serversd; }; class ConfThread : public Thread{ public: ConfThread(int sd){ confsd = sd;} ~ConfThread(void){} virtual void Run(void); private: int confsd; }; int ConnectToServer( void); void DoMsg( int sock); int SetupServerSock(int port); void DoMainLoop(int server, int confserver); void HandleServerConfig(GnuStr& param); void HandlePortConfig(GnuStr& param); void HandleLogClientConfig(GnuStr& param); void HandleLogServerConfig(GnuStr& param); //Global structure that stores command line parameters struct Params{ GnuStr server; int port; int stage; int localport; bool logclient; bool logserver; }; Params params; CmdLineOptions opts[] = { { "server = s", 0, ¶ms.server, "--server=s The host the server application runs on"}, { "port = i", 0, ¶ms.port, "--port=i The port of server application listens on"}, { "stage = i", 0, ¶ms.stage, "--stage=i Defines implementation stage of project"}, { "local = i", 0, ¶ms.localport, "--local=i The port to listen for requests for clients" }, { "logclient = b", 0, ¶ms.logclient, "--logclient=b copy information sent from client to stdout" }, { "logserver = b", 0, ¶ms.logserver, "--logserver=b copy information sent from server to stdout" }, { "confport = i", 0, ¶ms.confport, "---confport=i The port to change eavesdropper configuration" }, { 0, 0, 0, 0} }; int main(int argc, char** argv){ params.server = "rohan"; params.server = 9999; params.server = 2; params.localport = 9090; params.logclient = false; params.logserver = false; ReadCmdLineOptions(argc, argv, opts); cout<<"Options: "<StartDetached(); } else if (FD_ISSET( confserver, &readfds ) ) { length = sizeof(sin); int client = accept(confserver, (sockaddr*) &sin, &length); if ( client <= 0 ){ cerr<<"Accept call failed...ignoring."<StartDetached(); } } } int ConnectToServer(void){ NetAddress addr; addr.SetAddress( params.server, params.port ); int sock = socket( PF_INET, SOCK_STREAM, 0 ); if( sock == -1 ){ cerr<<"Socket call failed." << endl; perror("socket"); exit(-1); } sockaddr_in sin = addr; int retval = connect( sock, (sockaddr*)&sin, sizeof(sin)); if( retval < 0 ){ cerr<<"Could not connect to server: "<