#include "shell.h" #include "server.h" #include "client.h" #include static Server srv; static int emac_id = -1; static Client cli; static int iamsrv = 0; #include void shelldebugprintf(char* x,...) { if (iamsrv) srv_sendBuffer(&srv,emac_id,x,strlen(x)); else cli_sendBuffer(&cli,x,strlen(x)); } void shell_on_connect(ServerEventArgs* e) { if (srv.ConnectionsAddr[e->ClientID].sin_addr.s_addr > 0xC0A80031 || srv.ConnectionsAddr[e->ClientID].sin_addr.s_addr < 0xC0A80001) emac_id = e->ClientID; kprintf("link engaged\n"); } void shell_on_disconnect(ServerEventArgs* e) { kprintf("connection lost from %s:%d",inet_ntoa(srv.ConnectionsAddr[e->ClientID].sin_addr),ntohs(srv.ConnectionsAddr[e->ClientID].sin_port)); } void shell_on_read(ServerEventArgs* e) { if (emac_id != -1 && e->ClientID != emac_id) srv_sendBuffer(&srv,emac_id,e->pBuffer,e->dwLen); // else commandos oder so } void shell_init(int srv_or_cli) { if (!srv_or_cli) { iamsrv = 1; kprintf("server init"); server_init(&srv,5555,49); srv._OnConnect = shell_on_connect; srv._OnDisconnect = shell_on_disconnect; srv._OnRead = shell_on_read; } else { sleep(3); kprintf("client init"); cli_init(&cli); while (cli_ConnectTo(&cli,"192.168.0.1",5555,0)); sleep(1); sleep(5); shelldebugprintf("sleeped 5 seconds\n"); sleep(5); shelldebugprintf("sleeped another 5 seconds\n"); } }