Debian Codegraph @

contrib/ports/unix/proj/unixsim/simnode.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25 * OF SUCH DAMAGE.
26 *
27 * This file is part of the lwIP TCP/IP stack.
28 *
29 * Author: Adam Dunkels <[email protected]>
30 *
31 */
32
33 #include "lwip/debug.h"
34
35 #include <unistd.h>
36
37
38 #include "lwip/mem.h"
39 #include "lwip/memp.h"
40 #include "lwip/sys.h"
41 #include "lwip/tcp_impl.h"
42
43 #include "lwip/stats.h"
44
45
46 #include "lwip/tcpip.h"
47
48
49 #include "netif/unixif.h"
50 #include "netif/dropif.h"
51
52 #include "netif/tcpdump.h"
53
54 #include "lwip/ip_addr.h"
55
56 #include "arch/perf.h"
57
58 #include "httpd.h"
59 #include "udpecho.h"
60 #include "tcpecho.h"
61 #include "shell.h"
62
63 /* nonstatic debug cmd option, exported in lwipopts.h */
64 unsigned char debug_flags;
65
66 /*-----------------------------------------------------------------------------------*/
67 static void
68 tcp_timeout(void *data)
69 {
70 LWIP_UNUSED_ARG(data);
71 #if TCP_DEBUG
72 tcp_debug_print_pcbs();
73 #endif /* TCP_DEBUG */
74 sys_timeout(5000, tcp_timeout, NULL);
75 }
76 /*-----------------------------------------------------------------------------------*/
77 struct netif netif_unix;
78 /*-----------------------------------------------------------------------------------*/
79 static void
80 tcpip_init_done(void *arg)
81 {
82 ip_addr_t ipaddr, netmask, gw;
83 sys_sem_t *sem;
84 sem = (sys_sem_t *)arg;
85
86 IP4_ADDR(&gw, 192,168,1,1);
87 IP4_ADDR(&ipaddr, 192,168,1,2);
88 IP4_ADDR(&netmask, 255,255,255,0);
89
90 netif_set_default(netif_add(&netif_unix, &ipaddr, &netmask, &gw, NULL, unixif_init_client,
91 tcpip_input));
92 #if LWIP_IPV6
93 netif_create_ip6_linklocal_address(&netif_unix, 1);
94 #endif
95 /* netif_set_default(netif_add(&ipaddr, &netmask, &gw, NULL, sioslipif_init1,
96 tcpip_input)); */
97
98 tcpecho_init();
99 shell_init();
100 httpd_init();
101 udpecho_init();
102
103 printf("Applications started.\n");
104
105 sys_timeout(5000, tcp_timeout, NULL);
106
107 sys_sem_signal(sem);
108 }
109 /*-----------------------------------------------------------------------------------*/
110
111 static void
112 main_thread(void *arg)
113 {
114 sys_sem_t sem;
115 LWIP_UNUSED_ARG(arg);
116
117 if(sys_sem_new(&sem, 0) != ERR_OK) {
118 LWIP_ASSERT("Failed to create semaphore", 0);
119 }
120 tcpip_init(tcpip_init_done, &sem);
121 sys_sem_wait(&sem);
122 printf("TCP/IP initialized.\n");
123
124 #ifdef MEM_PERF
125 mem_perf_init("/tmp/memstats.client");
126 #endif /* MEM_PERF */
127
128 /* Block forever. */
129 sys_sem_wait(&sem);
130 }
131 /*-----------------------------------------------------------------------------------*/
132 int
133 main(void)
134 {
135 #ifdef PERF
136 perf_init("/tmp/client.perf");
137 #endif /* PERF */
138
139 tcpdump_init();
140
141 printf("System initialized.\n");
142
143 sys_thread_new("main_thread", main_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
144 pause();
145 return 0;
146 }
147 /*-----------------------------------------------------------------------------------*/
148
149
150
151
152
153
154
155