+
+ 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 + MAX_CONF_KEY_LEN + 1); /* +1 for ':' and '\0' */
+ 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", MAX_CONF_KEY_LEN);
+ cur_host->name = strdup(iniparser_getstring(conf, key_buf, NULL));
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "interval", MAX_CONF_KEY_LEN);
+ cur_host->ping_interval = iniparser_getint(conf, key_buf, -1);
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "max_delay", MAX_CONF_KEY_LEN);
+ cur_host->max_delay = iniparser_getint(conf, key_buf, -1);
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "up_cmd", MAX_CONF_KEY_LEN);
+ cur_host->up_cmd = strdup(iniparser_getstring(conf, key_buf, NULL));
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "down_cmd", MAX_CONF_KEY_LEN);
+ cur_host->down_cmd = strdup(iniparser_getstring(conf, key_buf, NULL));
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "start_condition", MAX_CONF_KEY_LEN);
+ const char * value = iniparser_getstring(conf, key_buf, NULL);
+ if (value) cur_host->host_up = *value == 'u' ? true : false;
+
+ 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);