--- /dev/null
+/*\r
+ * DNS Resolver\r
+ */\r
+#include <acess/sys.h>\r
+#include <stdio.h>\r
+#include <net.h>\r
+\r
+// === CONSTANTS ===\r
+#define NAMESERVER {10,0,2,3}\r
+\r
+uint8_t packet[] = {\r
+ // --- UDP header\r
+ 53, 0, // Dest port\r
+ 4, 0, // IPv4\r
+ 10,0,2,3, // Dest address\r
+ // --- DNS Packet\r
+ 0x13,0x37,\r
+ 0x01, // Recursion Desired\r
+ 0x00,\r
+ 0,1, // QDCOUNT\r
+ 0,0,\r
+ 0,0,\r
+ 0,0, // ARCOUNT\r
+ \r
+ #if 0\r
+ // www.mutabah.net, A, IN\r
+ 3,'w','w','w',\r
+ 7,'m','u','t','a','b','a','h',\r
+ 3,'n','e','t',\r
+ #else\r
+ // mussel.ucc.asn.au, A, IN\r
+ 6,'m','u','s','s','e','l',\r
+ 3,'u','c','c',\r
+ 3,'a','s','n',\r
+ 2,'a','u',\r
+ #endif\r
+ 0,\r
+ 0,1, // A\r
+ 0,1 // IN\r
+ };\r
+\r
+// === TYPES ===\r
+typedef struct sDNSPacket\r
+{\r
+ uint16_t ID;\r
+ // 1: Query/Response, 4: Opcode, 1: Authorative Answer, 1: Truncation, 1: Recursion Denied\r
+ uint8_t opcode;\r
+ uint8_t rcode; // 1: Recusions Desired, 3: Zero, 4: Response Code\r
+ uint16_t qdcount; // Question Count\r
+ uint16_t ancount; // Answer Count\r
+ uint16_t nscount; // Nameserver Resource Count\r
+ uint16_t arcount; // Additional Records count\r
+} tDNSPacket;\r
+\r
+// === PROTOTYPES ===\r
+\r
+// ==== CODE ====\r
+int main(int argc, char *argv[], char *envp[])\r
+{\r
+ int fd, tmp;\r
+ uint16_t port = 53;\r
+ uint8_t destip[4] = NAMESERVER;\r
+ uint8_t buf[512];\r
+ tDNSPacket *hdr = (void *) (buf + 4 + 4);\r
+\r
+ fd = Net_OpenSocket(4, destip, "udp");\r
+ if( fd == -1 ) {\r
+ fprintf(stderr, "Unable to create a UDP socket\n");\r
+ return 0;\r
+ }\r
+ port = 0; ioctl(fd, ioctl(fd, 3, "getset_localport"), &port);\r
+ port = 53; ioctl(fd, ioctl(fd, 3, "getset_remoteport"), &port);\r
+ ioctl(fd, ioctl(fd, 3, "set_remoteaddr"), &destip);\r
+ tmp = 32; ioctl(fd, ioctl(fd, 3, "getset_remotemask"), &tmp);\r
+ \r
+ write(fd, sizeof(packet), packet);\r
+ read(fd, 512, buf);\r
+ \r
+ printf("hdr = {\n");\r
+ printf(" .ID = 0x%04x\n", hdr->ID);\r
+ printf(" .opcode = 0x%04x\n", hdr->opcode);\r
+ printf(" .rcode = 0x%02x\n", hdr->rcode);\r
+ printf(" .qdcount = 0x%04x\n", hdr->qdcount);\r
+ printf(" .ancount = 0x%04x\n", hdr->ancount);\r
+ printf(" .nscount = 0x%04x\n", hdr->nscount);\r
+ printf(" .arcount = 0x%04x\n", hdr->arcount);\r
+ printf("}\n");\r
+ \r
+ \r
+ close(fd);\r
+ return 0;\r
+}\r