ia64/xen-unstable

annotate 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
rev   line source
keir@16821 1 /*
keir@16821 2 * daytime.c: a simple network service based on lwIP and mini-os
keir@16821 3 *
keir@16821 4 * Tim Deegan <Tim.Deegan@eu.citrix.net>, July 2007
keir@16821 5 */
keir@16821 6
keir@16821 7 #include <os.h>
keir@16821 8 #include <xmalloc.h>
keir@16821 9 #include <console.h>
keir@16821 10 #include <netfront.h>
keir@16821 11 #include <lwip/api.h>
keir@16821 12
keir@16821 13 static char message[29];
keir@16821 14
keir@16821 15 void run_server(void *p)
keir@16821 16 {
keir@16821 17 struct ip_addr listenaddr = { 0 };
keir@16821 18 struct ip_addr ipaddr = { htonl(0x0a000001) };
keir@16821 19 struct ip_addr netmask = { htonl(0xff000000) };
keir@16821 20 struct ip_addr gw = { 0 };
keir@16821 21 struct netconn *listener;
keir@16821 22 struct netconn *session;
keir@16821 23 struct timeval tv;
keir@16821 24 err_t rc;
keir@16821 25
keir@16821 26 start_networking();
keir@16821 27 networking_set_addr(&ipaddr, &netmask, &gw);
keir@16821 28
keir@16821 29 tprintk("Opening connection\n");
keir@16821 30
keir@16821 31 listener = netconn_new(NETCONN_TCP);
keir@16821 32 tprintk("Connection at %p\n", listener);
keir@16821 33
keir@16821 34 rc = netconn_bind(listener, &listenaddr, 13);
keir@16821 35 if (rc != ERR_OK) {
keir@16821 36 tprintk("Failed to bind connection: %i\n", rc);
keir@16821 37 return;
keir@16821 38 }
keir@16821 39
keir@16821 40 rc = netconn_listen(listener);
keir@16821 41 if (rc != ERR_OK) {
keir@16821 42 tprintk("Failed to listen on connection: %i\n", rc);
keir@16821 43 return;
keir@16821 44 }
keir@16821 45
keir@16821 46 while (1) {
keir@16821 47 session = netconn_accept(listener);
keir@16821 48 if (session == NULL)
keir@16821 49 continue;
keir@16821 50
keir@16821 51 gettimeofday(&tv, NULL);
keir@16821 52 sprintf(message, "%20lu.%6.6lu\n", tv.tv_sec, tv.tv_usec);
keir@16821 53 (void) netconn_write(session, message, strlen(message), NETCONN_COPY);
keir@16821 54 (void) netconn_disconnect(session);
keir@16821 55 (void) netconn_delete(session);
keir@16821 56 }
keir@16821 57 }
keir@16821 58
keir@16821 59
keir@16821 60 int app_main(start_info_t *si)
keir@16821 61 {
keir@16821 62 create_thread("server", run_server, NULL);
keir@16821 63 return 0;
keir@16821 64 }