+/* print the results as nslookup would */
+static struct hostent *hostent_fprint(struct hostent *host)
+{
+ if (host) {
+ printf("Name: %s\n", host->h_name);
+ addr_list_fprint(host->h_addr_list);
+ } else {
+ printf("*** Unknown host\n");
+ }
+ return host;
+}
+
+/* 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);
+}
+