X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Ftelnetd_src%2Fmain.c;h=bf6de99970a8f866f3b3e29733503726404f81d5;hb=8e1f78107cc9aa137de29e0c9df3a1fccb483b67;hp=8a66ad7a9512d399f30bc5d3fd68c63cd0d49c49;hpb=30c11f371da98d13344e8bed3766d3e574a65ac9;p=tpg%2Facess2.git diff --git a/Usermode/Applications/telnetd_src/main.c b/Usermode/Applications/telnetd_src/main.c index 8a66ad7a..bf6de999 100644 --- a/Usermode/Applications/telnetd_src/main.c +++ b/Usermode/Applications/telnetd_src/main.c @@ -1,9 +1,14 @@ /* + * Acess2 Telnet Server (TCP server test case) + * - By John Hodge (thePowersGang) + * + * main.c + * - All */ #include #include -#include #include +#include // === TYPES === typedef struct sClient @@ -41,7 +46,7 @@ int main(int argc, char *argv[]) int addrtype = Net_ParseAddress("10.0.2.10", data); int port = 23; giServerFD = Net_OpenSocket(addrtype, data, "tcps"); - ioctl(giServerFD, 4, &port); // Set port and start listening + _SysIOCtl(giServerFD, 4, &port); // Set port and start listening } // Event loop @@ -50,17 +55,17 @@ int main(int argc, char *argv[]) return 0; } +static void FD_SET_MAX(fd_set *set, int fd, int *maxfd) +{ + FD_SET(fd, set); + if(*maxfd < fd) *maxfd = fd; +} + void EventLoop(void) { fd_set fds; int maxfd; - void FD_SET_MAX(fd_set *set, int fd, int *maxfd) - { - FD_SET(fd, set); - if(*maxfd < fd) *maxfd = fd; - } - for( ;; ) { FD_ZERO(&fds); @@ -77,7 +82,7 @@ void EventLoop(void) } // Select! - select( maxfd+1, &fds, NULL, NULL, NULL ); + _SysSelect( maxfd+1, &fds, NULL, NULL, NULL, 0 ); // Check events if( FD_ISSET(giServerFD, &fds) ) @@ -108,7 +113,7 @@ void Server_NewClient(int FD) if( giNumClients == giConfig_MaxClients ) { // Open, reject - close( _SysOpenChild(FD, "", O_RDWR) ); + _SysClose( _SysOpenChild(FD, "", OPENFLAG_READ) ); return ; } @@ -121,18 +126,18 @@ void Server_NewClient(int FD) } } // Accept the connection - clt->Socket = _SysOpenChild(FD, "", O_RDWR); + clt->Socket = _SysOpenChild(FD, "", OPENFLAG_READ|OPENFLAG_WRITE); giNumClients ++; // Create stdin/stdout - clt->stdin = open("/Devices/fifo/anon", O_RDWR); - clt->stdout = open("/Devices/fifo/anon", O_RDWR); + clt->stdin = _SysOpen("/Devices/fifo/anon", OPENFLAG_READ|OPENFLAG_WRITE); + clt->stdout = _SysOpen("/Devices/fifo/anon", OPENFLAG_READ|OPENFLAG_WRITE); // TODO: Arguments and envp { int fds[3] = {clt->stdin, clt->stdout, clt->stdout}; const char *argv[] = {NULL}; - _SysSpawn("/Acess/SBin/login", argv, argv, 3, fds); + _SysSpawn("/Acess/SBin/login", argv, argv, 3, fds, NULL); } } @@ -141,9 +146,9 @@ void HandleServerBoundData(tClient *Client) char buf[BUFSIZ]; int len; - len = read(Client->Socket, buf, BUFSIZ); + len = _SysRead(Client->Socket, buf, BUFSIZ); if( len <= 0 ) return ; - write(Client->stdin, buf, len); + _SysWrite(Client->stdin, buf, len); } void HandleClientBoundData(tClient *Client) @@ -151,8 +156,8 @@ void HandleClientBoundData(tClient *Client) char buf[BUFSIZ]; int len; - len = read(Client->stdout, buf, BUFSIZ); + len = _SysRead(Client->stdout, buf, BUFSIZ); if( len <= 0 ) return ; - write(Client->Socket, buf, len); + _SysWrite(Client->Socket, buf, len); }