1 /* support functions for ip_pool modules */
8 #include <libippool/ip_pool_support.h>
10 void ip_pool_init(void)
14 ip_pool_t ip_pool_get_index(char *name)
21 fp = fopen(IPPOOL_CONF, "r");
22 if (!fp) exit_error(PARAMETER_PROBLEM,
23 "cannot open %s - no pool names", IPPOOL_CONF);
24 while (fgets(buf, sizeof(buf), fp)) {
25 char *p = strtok(buf, " \t\n");
28 if (!p || *p == '#') continue;
30 p = strtok(0, " \t\n");
31 if (p && 0 == strcmp(p, name)) {
36 exit_error(PARAMETER_PROBLEM,
37 "pool '%s' not found in %s\n", name, IPPOOL_CONF);
40 char *ip_pool_get_name(char *buf, int size, ip_pool_t index, int numeric)
45 /* make sure we have enough room, at least for a %d */
47 exit_error(PARAMETER_PROBLEM,
48 "ip_pool_support:get_name buf too small (%d vs. 16)\n",
52 fp = fopen(IPPOOL_CONF, "r");
54 while (fgets(buf, size, fp)) {
55 char *p = strtok(buf, " \t\n");
57 if (!p || *p == '#') continue;
58 if (index != atoi(p)) continue;
59 p = strtok(0, " \t\n");
60 if (!p || *p == '#') continue;
61 memmove(buf, p, strlen(p)+1);
69 sprintf(buf, "%d", index);