00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "uip.h"
00040 #include "uip_arp.h"
00041 #include "tapdev.h"
00042
00043 #include "timer.h"
00044
00045 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
00046
00047 #ifndef NULL
00048 #define NULL (void *)0
00049 #endif
00050
00051
00052 int
00053 main(void)
00054 {
00055 int i;
00056 uip_ipaddr_t ipaddr;
00057 struct timer periodic_timer, arp_timer;
00058
00059 timer_set(&periodic_timer, CLOCK_SECOND / 2);
00060 timer_set(&arp_timer, CLOCK_SECOND * 10);
00061
00062 tapdev_init();
00063 uip_init();
00064
00065 uip_ipaddr(ipaddr, 192,168,0,2);
00066 uip_sethostaddr(ipaddr);
00067 uip_ipaddr(ipaddr, 192,168,0,1);
00068 uip_setdraddr(ipaddr);
00069 uip_ipaddr(ipaddr, 255,255,255,0);
00070 uip_setnetmask(ipaddr);
00071
00072 httpd_init();
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 while(1) {
00099 uip_len = tapdev_read();
00100 if(uip_len > 0) {
00101 if(BUF->type == htons(UIP_ETHTYPE_IP)) {
00102 uip_arp_ipin();
00103 uip_input();
00104
00105
00106
00107 if(uip_len > 0) {
00108 uip_arp_out();
00109 tapdev_send();
00110 }
00111 } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) {
00112 uip_arp_arpin();
00113
00114
00115
00116 if(uip_len > 0) {
00117 tapdev_send();
00118 }
00119 }
00120
00121 } else if(timer_expired(&periodic_timer)) {
00122 timer_reset(&periodic_timer);
00123 for(i = 0; i < UIP_CONNS; i++) {
00124 uip_periodic(i);
00125
00126
00127
00128 if(uip_len > 0) {
00129 uip_arp_out();
00130 tapdev_send();
00131 }
00132 }
00133
00134 #if UIP_UDP
00135 for(i = 0; i < UIP_UDP_CONNS; i++) {
00136 uip_udp_periodic(i);
00137
00138
00139
00140 if(uip_len > 0) {
00141 uip_arp_out();
00142 tapdev_send();
00143 }
00144 }
00145 #endif
00146
00147
00148 if(timer_expired(&arp_timer)) {
00149 timer_reset(&arp_timer);
00150 uip_arp_timer();
00151 }
00152 }
00153 }
00154 return 0;
00155 }
00156
00157 void
00158 uip_log(char *m)
00159 {
00160 printf("uIP log message: %s\n", m);
00161 }
00162 void
00163 resolv_found(char *name, u16_t *ipaddr)
00164 {
00165 u16_t *ipaddr2;
00166
00167 if(ipaddr == NULL) {
00168 printf("Host '%s' not found.\n", name);
00169 } else {
00170 printf("Found name '%s' = %d.%d.%d.%d\n", name,
00171 htons(ipaddr[0]) >> 8,
00172 htons(ipaddr[0]) & 0xff,
00173 htons(ipaddr[1]) >> 8,
00174 htons(ipaddr[1]) & 0xff);
00175
00176 }
00177 }
00178 #ifdef __DHCPC_H__
00179 void
00180 dhcpc_configured(const struct dhcpc_state *s)
00181 {
00182 uip_sethostaddr(s->ipaddr);
00183 uip_setnetmask(s->netmask);
00184 uip_setdraddr(s->default_router);
00185 resolv_conf(s->dnsaddr);
00186 }
00187 #endif
00188 void
00189 smtp_done(unsigned char code)
00190 {
00191 printf("SMTP done with code %d\n", code);
00192 }
00193 void
00194 webclient_closed(void)
00195 {
00196 printf("Webclient: connection closed\n");
00197 }
00198 void
00199 webclient_aborted(void)
00200 {
00201 printf("Webclient: connection aborted\n");
00202 }
00203 void
00204 webclient_timedout(void)
00205 {
00206 printf("Webclient: connection timed out\n");
00207 }
00208 void
00209 webclient_connected(void)
00210 {
00211 printf("Webclient: connected, waiting for data...\n");
00212 }
00213 void
00214 webclient_datahandler(char *data, u16_t len)
00215 {
00216 printf("Webclient: got %d bytes of data.\n", len);
00217 }
00218