+/* changes a c-string matching the perl regex \d+\.\d+\.\d+\.\d+
+ * into a u_int32_t
+ */
+static u_int32_t str_to_addr(const char *addr)
+{
+ u_int32_t split[4];
+ u_int32_t ip;
+
+ sscanf(addr, "%d.%d.%d.%d",
+ &split[0], &split[1], &split[2], &split[3]);
+
+ /* assuming sscanf worked */
+ ip = (split[0] << 24) |
+ (split[1] << 16) | (split[2] << 8) | (split[3]);
+
+ return htonl(ip);
+}
+
+/* gethostbyaddr wrapper */
+static struct hostent *gethostbyaddr_wrapper(const char *address)
+{
+ struct in_addr addr;
+
+ addr.s_addr = str_to_addr(address);
+ return gethostbyaddr((char *) &addr, 4, AF_INET); /* IPv4 only for now */
+}
+
+#ifdef __UCLIBC__
+#warning FIXME after fixing uClibc to define struct _res
+static inline void server_print(void)
+{
+ printf("Server: %s\n", "default");
+ printf("Address: %s\n\n", "default");
+}
+#else
+/* lookup the default nameserver and display it */
+static inline void server_print(void)
+{
+ struct sockaddr_in def = _res.nsaddr_list[0];
+ char *ip = inet_ntoa(def.sin_addr);
+
+ hostent_fprint(gethostbyaddr_wrapper(ip));
+ printf("\n");
+}
+#endif