+
+ struct host_entry * host_list_end = NULL;
+ for (int i=0; i < host_count; i++) {
+ /* Allocate a reusable buffer large enough to hold the full 'section:key' string. */
+ int section_len = strlen(iniparser_getsecname(conf, i));
+ char * key_buf = malloc(section_len + 1 + MAXCONFKEYLEN + 1);
+ strcpy(key_buf, iniparser_getsecname(conf, i));
+ key_buf[section_len++] = ':';
+
+ struct host_entry * cur_host = malloc(sizeof(struct host_entry));
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "host", MAXCONFKEYLEN);
+ cur_host->name = strdup(iniparser_getstring(conf, key_buf, NULL));
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "interval", MAXCONFKEYLEN);
+ cur_host->ping_interval = iniparser_getint(conf, key_buf, -1);
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "max_delay", MAXCONFKEYLEN);
+ cur_host->max_delay = iniparser_getint(conf, key_buf, -1);
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "up_cmd", MAXCONFKEYLEN);
+ cur_host->up_cmd = strdup(iniparser_getstring(conf, key_buf, NULL));
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "down_cmd", MAXCONFKEYLEN);
+ cur_host->down_cmd = strdup(iniparser_getstring(conf, key_buf, NULL));
+
+ key_buf[section_len] = '\0';
+ /* TODO: Parse for up/down/auto in start_condition. */
+ /* TODO: Do a host up/down check if necessary. */
+ cur_host->host_up = true;
+
+ /* TODO: Do I want to make any checks for start_condition? */
+ if (cur_host->name == NULL || cur_host->ping_interval == -1 || cur_host->max_delay == -1) {
+ fprintf(stderr, "ERROR: Problems parsing section %s.\n", iniparser_getsecname(conf, i));
+ exit(EXIT_FAILURE);
+ }
+
+ cur_host->socket = -1;
+ cur_host->next = NULL;
+ gettimeofday(&(cur_host->last_ping_received), (struct timezone *) NULL);
+
+ if (first_host_in_list == NULL) {
+ first_host_in_list = cur_host;
+ host_list_end = cur_host;
+ } else {
+ host_list_end->next = cur_host;
+ host_list_end = cur_host;
+ }
+
+ free(key_buf);
+ }
+ iniparser_freedict(conf);
+}
+
+/*
+ * Parse string (IP or hostname) to Internet address.
+ *
+ * Returns 0 if host can't be resolved, otherwise returns an Internet address.
+ */
+uint32_t
+get_host_addr(const char * name)
+{
+ struct addrinfo hints;
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_INET;
+
+ int rv;
+ struct addrinfo * address;
+ if ((rv = getaddrinfo(name, NULL, &hints, &address)) != 0) return 0;
+ uint32_t result = ((struct sockaddr_in *)(address->ai_addr))->sin_addr.s_addr;
+ freeaddrinfo(address);
+ return result;