Merge pull request #80 from darconeous/mdns-resolv
Adds IPv6 and MDNS domain name resolution.
This commit is contained in:
commit
39e5a8c6dc
@ -114,7 +114,7 @@ PROCESS_THREAD(dhcp_process, ev, data)
|
||||
CTK_WIDGET_FOCUS(&window, &getbutton);
|
||||
|
||||
ctk_window_open(&window);
|
||||
dhcpc_init(uip_ethaddr.addr, sizeof(uip_ethaddr.addr));
|
||||
dhcpc_init(uip_lladdr.addr, sizeof(uip_lladdr.addr));
|
||||
|
||||
|
||||
while(1) {
|
||||
|
@ -191,8 +191,7 @@ applyconfig(void)
|
||||
addrptr = &addr;
|
||||
#if UIP_UDP
|
||||
if(uiplib_ipaddrconv(smtpserver, &addr) == 0) {
|
||||
addrptr = resolv_lookup(smtpserver);
|
||||
if(addrptr == NULL) {
|
||||
if(resolv_lookup(smtpserver, &addrptr) != RESOLV_STATUS_CACHED) {
|
||||
resolv_query(smtpserver);
|
||||
ctk_label_set_text(&statuslabel, "Resolving host...");
|
||||
return;
|
||||
@ -334,7 +333,7 @@ PROCESS_THREAD(email_process, ev, data)
|
||||
#if UIP_UDP
|
||||
} else if(ev == resolv_event_found) {
|
||||
if(strcmp(data, smtpserver) == 0) {
|
||||
if(resolv_lookup(smtpserver) != NULL) {
|
||||
if(resolv_lookup(smtpserver, NULL) == RESOLV_STATUS_CACHED) {
|
||||
applyconfig();
|
||||
ctk_label_set_text(&statuslabel, "");
|
||||
} else {
|
||||
|
@ -434,7 +434,7 @@ PROCESS_THREAD(ftp_process, ev, data)
|
||||
} else if(ev == resolv_event_found) {
|
||||
/* Either found a hostname, or not. */
|
||||
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));
|
||||
show_statustext("Connecting to ", hostname);
|
||||
} else {
|
||||
@ -508,8 +508,7 @@ PROCESS_THREAD(ftp_process, ev, data)
|
||||
ptractive = 1;
|
||||
#if UIP_UDP
|
||||
if(uiplib_ipaddrconv(hostname, &ipaddr) == 0) {
|
||||
ipaddrptr = resolv_lookup(hostname);
|
||||
if(ipaddrptr == NULL) {
|
||||
if(resolv_lookup(hostname, &ipaddrptr) != RESOLV_STATUS_CACHED) {
|
||||
resolv_query(hostname);
|
||||
show_statustext("Resolving host ", hostname);
|
||||
break;
|
||||
|
@ -378,9 +378,7 @@ httpd_ws_request(char request_type, const char *host_ip, const char *host_hdr,
|
||||
ipaddr = &addr;
|
||||
if(uiplib_ipaddrconv(host_ip, &addr) == 0) {
|
||||
#if 0 && UIP_UDP
|
||||
ipaddr = resolv_lookup(host_ip);
|
||||
|
||||
if(ipaddr == NULL) {
|
||||
if(resolv_lookup(host, &ipaddr) != RESOLV_STATUS_CACHED) {
|
||||
return NULL;
|
||||
}
|
||||
#else /* UIP_UDP */
|
||||
|
@ -246,8 +246,7 @@ PROCESS_THREAD(irc_process, ev, data)
|
||||
ipaddr = &serveraddr;
|
||||
#if UIP_UDP
|
||||
if(uiplib_ipaddrconv(server, &serveraddr) == 0) {
|
||||
ipaddr = resolv_lookup(server);
|
||||
if(ipaddr == NULL) {
|
||||
if(resolv_lookup(server, &ipaddr) != RESOLV_STATUS_CACHED) {
|
||||
resolv_query(server);
|
||||
} else {
|
||||
uip_ipaddr_copy(&serveraddr, ipaddr);
|
||||
@ -264,8 +263,7 @@ PROCESS_THREAD(irc_process, ev, data)
|
||||
#if UIP_UDP
|
||||
} else if(ev == resolv_event_found) {
|
||||
|
||||
ipaddr = resolv_lookup(server);
|
||||
if(ipaddr == NULL) {
|
||||
if(resolv_lookup(server, &ipaddr) != RESOLV_STATUS_CACHED) {
|
||||
ircc_text_output(&s, server, "hostname not found");
|
||||
} else {
|
||||
uip_ipaddr_copy(&serveraddr, ipaddr);
|
||||
|
@ -157,7 +157,7 @@ PROCESS_THREAD(shell_irc_process, ev, data)
|
||||
} else if(ev == resolv_event_found) {
|
||||
/* Either found a hostname, or not. */
|
||||
if((char *)data != NULL &&
|
||||
resolv_lookup((char *)data) != NULL) {
|
||||
resolv_lookup((char *)data, &ipaddr) == RESOLV_STATUS_CACHED) {
|
||||
uip_ipaddr_copy(serveraddr, ipaddr);
|
||||
ircc_connect(&s, server, serveraddr, nick);
|
||||
} else {
|
||||
|
@ -166,7 +166,7 @@ PROCESS_THREAD(shell_ping_process, ev, data)
|
||||
} else if(ev == resolv_event_found) {
|
||||
/* Either found a hostname, or not. */
|
||||
if((char *)data != NULL &&
|
||||
resolv_lookup((char *)data) != NULL) {
|
||||
resolv_lookup((char *)data, &ipaddr) == RESOLV_STATUS_CACHED) {
|
||||
uip_ipaddr_copy(serveraddr, ipaddr);
|
||||
telnet_connect(&s, server, serveraddr, nick);
|
||||
} else {
|
||||
|
@ -173,7 +173,7 @@ PROCESS_THREAD(shell_tcpsend_process, ev, data)
|
||||
} else if(ev == resolv_event_found) {
|
||||
/* Either found a hostname, or not. */
|
||||
if((char *)data != NULL &&
|
||||
resolv_lookup((char *)data) != NULL) {
|
||||
resolv_lookup((char *)data, &ipaddr) == RESOLV_STATUS_CACHED) {
|
||||
uip_ipaddr_copy(serveraddr, ipaddr);
|
||||
telnet_connect(&s, server, serveraddr, nick);
|
||||
} else {
|
||||
|
@ -123,7 +123,7 @@ PROCESS_THREAD(shell_udpsend_process, ev, data)
|
||||
} else if(ev == resolv_event_found) {
|
||||
/* Either found a hostname, or not. */
|
||||
if((char *)data != NULL &&
|
||||
resolv_lookup((char *)data) != NULL) {
|
||||
resolv_lookup((char *)data, &ipaddr) == RESOLV_STATUS_CACHED) {
|
||||
uip_ipaddr_copy(serveraddr, ipaddr);
|
||||
telnet_connect(&s, server, serveraddr, nick);
|
||||
} else {
|
||||
|
@ -130,12 +130,14 @@ open_url(char *url)
|
||||
/* Try to lookup the hostname. If it fails, we initiate a hostname
|
||||
lookup and print out an informative message on the statusbar. */
|
||||
if(uiplib_ipaddrconv(host, &addr) == 0) {
|
||||
uip_ipaddr_t *addrptr;
|
||||
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", "");
|
||||
resolv_query(host);
|
||||
return;
|
||||
}
|
||||
uip_ipaddr_copy(&addr, addrptr);
|
||||
}
|
||||
#else /* UIP_UDP */
|
||||
uiplib_ipaddrconv(host, &addr);
|
||||
@ -171,7 +173,7 @@ PROCESS_THREAD(shell_wget_process, ev, data)
|
||||
} else if(ev == resolv_event_found) {
|
||||
/* Either found a hostname, or not. */
|
||||
if((char *)data != NULL &&
|
||||
resolv_lookup((char *)data) != NULL) {
|
||||
resolv_lookup((char *)data, NULL) == RESOLV_STATUS_CACHED) {
|
||||
open_url(url);
|
||||
} else {
|
||||
shell_output_str(&wget_command, "Host not found.", "");
|
||||
|
@ -163,8 +163,7 @@ connect(void)
|
||||
addrptr = &addr;
|
||||
#if UIP_UDP
|
||||
if(uiplib_ipaddrconv(telnethost, &addr) == 0) {
|
||||
addrptr = resolv_lookup(telnethost);
|
||||
if(addrptr == NULL) {
|
||||
if(resolv_lookup(telnethost, &addrptr) == RESOLV_STATUS_UNCACHED) {
|
||||
resolv_query(telnethost);
|
||||
show("Resolving host...");
|
||||
return;
|
||||
@ -252,7 +251,7 @@ PROCESS_THREAD(simpletelnet_process, ev, data)
|
||||
#if UIP_UDP
|
||||
} else if(ev == resolv_event_found) {
|
||||
if(strcmp(data, telnethost) == 0) {
|
||||
if(resolv_lookup(telnethost) != NULL) {
|
||||
if(resolv_lookup(telnethost, NULL) == RESOLV_STATUS_CACHED) {
|
||||
connect();
|
||||
} else {
|
||||
show("Host not found");
|
||||
|
@ -134,8 +134,7 @@ connect(void)
|
||||
|
||||
addrptr = &addr;
|
||||
if(uiplib_ipaddrconv(host, &addr) == 0) {
|
||||
addrptr = resolv_lookup(host);
|
||||
if(addrptr == NULL) {
|
||||
if(resolv_lookup(host, &addrptr) == RESOLV_STATUS_UNCACHED) {
|
||||
resolv_query(host);
|
||||
show("Resolving host...");
|
||||
return;
|
||||
@ -198,7 +197,7 @@ PROCESS_THREAD(vnc_process, ev, data)
|
||||
LOADER_UNLOAD();
|
||||
} else if(ev == resolv_event_found) {
|
||||
if(strcmp(data, host) == 0) {
|
||||
if(resolv_lookup(host) != NULL) {
|
||||
if(resolv_lookup(host, NULL) == RESOLV_STATUS_CACHED) {
|
||||
connect();
|
||||
} else {
|
||||
show("Host not found");
|
||||
|
@ -140,9 +140,7 @@ webclient_get(const char *host, uint16_t port, const char *file)
|
||||
ipaddr = &addr;
|
||||
if(uiplib_ipaddrconv(host, &addr) == 0) {
|
||||
#if UIP_UDP
|
||||
ipaddr = resolv_lookup(host);
|
||||
|
||||
if(ipaddr == NULL) {
|
||||
if(resolv_lookup(host,&ipaddr) != RESOLV_STATUS_CACHED) {
|
||||
return 0;
|
||||
}
|
||||
#else /* UIP_UDP */
|
||||
@ -486,7 +484,7 @@ webclient_appcall(void *state)
|
||||
init_connection();
|
||||
}*/
|
||||
#if UIP_UDP
|
||||
if(resolv_lookup(s.host) == NULL) {
|
||||
if(resolv_lookup(s.host, NULL) != RESOLV_STATUS_CACHED) {
|
||||
resolv_query(s.host);
|
||||
}
|
||||
#endif /* UIP_UDP */
|
||||
|
@ -348,11 +348,13 @@ open_url(void)
|
||||
/* Try to lookup the hostname. If it fails, we initiate a hostname
|
||||
lookup and print out an informative message on the statusbar. */
|
||||
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);
|
||||
show_statustext("Resolving host...");
|
||||
return;
|
||||
}
|
||||
uip_ipaddr_copy(&addr, addrptr);
|
||||
}
|
||||
#else /* UIP_UDP */
|
||||
uiplib_ipaddrconv(host, &addr);
|
||||
@ -553,7 +555,8 @@ PROCESS_THREAD(www_process, ev, data)
|
||||
#if UIP_UDP
|
||||
} else if(ev == resolv_event_found) {
|
||||
/* 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();
|
||||
} else {
|
||||
show_statustext("Host not found");
|
||||
|
1462
core/net/resolv.c
1462
core/net/resolv.c
File diff suppressed because it is too large
Load Diff
@ -40,6 +40,16 @@
|
||||
#define __RESOLV_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.
|
||||
@ -47,11 +57,53 @@
|
||||
CCIF extern process_event_t resolv_event_found;
|
||||
|
||||
/* 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_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);
|
||||
|
||||
#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);
|
||||
|
||||
#endif /* __RESOLV_H__ */
|
||||
|
@ -592,11 +592,11 @@ uip_ds6_get_global(int8_t state)
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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
|
||||
((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) {
|
||||
locmaddr->isused = 1;
|
||||
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_lookup(uip_ipaddr_t *ipaddr)
|
||||
uip_ds6_maddr_lookup(const uip_ipaddr_t *ipaddr)
|
||||
{
|
||||
if(uip_ds6_list_loop
|
||||
((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) {
|
||||
return locmaddr;
|
||||
}
|
||||
|
@ -315,9 +315,9 @@ uip_ds6_addr_t *uip_ds6_get_global(int8_t state);
|
||||
|
||||
/** \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);
|
||||
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);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
@ -115,14 +115,14 @@ const uip_ipaddr_t uip_broadcast_addr =
|
||||
const uip_ipaddr_t uip_all_zeroes_addr = { { 0x0, /* rest is 0 */ } };
|
||||
|
||||
#if UIP_FIXEDETHADDR
|
||||
const struct uip_eth_addr uip_ethaddr = {{UIP_ETHADDR0,
|
||||
const uip_lladdr_t uip_lladdr = {{UIP_ETHADDR0,
|
||||
UIP_ETHADDR1,
|
||||
UIP_ETHADDR2,
|
||||
UIP_ETHADDR3,
|
||||
UIP_ETHADDR4,
|
||||
UIP_ETHADDR5}};
|
||||
#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
|
||||
|
||||
/* The packet buffer that contains incoming packets. */
|
||||
@ -1050,7 +1050,7 @@ uip_process(uint8_t flag)
|
||||
uip_ipaddr_copy(&ICMPBUF->srcipaddr, &uip_hostaddr);
|
||||
ICMPBUF->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS;
|
||||
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 = ~uip_icmp6chksum();
|
||||
|
||||
|
@ -311,8 +311,8 @@ uip_arp_arpin(void)
|
||||
BUF->opcode = UIP_HTONS(ARP_REPLY);
|
||||
|
||||
memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6);
|
||||
memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
|
||||
memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
|
||||
memcpy(BUF->shwaddr.addr, uip_lladdr.addr, 6);
|
||||
memcpy(BUF->ethhdr.src.addr, uip_lladdr.addr, 6);
|
||||
memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6);
|
||||
|
||||
uip_ipaddr_copy(&BUF->dipaddr, &BUF->sipaddr);
|
||||
@ -408,8 +408,8 @@ uip_arp_out(void)
|
||||
|
||||
memset(BUF->ethhdr.dest.addr, 0xff, 6);
|
||||
memset(BUF->dhwaddr.addr, 0x00, 6);
|
||||
memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
|
||||
memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
|
||||
memcpy(BUF->ethhdr.src.addr, uip_lladdr.addr, 6);
|
||||
memcpy(BUF->shwaddr.addr, uip_lladdr.addr, 6);
|
||||
|
||||
uip_ipaddr_copy(&BUF->dipaddr, &ipaddr);
|
||||
uip_ipaddr_copy(&BUF->sipaddr, &uip_hostaddr);
|
||||
@ -429,7 +429,7 @@ uip_arp_out(void)
|
||||
/* Build an ethernet header. */
|
||||
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);
|
||||
|
||||
|
@ -54,7 +54,6 @@
|
||||
#include "net/uip.h"
|
||||
|
||||
|
||||
CCIF extern struct uip_eth_addr uip_ethaddr;
|
||||
|
||||
/**
|
||||
* The Ethernet header.
|
||||
@ -130,12 +129,12 @@ void uip_arp_timer(void);
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define uip_setethaddr(eaddr) do {uip_ethaddr.addr[0] = eaddr.addr[0]; \
|
||||
uip_ethaddr.addr[1] = eaddr.addr[1];\
|
||||
uip_ethaddr.addr[2] = eaddr.addr[2];\
|
||||
uip_ethaddr.addr[3] = eaddr.addr[3];\
|
||||
uip_ethaddr.addr[4] = eaddr.addr[4];\
|
||||
uip_ethaddr.addr[5] = eaddr.addr[5];} while(0)
|
||||
#define uip_setethaddr(eaddr) do {uip_lladdr.addr[0] = eaddr.addr[0]; \
|
||||
uip_lladdr.addr[1] = eaddr.addr[1];\
|
||||
uip_lladdr.addr[2] = eaddr.addr[2];\
|
||||
uip_lladdr.addr[3] = eaddr.addr[3];\
|
||||
uip_lladdr.addr[4] = eaddr.addr[4];\
|
||||
uip_lladdr.addr[5] = eaddr.addr[5];} while(0)
|
||||
|
||||
/** @} */
|
||||
|
||||
|
@ -202,7 +202,7 @@ PROCESS_THREAD(ipconfig_process, ev, data)
|
||||
/* Allow resolver to set DNS server address. */
|
||||
PROCESS_PAUSE();
|
||||
|
||||
dhcpc_init(uip_ethaddr.addr, sizeof(uip_ethaddr.addr));
|
||||
dhcpc_init(uip_lladdr.addr, sizeof(uip_lladdr.addr));
|
||||
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT();
|
||||
|
@ -298,7 +298,7 @@ create_msg(CC_REGISTER_ARG struct dhcp_msg *m)
|
||||
m->op = DHCP_REPLY;
|
||||
/* m->htype = DHCP_HTYPE_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->secs = 0;
|
||||
memcpy(m->siaddr, &uip_hostaddr, 4);
|
||||
|
@ -155,11 +155,11 @@ HMODULE wpcap;
|
||||
|
||||
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 UIP_CONF_IPV6
|
||||
//struct uip_eth_addr uip_ethaddr;
|
||||
//struct uip_eth_addr uip_lladdr;
|
||||
#endif
|
||||
|
||||
static int (* pcap_findalldevs)(struct pcap_if **, char *);
|
||||
@ -266,7 +266,7 @@ set_ethaddr(struct in_addr addr)
|
||||
adapters->PhysicalAddress[4], adapters->PhysicalAddress[5]);
|
||||
log_message("set_ethaddr: ethernetaddr: ", buffer);
|
||||
#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
|
||||
uip_setethaddr((*(struct uip_eth_addr *)adapters->PhysicalAddress));
|
||||
#endif
|
||||
@ -328,7 +328,7 @@ set_ethaddr6(struct in_addr6 addr)
|
||||
adapters->PhysicalAddress[4], adapters->PhysicalAddress[5]);
|
||||
log_message("set_ethaddr: ethernetaddr: ", buffer);
|
||||
#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
|
||||
uip_setethaddr((*(struct uip_eth_addr *)adapters->PhysicalAddress));
|
||||
#endif
|
||||
|
@ -75,9 +75,7 @@ json_ws_udp_setup(const char *host, uint16_t port)
|
||||
ipaddr = &server_ipaddr;
|
||||
if(uiplib_ipaddrconv(host, &server_ipaddr) == 0) {
|
||||
#if 0 && UIP_UDP
|
||||
ipaddr = resolv_lookup(host);
|
||||
|
||||
if(ipaddr == NULL) {
|
||||
if(resolv_lookup(host, &ipaddr) != RESOLV_STATUS_CACHED) {
|
||||
return 0;
|
||||
}
|
||||
#else /* UIP_UDP */
|
||||
|
@ -2,7 +2,7 @@ CONTIKI_PROJECT = sky-shell-webserver
|
||||
all: $(CONTIKI_PROJECT)
|
||||
PROJECT_SOURCEFILES = webserver-nogui.c
|
||||
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
|
||||
SMALL=1
|
||||
|
||||
|
@ -187,7 +187,7 @@ tapdev_send(void)
|
||||
printf("\n");
|
||||
} else {
|
||||
memcpy(&BUF->dest, addr, 6);
|
||||
memcpy(&BUF->src, &uip_ethaddr, 6);
|
||||
memcpy(&BUF->src, &uip_lladdr, 6);
|
||||
uip_len += sizeof(struct uip_eth_hdr);
|
||||
do_send();
|
||||
}
|
||||
|
@ -30,8 +30,10 @@
|
||||
#include "contiki.h"
|
||||
#include "contiki-lib.h"
|
||||
#include "contiki-net.h"
|
||||
#include "net/resolv.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define DEBUG DEBUG_PRINT
|
||||
#include "net/uip-debug.h"
|
||||
@ -42,7 +44,7 @@
|
||||
static struct uip_udp_conn *client_conn;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(udp_client_process, "UDP client process");
|
||||
AUTOSTART_PROCESSES(&udp_client_process);
|
||||
AUTOSTART_PROCESSES(&resolv_process,&udp_client_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
tcpip_handler(void)
|
||||
@ -102,20 +104,43 @@ set_global_address(void)
|
||||
}
|
||||
#endif /* UIP_CONF_ROUTER */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
static resolv_status_t
|
||||
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) _QUOTEME(x)
|
||||
#ifdef UDP_CONNECTION_ADDR
|
||||
|
||||
resolv_status_t status = RESOLV_STATUS_ERROR;
|
||||
|
||||
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);
|
||||
}
|
||||
if(resolved_addr)
|
||||
uip_ipaddr_copy(ipaddr, resolved_addr);
|
||||
} else {
|
||||
status = RESOLV_STATUS_CACHED;
|
||||
}
|
||||
#elif UIP_CONF_ROUTER
|
||||
uip_ip6addr(ipaddr,0xaaaa,0,0,0,0x0212,0x7404,0x0004,0x0404);
|
||||
#else
|
||||
uip_ip6addr(ipaddr,0xfe80,0,0,0,0x6466,0x6666,0x6666,0x6666);
|
||||
#endif /* UDP_CONNECTION_ADDR */
|
||||
|
||||
return status;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(udp_client_process, ev, data)
|
||||
@ -132,7 +157,17 @@ PROCESS_THREAD(udp_client_process, ev, data)
|
||||
|
||||
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 */
|
||||
client_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL);
|
||||
|
@ -43,7 +43,7 @@
|
||||
static struct uip_udp_conn *server_conn;
|
||||
|
||||
PROCESS(udp_server_process, "UDP server process");
|
||||
AUTOSTART_PROCESSES(&udp_server_process);
|
||||
AUTOSTART_PROCESSES(&resolv_process,&udp_server_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
tcpip_handler(void)
|
||||
@ -94,6 +94,10 @@ PROCESS_THREAD(udp_server_process, ev, data)
|
||||
PROCESS_BEGIN();
|
||||
PRINTF("UDP server started\n");
|
||||
|
||||
#if RESOLV_CONF_SUPPORTS_MDNS
|
||||
resolv_set_hostname("contiki-udp-server");
|
||||
#endif
|
||||
|
||||
#if UIP_CONF_ROUTER
|
||||
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
|
||||
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
||||
|
@ -113,15 +113,16 @@ start_get(void)
|
||||
#if UIP_UDP
|
||||
/* First check if the host is an IP address. */
|
||||
if(uiplib_ipaddrconv(host, &addr) == 0) {
|
||||
|
||||
uip_ipaddr_t *addrptr;
|
||||
/* Try to lookup the hostname. If it fails, we initiate a hostname
|
||||
lookup and print out an informative message on the
|
||||
statusbar. */
|
||||
if(resolv_lookup(host) == NULL) {
|
||||
if(resolv_lookup(host, &addrptr) != RESOLV_STATUS_CACHED) {
|
||||
resolv_query(host);
|
||||
puts("Resolving host...");
|
||||
return;
|
||||
}
|
||||
uip_ipaddr_copy(&addr, addrptr);
|
||||
}
|
||||
#else /* UIP_UDP */
|
||||
uiplib_ipaddrconv(host, &addr);
|
||||
@ -184,7 +185,7 @@ PROCESS_THREAD(wget_process, ev, data)
|
||||
} else if(ev == resolv_event_found) {
|
||||
/* Either found a hostname, or not. */
|
||||
if((char *)data != NULL &&
|
||||
resolv_lookup((char *)data) != NULL) {
|
||||
resolv_lookup((char *)data, NULL) == RESOLV_STATUS_CACHED) {
|
||||
start_get();
|
||||
} else {
|
||||
puts("Host not found");
|
||||
|
@ -49,7 +49,7 @@ make udp-server.cooja TARGET=cooja</commands>
|
||||
<identifier>mtype512</identifier>
|
||||
<description>Sender</description>
|
||||
<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.Battery</moteinterface>
|
||||
<moteinterface>se.sics.cooja.contikimote.interfaces.ContikiVib</moteinterface>
|
||||
|
@ -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 0x000002da 0x0 contiki-esb.a(timer.o)
|
||||
.data 0x000002da 0x6 contiki-esb.a(uip.o)
|
||||
0x000002da uip_ethaddr
|
||||
0x000002da uip_lladdr
|
||||
.data 0x000002e0 0xa contiki-esb.a(tr1001-drv.o)
|
||||
0x000002e0 tr1001_drv_process
|
||||
.data 0x000002ea 0x0 contiki-esb.a(esb-sensors.o)
|
||||
|
@ -123,7 +123,7 @@ static int (* pcap_sendpacket)(struct pcap *, unsigned char *, int);
|
||||
#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] = "";
|
||||
|
||||
@ -147,7 +147,7 @@ error_exit(char *msg1)
|
||||
static void
|
||||
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
|
||||
@ -271,7 +271,7 @@ wpcap_poll(char * buf)
|
||||
|
||||
eth_hdr = (struct uip_eth_hdr *)packet;
|
||||
|
||||
if(memcmp(&uip_ethaddr,ð_hdr->src,sizeof(struct uip_eth_addr))!=0){
|
||||
if(memcmp(&uip_lladdr,ð_hdr->src,sizeof(struct uip_eth_addr))!=0){
|
||||
// It's not a packet originated from the interface itself.
|
||||
return 0;
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ struct arp_entry {
|
||||
struct uip_eth_addr ethaddr;
|
||||
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 struct uip_eth_addr broadcast_ethaddr =
|
||||
{{0xff,0xff,0xff,0xff,0xff,0xff}};
|
||||
@ -224,7 +224,7 @@ init_pcap(struct in_addr addr)
|
||||
static void
|
||||
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
|
||||
@ -439,8 +439,8 @@ arp_out(struct ethip_hdr *iphdr, int len)
|
||||
|
||||
memset(arphdr->ethhdr.dest.addr, 0xff, 6);
|
||||
memset(arphdr->dhwaddr.addr, 0x00, 6);
|
||||
memcpy(arphdr->ethhdr.src.addr, uip_ethaddr.addr, 6);
|
||||
memcpy(arphdr->shwaddr.addr, uip_ethaddr.addr, 6);
|
||||
memcpy(arphdr->ethhdr.src.addr, uip_lladdr.addr, 6);
|
||||
memcpy(arphdr->shwaddr.addr, uip_lladdr.addr, 6);
|
||||
|
||||
uip_ipaddr_copy(&arphdr->dipaddr, &ipaddr);
|
||||
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);
|
||||
}
|
||||
#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);
|
||||
|
||||
@ -489,8 +489,8 @@ do_arp(void *buf, int len)
|
||||
hdr->opcode = UIP_HTONS(ARP_REPLY);
|
||||
|
||||
memcpy(&hdr->dhwaddr.addr, &hdr->shwaddr.addr, 6);
|
||||
memcpy(&hdr->shwaddr.addr, &uip_ethaddr.addr, 6);
|
||||
memcpy(&hdr->ethhdr.src.addr, &uip_ethaddr.addr, 6);
|
||||
memcpy(&hdr->shwaddr.addr, &uip_lladdr.addr, 6);
|
||||
memcpy(&hdr->ethhdr.src.addr, &uip_lladdr.addr, 6);
|
||||
memcpy(&hdr->ethhdr.dest.addr, &hdr->dhwaddr.addr, 6);
|
||||
|
||||
uip_ipaddr_copy(&tmpaddr, &hdr->dipaddr);
|
||||
|
Loading…
Reference in New Issue
Block a user