ia64/xen-unstable

diff extras/mini-os/daytime.c @ 16821:3c49ae5641b0

minios: add lwIP 1.3.0 support

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Jan 21 11:20:52 2008 +0000 (2008-01-21)
parents
children 7fc9767f966a
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/extras/mini-os/daytime.c	Mon Jan 21 11:20:52 2008 +0000
     1.3 @@ -0,0 +1,64 @@
     1.4 +/* 
     1.5 + * daytime.c: a simple network service based on lwIP and mini-os
     1.6 + * 
     1.7 + * Tim Deegan <Tim.Deegan@eu.citrix.net>, July 2007
     1.8 + */
     1.9 +
    1.10 +#include <os.h>
    1.11 +#include <xmalloc.h>
    1.12 +#include <console.h>
    1.13 +#include <netfront.h>
    1.14 +#include <lwip/api.h>
    1.15 +
    1.16 +static char message[29];
    1.17 +
    1.18 +void run_server(void *p)
    1.19 +{
    1.20 +    struct ip_addr listenaddr = { 0 };
    1.21 +    struct ip_addr ipaddr = { htonl(0x0a000001) };
    1.22 +    struct ip_addr netmask = { htonl(0xff000000) };
    1.23 +    struct ip_addr gw = { 0 };
    1.24 +    struct netconn *listener;
    1.25 +    struct netconn *session;
    1.26 +    struct timeval tv;
    1.27 +    err_t rc;
    1.28 +
    1.29 +    start_networking();
    1.30 +    networking_set_addr(&ipaddr, &netmask, &gw);
    1.31 +
    1.32 +    tprintk("Opening connection\n");
    1.33 +
    1.34 +    listener = netconn_new(NETCONN_TCP);
    1.35 +    tprintk("Connection at %p\n", listener);
    1.36 +
    1.37 +    rc = netconn_bind(listener, &listenaddr, 13);
    1.38 +    if (rc != ERR_OK) {
    1.39 +        tprintk("Failed to bind connection: %i\n", rc);
    1.40 +        return;
    1.41 +    }
    1.42 +
    1.43 +    rc = netconn_listen(listener);
    1.44 +    if (rc != ERR_OK) {
    1.45 +        tprintk("Failed to listen on connection: %i\n", rc);
    1.46 +        return;
    1.47 +    }
    1.48 +
    1.49 +    while (1) {
    1.50 +        session = netconn_accept(listener);
    1.51 +        if (session == NULL) 
    1.52 +            continue;
    1.53 +
    1.54 +        gettimeofday(&tv, NULL);
    1.55 +        sprintf(message, "%20lu.%6.6lu\n", tv.tv_sec, tv.tv_usec);
    1.56 +        (void) netconn_write(session, message, strlen(message), NETCONN_COPY);
    1.57 +        (void) netconn_disconnect(session);
    1.58 +        (void) netconn_delete(session);
    1.59 +    }
    1.60 +}
    1.61 +
    1.62 +
    1.63 +int app_main(start_info_t *si)
    1.64 +{
    1.65 +    create_thread("server", run_server, NULL);
    1.66 +    return 0;
    1.67 +}