From 2973d0c78e9b8eed3c5af239927c6bd36af64604 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Wed, 13 Mar 2019 02:50:42 -0400 Subject: initial commit --- src/dns.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 src/dns.c (limited to 'src/dns.c') diff --git a/src/dns.c b/src/dns.c new file mode 100644 index 0000000..f5eef0f --- /dev/null +++ b/src/dns.c @@ -0,0 +1,130 @@ +#include +#include +#include +#include "uip.h" +#include "uiplib.h" +#include "rs232dev.h" +#include +#include +#include +#include + +#include "telnet.h" +#include "resolv.h" +#include "timer.h" + +#ifndef NULL +#define NULL (void *)0 +#endif /* NULL */ + +char buf[256]; + +int main(void) { + char c; + int i; + uip_ipaddr_t ipaddr; + struct timer periodic_timer; + + timer_set(&periodic_timer, CLOCK_SECOND / 2); + + rs232dev_init(); + uip_init(); + + uip_ipaddr(ipaddr, 192,168,0,2); + uip_sethostaddr(ipaddr); + uip_ipaddr(ipaddr, 192,168,0,1); + uip_setdraddr(ipaddr); + uip_ipaddr(ipaddr, 255,255,255,0); + uip_setnetmask(ipaddr); + + resolv_init(); + uip_ipaddr(ipaddr, 192,168,88,1); + resolv_conf(ipaddr); + + cursor(1); + + while(1) { + puts("DNS test. Hostname:"); + fgets(buf, 256, stdin); + for(i=0; i 0) { + uip_input(); + /* If the above function invocation resulted in data that + should be sent out on the network, the global variable + uip_len is set to a value > 0. */ + if(uip_len > 0) { + rs232dev_send(); + } + } else if(timer_expired(&periodic_timer)) { + timer_reset(&periodic_timer); + for(i = 0; i < UIP_CONNS; i++) { + uip_periodic(i); + /* If the above function invocation resulted in data that + should be sent out on the network, the global variable + uip_len is set to a value > 0. */ + if(uip_len > 0) { + rs232dev_send(); + } + } + +#if UIP_UDP + for(i = 0; i < UIP_UDP_CONNS; i++) { + uip_udp_periodic(i); + /* If the above function invocation resulted in data that + should be sent out on the network, the global variable + uip_len is set to a value > 0. */ + if(uip_len > 0) { + rs232dev_send(); + } + } +#endif /* UIP_UDP */ + } + + if(kbhit()) { + cgetc(); + break; + } + } + } +} + +void telnet_connected(struct telnet_state *s) { +} + +void telnet_closed(struct telnet_state *s) { +} + +void telnet_sent(struct telnet_state *s) { +} + +void telnet_aborted(struct telnet_state *s) { +} + +void telnet_timedout(struct telnet_state *s) { +} + +void telnet_newdata(struct telnet_state *s, char *data, u16_t len) { +} + +void resolv_found(char *name, u16_t *ipaddr) { + if(ipaddr == NULL) { + printf("Host '%s' not found.\n", name); + } else { + printf("Found name '%s' = %d.%d.%d.%d\n", name, + htons(ipaddr[0]) >> 8, + htons(ipaddr[0]) & 0xff, + htons(ipaddr[1]) >> 8, + htons(ipaddr[1]) & 0xff); + puts("Press any key..."); + // webclient_get("www.google.com", 80, "/index.html"); + // webclient_get(name, 80, "/~adam/uip"); + } +} -- cgit v1.2.3