2 * Copyright (c) 2002, Adam Dunkels.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials provided
13 * with the distribution.
14 * 3. The name of the author may not be used to endorse or promote
15 * products derived from this software without specific prior
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * This file is part of the Contiki OS
32 * $Id: contiki-main.c,v 1.23 2010/02/02 17:51:55 dak664 Exp $
38 #include <sys/select.h>
43 #include "contiki-net.h"
45 #include "dev/serial-line.h"
49 #include "net/wpcap-drv.h"
50 #else /* __CYGWIN__ */
51 #include "net/tapdev-drv.h"
52 #endif /* __CYGWIN__ */
55 PROCINIT(&etimer_process
, &tcpip_process
, &wpcap_process
, &serial_line_process
);
56 #else /* __CYGWIN__ */
57 PROCINIT(&etimer_process
, &tapdev_process
, &tcpip_process
, &serial_line_process
);
58 #endif /* __CYGWIN__ */
61 /*---------------------------------------------------------------------------*/
63 sprint_ip6(uip_ip6addr_t addr
)
66 unsigned char zerocnt
= 0;
67 unsigned char numprinted
= 0;
69 char * result
= thestring
;
72 while (numprinted
< 8) {
73 if ((addr
.u16
[i
] == 0) && (zerocnt
== 0)) {
74 while(addr
.u16
[zerocnt
+ i
] == 0) zerocnt
++;
81 numprinted
+= zerocnt
;
83 result
+= sprintf(result
, "%x", (unsigned int)(ntohs(addr
.u16
[i
])));
87 if (numprinted
!= 8) *result
++ = ':';
91 printf("%s",thestring
);
93 #endif /* UIP_CONF_IPV6 */
94 /*---------------------------------------------------------------------------*/
96 /*---------------------------------------------------------------------------*/
107 autostart_start(autostart_processes
);
109 /* Set default IP addresses if not specified */
113 uip_gethostaddr(&addr
);
115 uip_ipaddr(&addr
, 10,1,1,1);
117 printf("IP Address: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr
));
118 uip_sethostaddr(&addr
);
120 uip_getnetmask(&addr
);
122 uip_ipaddr(&addr
, 255,0,0,0);
123 uip_setnetmask(&addr
);
125 printf("Subnet Mask: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr
));
127 uip_getdraddr(&addr
);
129 uip_ipaddr(&addr
, 10,1,1,100);
130 uip_setdraddr(&addr
);
132 printf("Def. Router: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr
));
134 #else /* !UIP_CONF_IPV6 */
137 uip_ip6addr(&ipaddr
, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
138 uip_netif_addr_autoconf_set(&ipaddr
, &uip_lladdr
);
139 uip_netif_addr_add(&ipaddr
, 16, 0, TENTATIVE
);
140 printf("IP6 Address: ");sprint_ip6(ipaddr
);printf("\n");
141 #endif /* !UIP_CONF_IPV6 */
143 /* Make standard output unbuffered. */
144 setvbuf(stdout
, (char *)NULL
, _IONBF
, 0);
153 printf("%d processes in queue\n");
159 FD_SET(STDIN_FILENO
, &fds
);
160 select(1, &fds
, NULL
, NULL
, &tv
);
162 if(FD_ISSET(STDIN_FILENO
, &fds
)) {
164 if(read(STDIN_FILENO
, &c
, 1) > 0) {
165 serial_line_input_byte(c
);
168 etimer_request_poll();
173 /*---------------------------------------------------------------------------*/
174 void log_message(char *m1
, char *m2
)
176 printf("%s%s\n", m1
, m2
);
178 /*---------------------------------------------------------------------------*/
182 printf("uIP: '%s'\n", m
);
184 /*---------------------------------------------------------------------------*/
188 static unsigned short count
;
191 /*---------------------------------------------------------------------------*/