int main(int argc, char *argv[]) { int retcode; LOG_TRACE(LOG_INFORMATIONAL, "\nServer started. Is now initializing the setup...\n"); signal(SIGINT, my_handler); LOG_TRACE(LOG_INFORMATIONAL, "Setting up the valid arguments..."); setValidServerArguments(); //setting up all valid arguments LOG_TRACE(LOG_INFORMATIONAL, "... Done\n"); retcode = setup_shm(); handle_error(retcode, "Shared Memory could not be created.\n", PROCESS_EXIT); char *shm_start = shmat(shm_id, NULL, 0); LOG_TRACE(LOG_INFORMATIONAL, "... Done\n"); /* init shared memory control*/ retcode = initshm(shm_start); handle_error(retcode, "Could not create Shared Memory Control Set...\n", PROCESS_EXIT); /* init struct for PThread handling Clients */ myPThreadStruct = (struct pthread_struct *) malloc(sizeof(struct pthread_struct)); myPThreadStruct->isLast = 1; myPThreadStruct->nextClient = myPThreadStruct; /* if no arguments is chosen, output the usage of the Server */ if (argc == 1) { usage(); exit(1); } /* if arguments are chosen, validate the arguments */ else { printf("Verify valid arguments ...\n"); initValidServerArguments(argc, argv); } /* if no port for the server was chosen, set it to default port = 7000 */ if (validArguments[1].isSet == 0) { printf("There was no argument for the Server-Port. It will no be set to default = 7000\n"); ServerPort = 7000; validArguments[1].isSet = 1; } retcode = setTCPServer(); handle_error(retcode, "TCP Server settings could not be established!\n", PROCESS_EXIT); ServerListen(); /* clean up shared memory */ cleanup(shm_id); }
CNullModem::CNullModem(Bitu id, CommandLine* cmd):CSerial (id, cmd) { Bitu temptcpport=23; memset(&telClient, 0, sizeof(telClient)); InstallationSuccessful = false; serversocket = 0; clientsocket = 0; serverport = 0; clientport = 0; rx_retry = 0; rx_retry_max = 20; rx_state=N_RX_DISC; tx_gather = 12; dtrrespect=false; tx_block=false; receiveblock=false; transparent=false; telnet=false; Bitu bool_temp=0; // usedtr: The nullmodem will // 1) when it is client connect to the server not immediately but // as soon as a modem-aware application is started (DTR is switched on). // 2) only receive data when DTR is on. if (getBituSubstring("usedtr:", &bool_temp, cmd)) { if (bool_temp==1) { dtrrespect=true; transparent=true; DTR_delta=false; // connect immediately when DTR is already 1 } } // transparent: don't add additional handshake control. if (getBituSubstring("transparent:", &bool_temp, cmd)) { if (bool_temp==1) transparent=true; else transparent=false; } // telnet: interpret telnet commands. if (getBituSubstring("telnet:", &bool_temp, cmd)) { if (bool_temp==1) { transparent=true; telnet=true; } } // rxdelay: How many milliseconds to wait before causing an // overflow when the application is unresponsive. if (getBituSubstring("rxdelay:", &rx_retry_max, cmd)) { if (!(rx_retry_max<=10000)) { rx_retry_max=50; } } // txdelay: How many milliseconds to wait before sending data. // This reduces network overhead quite a lot. if (getBituSubstring("txdelay:", &tx_gather, cmd)) { if (!(tx_gather<=500)) { tx_gather=12; } } // port is for both server and client if (getBituSubstring("port:", &temptcpport, cmd)) { if (!(temptcpport>0&&temptcpport<65536)) { temptcpport=23; } } // socket inheritance (client-alike) if (getBituSubstring("inhsocket:", &bool_temp, cmd)) { #ifdef NATIVESOCKETS if (Netwrapper_GetCapabilities()&NETWRAPPER_TCP_NATIVESOCKET) { if (bool_temp==1) { int sock; if (control->cmdline->FindInt("-socket",sock,true)) { dtrrespect=false; transparent=true; LOG_MSG("Inheritance socket handle: %d",sock); if (!ClientConnect(new TCPClientSocket(sock))) return; } else { LOG_MSG("Serial%d: -socket parameter missing.",COMNUMBER); return; } } } else { LOG_MSG("Serial%d: socket inheritance not supported on this platform.", COMNUMBER); return; } #else LOG_MSG("Serial%d: socket inheritance not available.", COMNUMBER); #endif } else { // normal server/client std::string tmpstring; if (cmd->FindStringBegin("server:",tmpstring,false)) { // we are a client const char* hostnamechar=tmpstring.c_str(); size_t hostlen=strlen(hostnamechar)+1; if (hostlen>sizeof(hostnamebuffer)) { hostlen=sizeof(hostnamebuffer); hostnamebuffer[sizeof(hostnamebuffer)-1]=0; } memcpy(hostnamebuffer,hostnamechar,hostlen); clientport=(Bit16u)temptcpport; if (dtrrespect) { // we connect as soon as DTR is switched on setEvent(SERIAL_NULLMODEM_DTR_EVENT, 50); LOG_MSG("Serial%d: Waiting for DTR...",COMNUMBER); } else if (!ClientConnect( new TCPClientSocket((char*)hostnamebuffer,(Bit16u)clientport))) return; } else { // we are a server serverport = (Bit16u)temptcpport; if (!ServerListen()) return; } } CSerial::Init_Registers(); InstallationSuccessful = true; setCTS(dtrrespect||transparent); setDSR(dtrrespect||transparent); setRI(false); setCD(clientsocket > 0); // CD on if connection established }