ia64/xen-unstable

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