36 #include "contiki-net.h"
39 #include "net/dhcpc.h"
43 static struct ctk_button requestbutton =
45 static struct ctk_label statuslabel =
47 static struct ctk_label ipaddrlabel =
49 static char ipaddr[16];
50 static struct ctk_textentry ipaddrtextentry =
52 static struct ctk_label netmasklabel =
54 static char netmask[16];
55 static struct ctk_textentry netmasktextentry =
57 static struct ctk_label gatewaylabel =
59 static char gateway[16];
60 static struct ctk_textentry gatewaytextentry =
63 static struct ctk_label dnsserverlabel =
65 static char dnsserver[16];
66 static struct ctk_textentry dnsservertextentry =
69 static struct ctk_button savebutton =
71 static struct ctk_button cancelbutton =
74 PROCESS(dhcp_process,
"DHCP client");
76 AUTOSTART_PROCESSES(&dhcp_process);
80 makebyte(u8_t byte,
char *str)
83 *str++ = (byte / 100 ) % 10 +
'0';
86 *str++ = (byte / 10) % 10 +
'0';
88 *str++ = (byte % 10) +
'0';
96 str = makebyte(addr->u8[0], str);
98 str = makebyte(addr->u8[1], str);
100 str = makebyte(addr->u8[2], str);
102 str = makebyte(addr->u8[3], str);
112 makeaddr(&addr, ipaddr);
115 makeaddr(&addr, netmask);
118 makeaddr(&addr, gateway);
122 if(addrptr !=
NULL) {
123 makeaddr(addrptr, dnsserver);
129 nullterminate(
char *cptr)
133 for(; *cptr !=
' ' && *cptr != 0; ++cptr);
138 apply_tcpipconfig(
void)
141 int size = cfs_read(file, uip_buf, 100);
144 nullterminate(ipaddr);
147 nullterminate(netmask);
150 nullterminate(gateway);
154 nullterminate(dnsserver);
159 cfs_write(file, uip_buf, size);
164 set_statustext(
char *text)
206 dhcpc_init(uip_ethaddr.addr,
sizeof(uip_ethaddr.addr));
211 if(ev == PROCESS_EVENT_MSG) {
215 dhcpc_appcall(ev, data);
217 if(data == (process_data_t)&requestbutton) {
219 set_statustext(
"Requesting...");
221 if(data == (process_data_t)&savebutton) {
225 if(data == (process_data_t)&cancelbutton) {
229 #
if CTK_CONF_WINDOWCLOSE
232 ev == PROCESS_EVENT_EXIT) {
241 dhcpc_configured(
const struct dhcpc_state *s)
250 set_statustext(
"Configured.");
255 dhcpc_unconfigured(
const struct dhcpc_state *s)
266 set_statustext(
"Unconfigured.");