metalsvm/kernel/shell.c
Carl-Benedikt Krüger 53b736e925 shell test
2011-07-26 14:35:55 +02:00

72 lines
1.5 KiB
C

#include "shell.h"
#include "server.h"
#include "client.h"
#include <metalsvm/time.h>
static Server srv;
static int emac_id = -1;
static Client cli;
static int iamsrv = 0;
char shellbuffer[512];
void shelldebugprint(char* x)
{
kprintf("debugprinting");
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("bmc connected");
}
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,23,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",23,0));
sleep(1);
}
}