Merge pull request #80 from darconeous/mdns-resolv

Adds IPv6 and MDNS domain name resolution.
This commit is contained in:
Adam Dunkels 2013-03-10 12:58:39 -07:00
commit 39e5a8c6dc
34 changed files with 1397 additions and 333 deletions

View file

@ -114,7 +114,7 @@ PROCESS_THREAD(dhcp_process, ev, data)
CTK_WIDGET_FOCUS(&window, &getbutton); CTK_WIDGET_FOCUS(&window, &getbutton);
ctk_window_open(&window); ctk_window_open(&window);
dhcpc_init(uip_ethaddr.addr, sizeof(uip_ethaddr.addr)); dhcpc_init(uip_lladdr.addr, sizeof(uip_lladdr.addr));
while(1) { while(1) {

View file

@ -191,8 +191,7 @@ applyconfig(void)
addrptr = &addr; addrptr = &addr;
#if UIP_UDP #if UIP_UDP
if(uiplib_ipaddrconv(smtpserver, &addr) == 0) { if(uiplib_ipaddrconv(smtpserver, &addr) == 0) {
addrptr = resolv_lookup(smtpserver); if(resolv_lookup(smtpserver, &addrptr) != RESOLV_STATUS_CACHED) {
if(addrptr == NULL) {
resolv_query(smtpserver); resolv_query(smtpserver);
ctk_label_set_text(&statuslabel, "Resolving host..."); ctk_label_set_text(&statuslabel, "Resolving host...");
return; return;
@ -334,7 +333,7 @@ PROCESS_THREAD(email_process, ev, data)
#if UIP_UDP #if UIP_UDP
} else if(ev == resolv_event_found) { } else if(ev == resolv_event_found) {
if(strcmp(data, smtpserver) == 0) { if(strcmp(data, smtpserver) == 0) {
if(resolv_lookup(smtpserver) != NULL) { if(resolv_lookup(smtpserver, NULL) == RESOLV_STATUS_CACHED) {
applyconfig(); applyconfig();
ctk_label_set_text(&statuslabel, ""); ctk_label_set_text(&statuslabel, "");
} else { } else {

View file

@ -434,7 +434,7 @@ PROCESS_THREAD(ftp_process, ev, data)
} else if(ev == resolv_event_found) { } else if(ev == resolv_event_found) {
/* Either found a hostname, or not. */ /* Either found a hostname, or not. */
if((char *)data != NULL && if((char *)data != NULL &&
(ipaddrptr = resolv_lookup((char *)data)) != NULL) { resolv_lookup((char *)data, &ipaddrptr) == RESOLV_STATUS_CACHED) {
connection = ftpc_connect(ipaddrptr, UIP_HTONS(21)); connection = ftpc_connect(ipaddrptr, UIP_HTONS(21));
show_statustext("Connecting to ", hostname); show_statustext("Connecting to ", hostname);
} else { } else {
@ -508,8 +508,7 @@ PROCESS_THREAD(ftp_process, ev, data)
ptractive = 1; ptractive = 1;
#if UIP_UDP #if UIP_UDP
if(uiplib_ipaddrconv(hostname, &ipaddr) == 0) { if(uiplib_ipaddrconv(hostname, &ipaddr) == 0) {
ipaddrptr = resolv_lookup(hostname); if(resolv_lookup(hostname, &ipaddrptr) != RESOLV_STATUS_CACHED) {
if(ipaddrptr == NULL) {
resolv_query(hostname); resolv_query(hostname);
show_statustext("Resolving host ", hostname); show_statustext("Resolving host ", hostname);
break; break;

View file

@ -378,9 +378,7 @@ httpd_ws_request(char request_type, const char *host_ip, const char *host_hdr,
ipaddr = &addr; ipaddr = &addr;
if(uiplib_ipaddrconv(host_ip, &addr) == 0) { if(uiplib_ipaddrconv(host_ip, &addr) == 0) {
#if 0 && UIP_UDP #if 0 && UIP_UDP
ipaddr = resolv_lookup(host_ip); if(resolv_lookup(host, &ipaddr) != RESOLV_STATUS_CACHED) {
if(ipaddr == NULL) {
return NULL; return NULL;
} }
#else /* UIP_UDP */ #else /* UIP_UDP */

View file

@ -246,8 +246,7 @@ PROCESS_THREAD(irc_process, ev, data)
ipaddr = &serveraddr; ipaddr = &serveraddr;
#if UIP_UDP #if UIP_UDP
if(uiplib_ipaddrconv(server, &serveraddr) == 0) { if(uiplib_ipaddrconv(server, &serveraddr) == 0) {
ipaddr = resolv_lookup(server); if(resolv_lookup(server, &ipaddr) != RESOLV_STATUS_CACHED) {
if(ipaddr == NULL) {
resolv_query(server); resolv_query(server);
} else { } else {
uip_ipaddr_copy(&serveraddr, ipaddr); uip_ipaddr_copy(&serveraddr, ipaddr);
@ -264,8 +263,7 @@ PROCESS_THREAD(irc_process, ev, data)
#if UIP_UDP #if UIP_UDP
} else if(ev == resolv_event_found) { } else if(ev == resolv_event_found) {
ipaddr = resolv_lookup(server); if(resolv_lookup(server, &ipaddr) != RESOLV_STATUS_CACHED) {
if(ipaddr == NULL) {
ircc_text_output(&s, server, "hostname not found"); ircc_text_output(&s, server, "hostname not found");
} else { } else {
uip_ipaddr_copy(&serveraddr, ipaddr); uip_ipaddr_copy(&serveraddr, ipaddr);

View file

@ -157,7 +157,7 @@ PROCESS_THREAD(shell_irc_process, ev, data)
} else if(ev == resolv_event_found) { } else if(ev == resolv_event_found) {
/* Either found a hostname, or not. */ /* Either found a hostname, or not. */
if((char *)data != NULL && if((char *)data != NULL &&
resolv_lookup((char *)data) != NULL) { resolv_lookup((char *)data, &ipaddr) == RESOLV_STATUS_CACHED) {
uip_ipaddr_copy(serveraddr, ipaddr); uip_ipaddr_copy(serveraddr, ipaddr);
ircc_connect(&s, server, serveraddr, nick); ircc_connect(&s, server, serveraddr, nick);
} else { } else {

View file

@ -166,7 +166,7 @@ PROCESS_THREAD(shell_ping_process, ev, data)
} else if(ev == resolv_event_found) { } else if(ev == resolv_event_found) {
/* Either found a hostname, or not. */ /* Either found a hostname, or not. */
if((char *)data != NULL && if((char *)data != NULL &&
resolv_lookup((char *)data) != NULL) { resolv_lookup((char *)data, &ipaddr) == RESOLV_STATUS_CACHED) {
uip_ipaddr_copy(serveraddr, ipaddr); uip_ipaddr_copy(serveraddr, ipaddr);
telnet_connect(&s, server, serveraddr, nick); telnet_connect(&s, server, serveraddr, nick);
} else { } else {

View file

@ -173,7 +173,7 @@ PROCESS_THREAD(shell_tcpsend_process, ev, data)
} else if(ev == resolv_event_found) { } else if(ev == resolv_event_found) {
/* Either found a hostname, or not. */ /* Either found a hostname, or not. */
if((char *)data != NULL && if((char *)data != NULL &&
resolv_lookup((char *)data) != NULL) { resolv_lookup((char *)data, &ipaddr) == RESOLV_STATUS_CACHED) {
uip_ipaddr_copy(serveraddr, ipaddr); uip_ipaddr_copy(serveraddr, ipaddr);
telnet_connect(&s, server, serveraddr, nick); telnet_connect(&s, server, serveraddr, nick);
} else { } else {

View file

@ -123,7 +123,7 @@ PROCESS_THREAD(shell_udpsend_process, ev, data)
} else if(ev == resolv_event_found) { } else if(ev == resolv_event_found) {
/* Either found a hostname, or not. */ /* Either found a hostname, or not. */
if((char *)data != NULL && if((char *)data != NULL &&
resolv_lookup((char *)data) != NULL) { resolv_lookup((char *)data, &ipaddr) == RESOLV_STATUS_CACHED) {
uip_ipaddr_copy(serveraddr, ipaddr); uip_ipaddr_copy(serveraddr, ipaddr);
telnet_connect(&s, server, serveraddr, nick); telnet_connect(&s, server, serveraddr, nick);
} else { } else {

View file

@ -130,12 +130,14 @@ open_url(char *url)
/* Try to lookup the hostname. If it fails, we initiate a hostname /* Try to lookup the hostname. If it fails, we initiate a hostname
lookup and print out an informative message on the statusbar. */ lookup and print out an informative message on the statusbar. */
if(uiplib_ipaddrconv(host, &addr) == 0) { if(uiplib_ipaddrconv(host, &addr) == 0) {
uip_ipaddr_t *addrptr;
shell_output_str(&wget_command, "Not an IP address", ""); shell_output_str(&wget_command, "Not an IP address", "");
if(resolv_lookup(host) == NULL) { if(resolv_lookup(host, &addrptr) == RESOLV_STATUS_UNCACHED) {
shell_output_str(&wget_command, "Not resolved", ""); shell_output_str(&wget_command, "Not resolved", "");
resolv_query(host); resolv_query(host);
return; return;
} }
uip_ipaddr_copy(&addr, addrptr);
} }
#else /* UIP_UDP */ #else /* UIP_UDP */
uiplib_ipaddrconv(host, &addr); uiplib_ipaddrconv(host, &addr);
@ -171,7 +173,7 @@ PROCESS_THREAD(shell_wget_process, ev, data)
} else if(ev == resolv_event_found) { } else if(ev == resolv_event_found) {
/* Either found a hostname, or not. */ /* Either found a hostname, or not. */
if((char *)data != NULL && if((char *)data != NULL &&
resolv_lookup((char *)data) != NULL) { resolv_lookup((char *)data, NULL) == RESOLV_STATUS_CACHED) {
open_url(url); open_url(url);
} else { } else {
shell_output_str(&wget_command, "Host not found.", ""); shell_output_str(&wget_command, "Host not found.", "");

View file

@ -163,8 +163,7 @@ connect(void)
addrptr = &addr; addrptr = &addr;
#if UIP_UDP #if UIP_UDP
if(uiplib_ipaddrconv(telnethost, &addr) == 0) { if(uiplib_ipaddrconv(telnethost, &addr) == 0) {
addrptr = resolv_lookup(telnethost); if(resolv_lookup(telnethost, &addrptr) == RESOLV_STATUS_UNCACHED) {
if(addrptr == NULL) {
resolv_query(telnethost); resolv_query(telnethost);
show("Resolving host..."); show("Resolving host...");
return; return;
@ -252,7 +251,7 @@ PROCESS_THREAD(simpletelnet_process, ev, data)
#if UIP_UDP #if UIP_UDP
} else if(ev == resolv_event_found) { } else if(ev == resolv_event_found) {
if(strcmp(data, telnethost) == 0) { if(strcmp(data, telnethost) == 0) {
if(resolv_lookup(telnethost) != NULL) { if(resolv_lookup(telnethost, NULL) == RESOLV_STATUS_CACHED) {
connect(); connect();
} else { } else {
show("Host not found"); show("Host not found");

View file

@ -134,8 +134,7 @@ connect(void)
addrptr = &addr; addrptr = &addr;
if(uiplib_ipaddrconv(host, &addr) == 0) { if(uiplib_ipaddrconv(host, &addr) == 0) {
addrptr = resolv_lookup(host); if(resolv_lookup(host, &addrptr) == RESOLV_STATUS_UNCACHED) {
if(addrptr == NULL) {
resolv_query(host); resolv_query(host);
show("Resolving host..."); show("Resolving host...");
return; return;
@ -198,7 +197,7 @@ PROCESS_THREAD(vnc_process, ev, data)
LOADER_UNLOAD(); LOADER_UNLOAD();
} else if(ev == resolv_event_found) { } else if(ev == resolv_event_found) {
if(strcmp(data, host) == 0) { if(strcmp(data, host) == 0) {
if(resolv_lookup(host) != NULL) { if(resolv_lookup(host, NULL) == RESOLV_STATUS_CACHED) {
connect(); connect();
} else { } else {
show("Host not found"); show("Host not found");

View file

@ -140,9 +140,7 @@ webclient_get(const char *host, uint16_t port, const char *file)
ipaddr = &addr; ipaddr = &addr;
if(uiplib_ipaddrconv(host, &addr) == 0) { if(uiplib_ipaddrconv(host, &addr) == 0) {
#if UIP_UDP #if UIP_UDP
ipaddr = resolv_lookup(host); if(resolv_lookup(host,&ipaddr) != RESOLV_STATUS_CACHED) {
if(ipaddr == NULL) {
return 0; return 0;
} }
#else /* UIP_UDP */ #else /* UIP_UDP */
@ -486,7 +484,7 @@ webclient_appcall(void *state)
init_connection(); init_connection();
}*/ }*/
#if UIP_UDP #if UIP_UDP
if(resolv_lookup(s.host) == NULL) { if(resolv_lookup(s.host, NULL) != RESOLV_STATUS_CACHED) {
resolv_query(s.host); resolv_query(s.host);
} }
#endif /* UIP_UDP */ #endif /* UIP_UDP */

View file

@ -348,11 +348,13 @@ open_url(void)
/* Try to lookup the hostname. If it fails, we initiate a hostname /* Try to lookup the hostname. If it fails, we initiate a hostname
lookup and print out an informative message on the statusbar. */ lookup and print out an informative message on the statusbar. */
if(uiplib_ipaddrconv(host, &addr) == 0) { if(uiplib_ipaddrconv(host, &addr) == 0) {
if(resolv_lookup(host) == NULL) { uip_ipaddr_t *addrptr;
if(resolv_lookup(host, &addrptr) != RESOLV_STATUS_CACHED) {
resolv_query(host); resolv_query(host);
show_statustext("Resolving host..."); show_statustext("Resolving host...");
return; return;
} }
uip_ipaddr_copy(&addr, addrptr);
} }
#else /* UIP_UDP */ #else /* UIP_UDP */
uiplib_ipaddrconv(host, &addr); uiplib_ipaddrconv(host, &addr);
@ -553,7 +555,8 @@ PROCESS_THREAD(www_process, ev, data)
#if UIP_UDP #if UIP_UDP
} else if(ev == resolv_event_found) { } else if(ev == resolv_event_found) {
/* Either found a hostname, or not. */ /* Either found a hostname, or not. */
if((char *)data != NULL && resolv_lookup((char *)data) != NULL) { if((char *)data != NULL &&
resolv_lookup((char *)data, NULL) == RESOLV_STATUS_CACHED) {
open_url(); open_url();
} else { } else {
show_statustext("Host not found"); show_statustext("Host not found");

File diff suppressed because it is too large Load diff

View file

@ -40,6 +40,16 @@
#define __RESOLV_H__ #define __RESOLV_H__
#include "contiki.h" #include "contiki.h"
#include "uip.h"
/** If RESOLV_CONF_SUPPORTS_MDNS is set, then queries
* for domain names in the `local` TLD will use MDNS and
* will respond to MDNS queries for this device's hostname,
* as described by draft-cheshire-dnsext-multicastdns.
*/
#ifndef RESOLV_CONF_SUPPORTS_MDNS
#define RESOLV_CONF_SUPPORTS_MDNS (1)
#endif
/** /**
* Event that is broadcasted when a DNS name has been resolved. * Event that is broadcasted when a DNS name has been resolved.
@ -48,10 +58,52 @@ CCIF extern process_event_t resolv_event_found;
/* Functions. */ /* Functions. */
CCIF void resolv_conf(const uip_ipaddr_t * dnsserver); CCIF void resolv_conf(const uip_ipaddr_t * dnsserver);
CCIF uip_ipaddr_t *resolv_getserver(void); CCIF uip_ipaddr_t *resolv_getserver(void);
CCIF uip_ipaddr_t *resolv_lookup(const char *name);
enum {
/** Hostname is fresh and usable. This response is cached and will eventually
* expire to RESOLV_STATUS_EXPIRED.*/
RESOLV_STATUS_CACHED = 0,
/** Hostname was not found in the cache. Use resolv_query() to look it up. */
RESOLV_STATUS_UNCACHED,
/** Hostname was found, but it's status has expired. The address returned
* should not be used. Use resolv_query() to freshen it up.
*/
RESOLV_STATUS_EXPIRED,
/** The server has returned a not-found response for this domain name.
* This response is cached for the period described in the server.
* You may issue a new query at any time using resolv_query(), but
* you will generally want to wait until this domain's status becomes
* RESOLV_STATUS_EXPIRED.
*/
RESOLV_STATUS_NOT_FOUND,
/** This hostname is in the process of being resolved. Try again soon. */
RESOLV_STATUS_RESOLVING,
/** Some sort of server error was encountered while trying to look up this
* record. This response is cached and will eventually expire to
* RESOLV_STATUS_EXPIRED.
*/
RESOLV_STATUS_ERROR,
};
typedef uint8_t resolv_status_t;
CCIF resolv_status_t resolv_lookup(const char *name, uip_ipaddr_t ** ipaddr);
CCIF void resolv_query(const char *name); CCIF void resolv_query(const char *name);
#if RESOLV_CONF_SUPPORTS_MDNS
CCIF void resolv_set_hostname(const char *hostname);
CCIF const char *resolv_get_hostname(void);
#endif
PROCESS_NAME(resolv_process); PROCESS_NAME(resolv_process);
#endif /* __RESOLV_H__ */ #endif /* __RESOLV_H__ */

View file

@ -592,11 +592,11 @@ uip_ds6_get_global(int8_t state)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
uip_ds6_maddr_t * uip_ds6_maddr_t *
uip_ds6_maddr_add(uip_ipaddr_t *ipaddr) uip_ds6_maddr_add(const uip_ipaddr_t *ipaddr)
{ {
if(uip_ds6_list_loop if(uip_ds6_list_loop
((uip_ds6_element_t *)uip_ds6_if.maddr_list, UIP_DS6_MADDR_NB, ((uip_ds6_element_t *)uip_ds6_if.maddr_list, UIP_DS6_MADDR_NB,
sizeof(uip_ds6_maddr_t), ipaddr, 128, sizeof(uip_ds6_maddr_t), (void*)ipaddr, 128,
(uip_ds6_element_t **)&locmaddr) == FREESPACE) { (uip_ds6_element_t **)&locmaddr) == FREESPACE) {
locmaddr->isused = 1; locmaddr->isused = 1;
uip_ipaddr_copy(&locmaddr->ipaddr, ipaddr); uip_ipaddr_copy(&locmaddr->ipaddr, ipaddr);
@ -617,11 +617,11 @@ uip_ds6_maddr_rm(uip_ds6_maddr_t *maddr)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
uip_ds6_maddr_t * uip_ds6_maddr_t *
uip_ds6_maddr_lookup(uip_ipaddr_t *ipaddr) uip_ds6_maddr_lookup(const uip_ipaddr_t *ipaddr)
{ {
if(uip_ds6_list_loop if(uip_ds6_list_loop
((uip_ds6_element_t *)uip_ds6_if.maddr_list, UIP_DS6_MADDR_NB, ((uip_ds6_element_t *)uip_ds6_if.maddr_list, UIP_DS6_MADDR_NB,
sizeof(uip_ds6_maddr_t), ipaddr, 128, sizeof(uip_ds6_maddr_t), (void*)ipaddr, 128,
(uip_ds6_element_t **)&locmaddr) == FOUND) { (uip_ds6_element_t **)&locmaddr) == FOUND) {
return locmaddr; return locmaddr;
} }

View file

@ -315,9 +315,9 @@ uip_ds6_addr_t *uip_ds6_get_global(int8_t state);
/** \name Multicast address list basic routines */ /** \name Multicast address list basic routines */
/** @{ */ /** @{ */
uip_ds6_maddr_t *uip_ds6_maddr_add(uip_ipaddr_t *ipaddr); uip_ds6_maddr_t *uip_ds6_maddr_add(const uip_ipaddr_t *ipaddr);
void uip_ds6_maddr_rm(uip_ds6_maddr_t *maddr); void uip_ds6_maddr_rm(uip_ds6_maddr_t *maddr);
uip_ds6_maddr_t *uip_ds6_maddr_lookup(uip_ipaddr_t *ipaddr); uip_ds6_maddr_t *uip_ds6_maddr_lookup(const uip_ipaddr_t *ipaddr);
/** @} */ /** @} */

View file

@ -115,14 +115,14 @@ const uip_ipaddr_t uip_broadcast_addr =
const uip_ipaddr_t uip_all_zeroes_addr = { { 0x0, /* rest is 0 */ } }; const uip_ipaddr_t uip_all_zeroes_addr = { { 0x0, /* rest is 0 */ } };
#if UIP_FIXEDETHADDR #if UIP_FIXEDETHADDR
const struct uip_eth_addr uip_ethaddr = {{UIP_ETHADDR0, const uip_lladdr_t uip_lladdr = {{UIP_ETHADDR0,
UIP_ETHADDR1, UIP_ETHADDR1,
UIP_ETHADDR2, UIP_ETHADDR2,
UIP_ETHADDR3, UIP_ETHADDR3,
UIP_ETHADDR4, UIP_ETHADDR4,
UIP_ETHADDR5}}; UIP_ETHADDR5}};
#else #else
struct uip_eth_addr uip_ethaddr = {{0,0,0,0,0,0}}; uip_lladdr_t uip_lladdr = {{0,0,0,0,0,0}};
#endif #endif
/* The packet buffer that contains incoming packets. */ /* The packet buffer that contains incoming packets. */
@ -1050,7 +1050,7 @@ uip_process(uint8_t flag)
uip_ipaddr_copy(&ICMPBUF->srcipaddr, &uip_hostaddr); uip_ipaddr_copy(&ICMPBUF->srcipaddr, &uip_hostaddr);
ICMPBUF->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS; ICMPBUF->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS;
ICMPBUF->options[1] = 1; /* Options length, 1 = 8 bytes. */ ICMPBUF->options[1] = 1; /* Options length, 1 = 8 bytes. */
memcpy(&(ICMPBUF->options[2]), &uip_ethaddr, sizeof(uip_ethaddr)); memcpy(&(ICMPBUF->options[2]), &uip_lladdr, sizeof(uip_lladdr));
ICMPBUF->icmpchksum = 0; ICMPBUF->icmpchksum = 0;
ICMPBUF->icmpchksum = ~uip_icmp6chksum(); ICMPBUF->icmpchksum = ~uip_icmp6chksum();

View file

@ -311,8 +311,8 @@ uip_arp_arpin(void)
BUF->opcode = UIP_HTONS(ARP_REPLY); BUF->opcode = UIP_HTONS(ARP_REPLY);
memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6); memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6);
memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6); memcpy(BUF->shwaddr.addr, uip_lladdr.addr, 6);
memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6); memcpy(BUF->ethhdr.src.addr, uip_lladdr.addr, 6);
memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6); memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6);
uip_ipaddr_copy(&BUF->dipaddr, &BUF->sipaddr); uip_ipaddr_copy(&BUF->dipaddr, &BUF->sipaddr);
@ -408,8 +408,8 @@ uip_arp_out(void)
memset(BUF->ethhdr.dest.addr, 0xff, 6); memset(BUF->ethhdr.dest.addr, 0xff, 6);
memset(BUF->dhwaddr.addr, 0x00, 6); memset(BUF->dhwaddr.addr, 0x00, 6);
memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6); memcpy(BUF->ethhdr.src.addr, uip_lladdr.addr, 6);
memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6); memcpy(BUF->shwaddr.addr, uip_lladdr.addr, 6);
uip_ipaddr_copy(&BUF->dipaddr, &ipaddr); uip_ipaddr_copy(&BUF->dipaddr, &ipaddr);
uip_ipaddr_copy(&BUF->sipaddr, &uip_hostaddr); uip_ipaddr_copy(&BUF->sipaddr, &uip_hostaddr);
@ -429,7 +429,7 @@ uip_arp_out(void)
/* Build an ethernet header. */ /* Build an ethernet header. */
memcpy(IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6); memcpy(IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6);
} }
memcpy(IPBUF->ethhdr.src.addr, uip_ethaddr.addr, 6); memcpy(IPBUF->ethhdr.src.addr, uip_lladdr.addr, 6);
IPBUF->ethhdr.type = UIP_HTONS(UIP_ETHTYPE_IP); IPBUF->ethhdr.type = UIP_HTONS(UIP_ETHTYPE_IP);

View file

@ -54,7 +54,6 @@
#include "net/uip.h" #include "net/uip.h"
CCIF extern struct uip_eth_addr uip_ethaddr;
/** /**
* The Ethernet header. * The Ethernet header.
@ -130,12 +129,12 @@ void uip_arp_timer(void);
* *
* \hideinitializer * \hideinitializer
*/ */
#define uip_setethaddr(eaddr) do {uip_ethaddr.addr[0] = eaddr.addr[0]; \ #define uip_setethaddr(eaddr) do {uip_lladdr.addr[0] = eaddr.addr[0]; \
uip_ethaddr.addr[1] = eaddr.addr[1];\ uip_lladdr.addr[1] = eaddr.addr[1];\
uip_ethaddr.addr[2] = eaddr.addr[2];\ uip_lladdr.addr[2] = eaddr.addr[2];\
uip_ethaddr.addr[3] = eaddr.addr[3];\ uip_lladdr.addr[3] = eaddr.addr[3];\
uip_ethaddr.addr[4] = eaddr.addr[4];\ uip_lladdr.addr[4] = eaddr.addr[4];\
uip_ethaddr.addr[5] = eaddr.addr[5];} while(0) uip_lladdr.addr[5] = eaddr.addr[5];} while(0)
/** @} */ /** @} */

View file

@ -202,7 +202,7 @@ PROCESS_THREAD(ipconfig_process, ev, data)
/* Allow resolver to set DNS server address. */ /* Allow resolver to set DNS server address. */
PROCESS_PAUSE(); PROCESS_PAUSE();
dhcpc_init(uip_ethaddr.addr, sizeof(uip_ethaddr.addr)); dhcpc_init(uip_lladdr.addr, sizeof(uip_lladdr.addr));
while(1) { while(1) {
PROCESS_WAIT_EVENT(); PROCESS_WAIT_EVENT();

View file

@ -298,7 +298,7 @@ create_msg(CC_REGISTER_ARG struct dhcp_msg *m)
m->op = DHCP_REPLY; m->op = DHCP_REPLY;
/* m->htype = DHCP_HTYPE_ETHERNET; */ /* m->htype = DHCP_HTYPE_ETHERNET; */
/* m->hlen = DHCP_HLEN_ETHERNET; */ /* m->hlen = DHCP_HLEN_ETHERNET; */
/* memcpy(m->chaddr, &uip_ethaddr,DHCP_HLEN_ETHERNET); */ /* memcpy(m->chaddr, &uip_lladdr,DHCP_HLEN_ETHERNET); */
m->hops = 0; m->hops = 0;
m->secs = 0; m->secs = 0;
memcpy(m->siaddr, &uip_hostaddr, 4); memcpy(m->siaddr, &uip_hostaddr, 4);

View file

@ -155,11 +155,11 @@ HMODULE wpcap;
static struct pcap *pcap; static struct pcap *pcap;
/* uip_ethaddr is defined in uip.c. It is not used in uip6.c. /* uip_lladdr is defined in uip.c. It is not used in uip6.c.
* If needed for some purpose it can be defined here * If needed for some purpose it can be defined here
*/ */
#if UIP_CONF_IPV6 #if UIP_CONF_IPV6
//struct uip_eth_addr uip_ethaddr; //struct uip_eth_addr uip_lladdr;
#endif #endif
static int (* pcap_findalldevs)(struct pcap_if **, char *); static int (* pcap_findalldevs)(struct pcap_if **, char *);
@ -266,7 +266,7 @@ set_ethaddr(struct in_addr addr)
adapters->PhysicalAddress[4], adapters->PhysicalAddress[5]); adapters->PhysicalAddress[4], adapters->PhysicalAddress[5]);
log_message("set_ethaddr: ethernetaddr: ", buffer); log_message("set_ethaddr: ethernetaddr: ", buffer);
#if UIP_CONF_IPV6 #if UIP_CONF_IPV6
// int i;for (i=0;i<6;i++) uip_ethaddr.addr[i] = adapters->PhysicalAddress[i]; // int i;for (i=0;i<6;i++) uip_lladdr.addr[i] = adapters->PhysicalAddress[i];
#else #else
uip_setethaddr((*(struct uip_eth_addr *)adapters->PhysicalAddress)); uip_setethaddr((*(struct uip_eth_addr *)adapters->PhysicalAddress));
#endif #endif
@ -328,7 +328,7 @@ set_ethaddr6(struct in_addr6 addr)
adapters->PhysicalAddress[4], adapters->PhysicalAddress[5]); adapters->PhysicalAddress[4], adapters->PhysicalAddress[5]);
log_message("set_ethaddr: ethernetaddr: ", buffer); log_message("set_ethaddr: ethernetaddr: ", buffer);
#if UIP_CONF_IPV6 #if UIP_CONF_IPV6
// int i;for (i=0;i<6;i++) uip_ethaddr.addr[i] = adapters->PhysicalAddress[i]; //does this need doing? // int i;for (i=0;i<6;i++) uip_lladdr.addr[i] = adapters->PhysicalAddress[i]; //does this need doing?
#else #else
uip_setethaddr((*(struct uip_eth_addr *)adapters->PhysicalAddress)); uip_setethaddr((*(struct uip_eth_addr *)adapters->PhysicalAddress));
#endif #endif

View file

@ -75,9 +75,7 @@ json_ws_udp_setup(const char *host, uint16_t port)
ipaddr = &server_ipaddr; ipaddr = &server_ipaddr;
if(uiplib_ipaddrconv(host, &server_ipaddr) == 0) { if(uiplib_ipaddrconv(host, &server_ipaddr) == 0) {
#if 0 && UIP_UDP #if 0 && UIP_UDP
ipaddr = resolv_lookup(host); if(resolv_lookup(host, &ipaddr) != RESOLV_STATUS_CACHED) {
if(ipaddr == NULL) {
return 0; return 0;
} }
#else /* UIP_UDP */ #else /* UIP_UDP */

View file

@ -2,7 +2,7 @@ CONTIKI_PROJECT = sky-shell-webserver
all: $(CONTIKI_PROJECT) all: $(CONTIKI_PROJECT)
PROJECT_SOURCEFILES = webserver-nogui.c PROJECT_SOURCEFILES = webserver-nogui.c
HTTPD_CFS=1 HTTPD_CFS=1
CFLAGS = -DWITH_UIP=1 CFLAGS = -DWITH_UIP=1 -DRESOLV_CONF_SUPPORTS_MDNS=0
DEFINES=NETSTACK_MAC=nullmac_driver,NETSTACK_RDC=nullrdc_driver DEFINES=NETSTACK_MAC=nullmac_driver,NETSTACK_RDC=nullrdc_driver
SMALL=1 SMALL=1

View file

@ -187,7 +187,7 @@ tapdev_send(void)
printf("\n"); printf("\n");
} else { } else {
memcpy(&BUF->dest, addr, 6); memcpy(&BUF->dest, addr, 6);
memcpy(&BUF->src, &uip_ethaddr, 6); memcpy(&BUF->src, &uip_lladdr, 6);
uip_len += sizeof(struct uip_eth_hdr); uip_len += sizeof(struct uip_eth_hdr);
do_send(); do_send();
} }

View file

@ -30,8 +30,10 @@
#include "contiki.h" #include "contiki.h"
#include "contiki-lib.h" #include "contiki-lib.h"
#include "contiki-net.h" #include "contiki-net.h"
#include "net/resolv.h"
#include <string.h> #include <string.h>
#include <stdbool.h>
#define DEBUG DEBUG_PRINT #define DEBUG DEBUG_PRINT
#include "net/uip-debug.h" #include "net/uip-debug.h"
@ -42,7 +44,7 @@
static struct uip_udp_conn *client_conn; static struct uip_udp_conn *client_conn;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
PROCESS(udp_client_process, "UDP client process"); PROCESS(udp_client_process, "UDP client process");
AUTOSTART_PROCESSES(&udp_client_process); AUTOSTART_PROCESSES(&resolv_process,&udp_client_process);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
tcpip_handler(void) tcpip_handler(void)
@ -102,20 +104,43 @@ set_global_address(void)
} }
#endif /* UIP_CONF_ROUTER */ #endif /* UIP_CONF_ROUTER */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static resolv_status_t
set_connection_address(uip_ipaddr_t *ipaddr) set_connection_address(uip_ipaddr_t *ipaddr)
{ {
#ifndef UDP_CONNECTION_ADDR
#if RESOLV_CONF_SUPPORTS_MDNS
#define UDP_CONNECTION_ADDR contiki-udp-server.local
#elif UIP_CONF_ROUTER
#define UDP_CONNECTION_ADDR aaaa:0:0:0:0212:7404:0004:0404
#else
#define UDP_CONNECTION_ADDR fe80:0:0:0:6466:6666:6666:6666
#endif
#endif /* !UDP_CONNECTION_ADDR */
#define _QUOTEME(x) #x #define _QUOTEME(x) #x
#define QUOTEME(x) _QUOTEME(x) #define QUOTEME(x) _QUOTEME(x)
#ifdef UDP_CONNECTION_ADDR
resolv_status_t status = RESOLV_STATUS_ERROR;
if(uiplib_ipaddrconv(QUOTEME(UDP_CONNECTION_ADDR), ipaddr) == 0) { if(uiplib_ipaddrconv(QUOTEME(UDP_CONNECTION_ADDR), ipaddr) == 0) {
PRINTF("UDP client failed to parse address '%s'\n", QUOTEME(UDP_CONNECTION_ADDR)); uip_ipaddr_t *resolved_addr = NULL;
status = resolv_lookup(QUOTEME(UDP_CONNECTION_ADDR),&resolved_addr);
if(status == RESOLV_STATUS_UNCACHED || status == RESOLV_STATUS_EXPIRED) {
PRINTF("Attempting to look up %s\n",QUOTEME(UDP_CONNECTION_ADDR));
resolv_query(QUOTEME(UDP_CONNECTION_ADDR));
status = RESOLV_STATUS_RESOLVING;
} else if(status == RESOLV_STATUS_CACHED && resolved_addr != NULL) {
PRINTF("Lookup of \"%s\" succeded!\n",QUOTEME(UDP_CONNECTION_ADDR));
} else {
PRINTF("Lookup of \"%s\" failed. status = %d\n",QUOTEME(UDP_CONNECTION_ADDR),status);
} }
#elif UIP_CONF_ROUTER if(resolved_addr)
uip_ip6addr(ipaddr,0xaaaa,0,0,0,0x0212,0x7404,0x0004,0x0404); uip_ipaddr_copy(ipaddr, resolved_addr);
#else } else {
uip_ip6addr(ipaddr,0xfe80,0,0,0,0x6466,0x6666,0x6666,0x6666); status = RESOLV_STATUS_CACHED;
#endif /* UDP_CONNECTION_ADDR */ }
return status;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data) PROCESS_THREAD(udp_client_process, ev, data)
@ -132,7 +157,17 @@ PROCESS_THREAD(udp_client_process, ev, data)
print_local_addresses(); print_local_addresses();
set_connection_address(&ipaddr); static resolv_status_t status = RESOLV_STATUS_UNCACHED;
while(status != RESOLV_STATUS_CACHED) {
status = set_connection_address(&ipaddr);
if(status == RESOLV_STATUS_RESOLVING) {
PROCESS_WAIT_EVENT_UNTIL(ev == resolv_event_found);
} else if(status != RESOLV_STATUS_CACHED) {
PRINTF("Can't get connection address.\n");
PROCESS_YIELD();
}
}
/* new connection with remote host */ /* new connection with remote host */
client_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL); client_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL);

View file

@ -43,7 +43,7 @@
static struct uip_udp_conn *server_conn; static struct uip_udp_conn *server_conn;
PROCESS(udp_server_process, "UDP server process"); PROCESS(udp_server_process, "UDP server process");
AUTOSTART_PROCESSES(&udp_server_process); AUTOSTART_PROCESSES(&resolv_process,&udp_server_process);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
tcpip_handler(void) tcpip_handler(void)
@ -94,6 +94,10 @@ PROCESS_THREAD(udp_server_process, ev, data)
PROCESS_BEGIN(); PROCESS_BEGIN();
PRINTF("UDP server started\n"); PRINTF("UDP server started\n");
#if RESOLV_CONF_SUPPORTS_MDNS
resolv_set_hostname("contiki-udp-server");
#endif
#if UIP_CONF_ROUTER #if UIP_CONF_ROUTER
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);

View file

@ -113,15 +113,16 @@ start_get(void)
#if UIP_UDP #if UIP_UDP
/* First check if the host is an IP address. */ /* First check if the host is an IP address. */
if(uiplib_ipaddrconv(host, &addr) == 0) { if(uiplib_ipaddrconv(host, &addr) == 0) {
uip_ipaddr_t *addrptr;
/* Try to lookup the hostname. If it fails, we initiate a hostname /* Try to lookup the hostname. If it fails, we initiate a hostname
lookup and print out an informative message on the lookup and print out an informative message on the
statusbar. */ statusbar. */
if(resolv_lookup(host) == NULL) { if(resolv_lookup(host, &addrptr) != RESOLV_STATUS_CACHED) {
resolv_query(host); resolv_query(host);
puts("Resolving host..."); puts("Resolving host...");
return; return;
} }
uip_ipaddr_copy(&addr, addrptr);
} }
#else /* UIP_UDP */ #else /* UIP_UDP */
uiplib_ipaddrconv(host, &addr); uiplib_ipaddrconv(host, &addr);
@ -184,7 +185,7 @@ PROCESS_THREAD(wget_process, ev, data)
} else if(ev == resolv_event_found) { } else if(ev == resolv_event_found) {
/* Either found a hostname, or not. */ /* Either found a hostname, or not. */
if((char *)data != NULL && if((char *)data != NULL &&
resolv_lookup((char *)data) != NULL) { resolv_lookup((char *)data, NULL) == RESOLV_STATUS_CACHED) {
start_get(); start_get();
} else { } else {
puts("Host not found"); puts("Host not found");

View file

@ -49,7 +49,7 @@ make udp-server.cooja TARGET=cooja</commands>
<identifier>mtype512</identifier> <identifier>mtype512</identifier>
<description>Sender</description> <description>Sender</description>
<contikiapp>[CONTIKI_DIR]/examples/udp-ipv6/udp-client.c</contikiapp> <contikiapp>[CONTIKI_DIR]/examples/udp-ipv6/udp-client.c</contikiapp>
<commands>make udp-client.cooja TARGET=cooja DEFINES=UDP_CONNECTION_ADDR=fe80::201:1:1:1</commands> <commands>make udp-client.cooja TARGET=cooja</commands>
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface> <moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
<moteinterface>se.sics.cooja.interfaces.Battery</moteinterface> <moteinterface>se.sics.cooja.interfaces.Battery</moteinterface>
<moteinterface>se.sics.cooja.contikimote.interfaces.ContikiVib</moteinterface> <moteinterface>se.sics.cooja.contikimote.interfaces.ContikiVib</moteinterface>

View file

@ -685,7 +685,7 @@ LOAD /cygdrive/c/mspgcc/bin/../lib/gcc-lib/msp430/3.2.3/msp2/libgcc.a
.data 0x000002d8 0x2 contiki-esb.a(service.o) .data 0x000002d8 0x2 contiki-esb.a(service.o)
.data 0x000002da 0x0 contiki-esb.a(timer.o) .data 0x000002da 0x0 contiki-esb.a(timer.o)
.data 0x000002da 0x6 contiki-esb.a(uip.o) .data 0x000002da 0x6 contiki-esb.a(uip.o)
0x000002da uip_ethaddr 0x000002da uip_lladdr
.data 0x000002e0 0xa contiki-esb.a(tr1001-drv.o) .data 0x000002e0 0xa contiki-esb.a(tr1001-drv.o)
0x000002e0 tr1001_drv_process 0x000002e0 tr1001_drv_process
.data 0x000002ea 0x0 contiki-esb.a(esb-sensors.o) .data 0x000002ea 0x0 contiki-esb.a(esb-sensors.o)

View file

@ -123,7 +123,7 @@ static int (* pcap_sendpacket)(struct pcap *, unsigned char *, int);
#include "net/uip_arp.h" #include "net/uip_arp.h"
struct uip_eth_addr uip_ethaddr = {{0,0,0,0,0,0}}; struct uip_eth_addr uip_lladdr = {{0,0,0,0,0,0}};
static char interface_name[256] = ""; static char interface_name[256] = "";
@ -147,7 +147,7 @@ error_exit(char *msg1)
static void static void
setethaddr(struct uip_eth_addr *a) setethaddr(struct uip_eth_addr *a)
{ {
memcpy(&uip_ethaddr, a, sizeof(struct uip_eth_addr)); memcpy(&uip_lladdr, a, sizeof(struct uip_eth_addr));
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
@ -271,7 +271,7 @@ wpcap_poll(char * buf)
eth_hdr = (struct uip_eth_hdr *)packet; eth_hdr = (struct uip_eth_hdr *)packet;
if(memcmp(&uip_ethaddr,&eth_hdr->src,sizeof(struct uip_eth_addr))!=0){ if(memcmp(&uip_lladdr,&eth_hdr->src,sizeof(struct uip_eth_addr))!=0){
// It's not a packet originated from the interface itself. // It's not a packet originated from the interface itself.
return 0; return 0;
} }

View file

@ -150,7 +150,7 @@ struct arp_entry {
struct uip_eth_addr ethaddr; struct uip_eth_addr ethaddr;
uint8_t time; uint8_t time;
}; };
static struct uip_eth_addr uip_ethaddr = {{0,0,0,0,0,0}}; static struct uip_eth_addr uip_lladdr = {{0,0,0,0,0,0}};
static const uip_ipaddr_t all_zeroes_addr = { { 0x0, /* rest is 0 */ } }; static const uip_ipaddr_t all_zeroes_addr = { { 0x0, /* rest is 0 */ } };
static const struct uip_eth_addr broadcast_ethaddr = static const struct uip_eth_addr broadcast_ethaddr =
{{0xff,0xff,0xff,0xff,0xff,0xff}}; {{0xff,0xff,0xff,0xff,0xff,0xff}};
@ -224,7 +224,7 @@ init_pcap(struct in_addr addr)
static void static void
setethaddr(struct uip_eth_addr *a) setethaddr(struct uip_eth_addr *a)
{ {
memcpy(&uip_ethaddr, a, sizeof(struct uip_eth_addr)); memcpy(&uip_lladdr, a, sizeof(struct uip_eth_addr));
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
@ -439,8 +439,8 @@ arp_out(struct ethip_hdr *iphdr, int len)
memset(arphdr->ethhdr.dest.addr, 0xff, 6); memset(arphdr->ethhdr.dest.addr, 0xff, 6);
memset(arphdr->dhwaddr.addr, 0x00, 6); memset(arphdr->dhwaddr.addr, 0x00, 6);
memcpy(arphdr->ethhdr.src.addr, uip_ethaddr.addr, 6); memcpy(arphdr->ethhdr.src.addr, uip_lladdr.addr, 6);
memcpy(arphdr->shwaddr.addr, uip_ethaddr.addr, 6); memcpy(arphdr->shwaddr.addr, uip_lladdr.addr, 6);
uip_ipaddr_copy(&arphdr->dipaddr, &ipaddr); uip_ipaddr_copy(&arphdr->dipaddr, &ipaddr);
uip_ipaddr_copy(&arphdr->sipaddr, &netaddr); uip_ipaddr_copy(&arphdr->sipaddr, &netaddr);
@ -460,7 +460,7 @@ arp_out(struct ethip_hdr *iphdr, int len)
memcpy(iphdr->ethhdr.dest.addr, tabptr->ethaddr.addr, 6); memcpy(iphdr->ethhdr.dest.addr, tabptr->ethaddr.addr, 6);
} }
#endif /* 0 */ #endif /* 0 */
memcpy(iphdr->ethhdr.src.addr, uip_ethaddr.addr, 6); memcpy(iphdr->ethhdr.src.addr, uip_lladdr.addr, 6);
iphdr->ethhdr.type = UIP_HTONS(UIP_ETHTYPE_IP); iphdr->ethhdr.type = UIP_HTONS(UIP_ETHTYPE_IP);
@ -489,8 +489,8 @@ do_arp(void *buf, int len)
hdr->opcode = UIP_HTONS(ARP_REPLY); hdr->opcode = UIP_HTONS(ARP_REPLY);
memcpy(&hdr->dhwaddr.addr, &hdr->shwaddr.addr, 6); memcpy(&hdr->dhwaddr.addr, &hdr->shwaddr.addr, 6);
memcpy(&hdr->shwaddr.addr, &uip_ethaddr.addr, 6); memcpy(&hdr->shwaddr.addr, &uip_lladdr.addr, 6);
memcpy(&hdr->ethhdr.src.addr, &uip_ethaddr.addr, 6); memcpy(&hdr->ethhdr.src.addr, &uip_lladdr.addr, 6);
memcpy(&hdr->ethhdr.dest.addr, &hdr->dhwaddr.addr, 6); memcpy(&hdr->ethhdr.dest.addr, &hdr->dhwaddr.addr, 6);
uip_ipaddr_copy(&tmpaddr, &hdr->dipaddr); uip_ipaddr_copy(&tmpaddr, &hdr->dipaddr);