--- dnswatch.c.orig 2010-07-20 21:04:39.000000000 +0200 +++ dnswatch.c 2010-07-20 21:06:27.000000000 +0200 @@ -44,6 +44,10 @@ #include #include + +#define LINE_LENGTH 128 +#define NUMHOSTS 128 + /* Resolves each host name in a given list at regular intervals, and runs a command whenever any of them resolves to a different IP address than @@ -92,10 +96,11 @@ int interval; char *file; char *command; - properties list, props; + char line[LINE_LENGTH]; + char *p; struct in_addr *ips; - int fd; FILE *pidfd; + FILE *fp; if (argc > 5 || argc < 4) usage(); @@ -121,45 +126,46 @@ } // Attempt to open configuration file which lists hosts - fd = open(file, O_RDONLY); - if (fd == -1) { + if ((fp=fopen(file, "r")) == NULL) { syslog(LOG_ERR, "unable to open configuration file '%s'", file); exit(1); } // Read hostnames in that are in the configuration file - props = properties_read(fd); - if (props == NULL) { - syslog(LOG_ERR, "error reading configuration file"); - exit(1); + int count = 0; + char **hostlist = malloc(NUMHOSTS * sizeof(char *)); + if (hostlist == NULL) { + fprintf(stderr, "malloc failed\n"); + exit(2); } - - // Close open file handle for dnswatch configuration - close(fd); - - int hosts = 1; - list = props; - while (list != NULL) { - list = list->next; - hosts++; + while(fgets(line, sizeof line, fp) != NULL) { + p = strchr(line, '\n'); + if (p) { + *p = '\0'; + } + hostlist[count] = malloc(strlen(line)); + strcpy(hostlist[count], line); + count++; } + // Close open file handle for dnswatch configuration + fclose(fp); + // Create a place to hold resolved ip addresses - ips = calloc(hosts, sizeof(struct in_addr)); + ips = calloc(count, sizeof(struct in_addr)); if (ips == NULL) { fprintf(stderr, "calloc failed\n"); exit(2); } + // Loop forever checking to see if a hostname changes while (1) { int i = 0; int changes = 0; - list = props; - while (list != NULL) { - changes += check_hostname(list->name, &ips[i]); - list = list->next; - i++; + for (i = 0; i