From 0464a12749f9b868bd681cbd93c3b3227e23ea8a Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Mon, 21 Jan 2008 11:20:52 +0000 Subject: minios: add lwIP 1.3.0 support Signed-off-by: Samuel Thibault --- extras/mini-os/daytime.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 extras/mini-os/daytime.c (limited to 'extras/mini-os/daytime.c') diff --git a/extras/mini-os/daytime.c b/extras/mini-os/daytime.c new file mode 100644 index 0000000000..d6cd50ef63 --- /dev/null +++ b/extras/mini-os/daytime.c @@ -0,0 +1,64 @@ +/* + * daytime.c: a simple network service based on lwIP and mini-os + * + * Tim Deegan , July 2007 + */ + +#include +#include +#include +#include +#include + +static char message[29]; + +void run_server(void *p) +{ + struct ip_addr listenaddr = { 0 }; + struct ip_addr ipaddr = { htonl(0x0a000001) }; + struct ip_addr netmask = { htonl(0xff000000) }; + struct ip_addr gw = { 0 }; + struct netconn *listener; + struct netconn *session; + struct timeval tv; + err_t rc; + + start_networking(); + networking_set_addr(&ipaddr, &netmask, &gw); + + tprintk("Opening connection\n"); + + listener = netconn_new(NETCONN_TCP); + tprintk("Connection at %p\n", listener); + + rc = netconn_bind(listener, &listenaddr, 13); + if (rc != ERR_OK) { + tprintk("Failed to bind connection: %i\n", rc); + return; + } + + rc = netconn_listen(listener); + if (rc != ERR_OK) { + tprintk("Failed to listen on connection: %i\n", rc); + return; + } + + while (1) { + session = netconn_accept(listener); + if (session == NULL) + continue; + + gettimeofday(&tv, NULL); + sprintf(message, "%20lu.%6.6lu\n", tv.tv_sec, tv.tv_usec); + (void) netconn_write(session, message, strlen(message), NETCONN_COPY); + (void) netconn_disconnect(session); + (void) netconn_delete(session); + } +} + + +int app_main(start_info_t *si) +{ + create_thread("server", run_server, NULL); + return 0; +} -- cgit v1.2.3