diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2008-01-21 11:20:52 +0000 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2008-01-21 11:20:52 +0000 |
commit | 0464a12749f9b868bd681cbd93c3b3227e23ea8a (patch) | |
tree | 21a66419dd63914f00f0ea5eaab8c4a168657be1 /extras/mini-os/daytime.c | |
parent | afb13d4890c7b505865b8264247c2049fd0c2227 (diff) | |
download | xen-0464a12749f9b868bd681cbd93c3b3227e23ea8a.tar.gz xen-0464a12749f9b868bd681cbd93c3b3227e23ea8a.tar.bz2 xen-0464a12749f9b868bd681cbd93c3b3227e23ea8a.zip |
minios: add lwIP 1.3.0 support
Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
Diffstat (limited to 'extras/mini-os/daytime.c')
-rw-r--r-- | extras/mini-os/daytime.c | 64 |
1 files changed, 64 insertions, 0 deletions
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 <Tim.Deegan@eu.citrix.net>, July 2007 + */ + +#include <os.h> +#include <xmalloc.h> +#include <console.h> +#include <netfront.h> +#include <lwip/api.h> + +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; +} |