1 /*
2 * dns.c dependecy injection -- preincluded to inject interface test functions into static variables
3 *
4 */
5 #include "no_warn_host.h"
6
7 #include "lwip/opt.h"
8 #include "lwip/udp.h"
9 #include "lwip/mem.h"
10 #include "lwip/memp.h"
11 #include "lwip/dns.h"
12 #include "lwip/ip_addr.h"
13
14 #define ipaddr_aton(cp, addr) ip4addr_aton(cp, addr)
15
16 extern uint32_t g_random_numbers[8];
17 extern uint32_t g_random_numbers_cnt;
18
19 #ifndef BUILDING_DEF
20
__assert_func(const char * file,int line,const char * func,const char * expr)21 void __assert_func(const char *file, int line, const char *func, const char *expr)
22 {
23 printf("Assert failed in %s, %s:%d (%s)", func, file, line, expr);
24 abort();
25 }
26
ip4addr_aton(const char * cp,ip4_addr_t * addr)27 int ip4addr_aton(const char *cp, ip4_addr_t *addr)
28 {
29 return 0;
30 }
31
32 static err_t dns_enqueue(const char *name, size_t hostnamelen, dns_found_callback found, void *callback_arg, u8_t dns_addrtype);
33 static void dns_recv(void *s, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port);
34
35 void (*dns_test_static_dns_recv)(void *s, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) = NULL;
36 err_t (*dns_test_static_dns_enqueue)(const char *name, size_t hostnamelen, dns_found_callback found, void *callback_arg, u8_t dns_addrtype) = NULL;
37
dns_test_init_di(void)38 void dns_test_init_di(void)
39 {
40 dns_test_static_dns_recv = dns_recv;
41 dns_test_static_dns_enqueue = dns_enqueue;
42 }
43
44
dns_test_dns_enqueue(const char * name,size_t hostnamelen,dns_found_callback found,void * callback_arg,u8_t dns_addrtype)45 err_t dns_test_dns_enqueue(const char *name, size_t hostnamelen, dns_found_callback found, void *callback_arg, u8_t dns_addrtype)
46 {
47 return dns_test_static_dns_enqueue(name, hostnamelen, found, callback_arg, dns_addrtype);
48 }
49
dns_test_dns_recv(void * s,struct udp_pcb * pcb,struct pbuf * p,const ip_addr_t * addr,u16_t port)50 void dns_test_dns_recv(void *s, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
51 {
52 dns_test_static_dns_recv(s, pcb, p, addr, port);
53 }
54
dns_test_inject_port_and_txid(int port,int txid)55 void dns_test_inject_port_and_txid(int port, int txid)
56 {
57 // inject random numbers
58 g_random_numbers[0] = port; //for port
59 g_random_numbers[1] = txid; //for txid
60 g_random_numbers_cnt = 0; // let's start with the port
61 }
62 #endif
63