2 * Acess2 Networking Toolkit
3 * By John Hodge (thePowersGang)
6 * - Hostname<->Address resolution
8 #include <stddef.h> // size_t / NULL
9 #include <stdint.h> // uint*_t
10 #include <string.h> // memcpy, strchr
12 #include <acess/sys.h> // for _SysSelect
13 #include <acess/fd_set.h> // FD_SET
15 #include "include/dns.h"
16 #include "include/dns_int.h"
19 //int DNS_Query(int ServerAType, const void *ServerAddr, const char *name, enum eTypes type, enum eClass class, handle_record_t* handle_record, void *info);
22 int DNS_Query(int ServerAType, const void *ServerAddr, const char *name, enum eTypes type, enum eClass class, handle_record_t* handle_record, void *info)
25 size_t packlen = DNS_int_EncodeQuery(packet, sizeof(packet), name, type, class);
27 // Send and wait for reply
29 // > TODO: Lock DNS queries
31 int sock = Net_OpenSocket_UDP(ServerAType, ServerAddr, 53, 0);
34 _SysDebug("DNS_Query - UDP open failed");
35 // TODO: Correctly report this failure with a useful error code
38 int rv = Net_UDP_SendTo(sock, 53, ServerAType, ServerAddr, pos, packet);
40 _SysDebug("DNS_Query - Write failed");
41 // TODO: Error reporting
51 int64_t timeout = 2000; // Give it two seconds, should be long enough
52 rv = _SysSelect(nfd, &fds, NULL, NULL, &timeout, 0);
54 // Timeout with no reply, give up
55 _SysDebug("DNS_Query - Timeout");
60 // Oops, select failed
61 _SysDebug("DNS_Query - Select failure");
66 int return_len = Net_UDP_RecvFrom(sock, NULL, NULL, NULL, sizeof(packet), packet);
67 if( return_len <= 0 ) {
68 // TODO: Error reporting
69 _SysDebug("DNS_Query - Read failure");
75 // > TODO: Lock DNS queries
77 // For each response in the answer (and additional) sections, call the passed callback
78 return DNS_int_ParseResponse(packet, return_len, info, handle_record);