35 #include "contiki-net.h"
38 #include "net/ip/dhcpc.h"
42 static struct ctk_button requestbutton =
44 static struct ctk_label statuslabel =
46 static struct ctk_label ipaddrlabel =
48 static char ipaddr[16];
49 static struct ctk_textentry ipaddrtextentry =
51 static struct ctk_label netmasklabel =
53 static char netmask[16];
54 static struct ctk_textentry netmasktextentry =
56 static struct ctk_label gatewaylabel =
58 static char gateway[16];
59 static struct ctk_textentry gatewaytextentry =
62 static struct ctk_label dnsserverlabel =
64 static char dnsserver[16];
65 static struct ctk_textentry dnsservertextentry =
68 static struct ctk_button savebutton =
70 static struct ctk_button cancelbutton =
73 PROCESS(ipconfig_process,
"IP config");
75 AUTOSTART_PROCESSES(&ipconfig_process);
79 makebyte(uint8_t byte,
char *str)
82 *str++ = (byte / 100 ) % 10 +
'0';
85 *str++ = (byte / 10) % 10 +
'0';
87 *str++ = (byte % 10) +
'0';
93 makeaddr(uip_ipaddr_t *addr,
char *str)
95 str = makebyte(addr->u8[0], str);
97 str = makebyte(addr->u8[1], str);
99 str = makebyte(addr->u8[2], str);
101 str = makebyte(addr->u8[3], str);
108 uip_ipaddr_t addr, *addrptr;
111 makeaddr(&addr, ipaddr);
114 makeaddr(&addr, netmask);
117 makeaddr(&addr, gateway);
120 addrptr = resolv_getserver();
121 if(addrptr !=
NULL) {
122 makeaddr(addrptr, dnsserver);
128 nullterminate(
char *cptr)
132 for(; *cptr !=
' ' && *cptr != 0; ++cptr);
137 apply_tcpipconfig(
void)
140 int size = cfs_read(file, uip_buf, 100);
143 nullterminate(ipaddr);
146 nullterminate(netmask);
149 nullterminate(gateway);
153 nullterminate(dnsserver);
158 cfs_write(file, uip_buf, size);
163 set_statustext(
char *text)
212 if(ev == PROCESS_EVENT_MSG) {
216 dhcpc_appcall(ev, data);
218 if(data == (process_data_t)&requestbutton) {
220 set_statustext(
"Requesting...");
222 if(data == (process_data_t)&savebutton) {
226 if(data == (process_data_t)&cancelbutton) {
230 #
if CTK_CONF_WINDOWCLOSE
233 ev == PROCESS_EVENT_EXIT) {
242 dhcpc_configured(
const struct dhcpc_state *s)
248 resolv_conf(&s->dnsaddr);
251 set_statustext(
"Configured.");
256 dhcpc_unconfigured(
const struct dhcpc_state *s)
258 static uip_ipaddr_t nulladdr;
264 resolv_conf(&nulladdr);
267 set_statustext(
"Unconfigured.");