Adding to README, adding in new code for reading to a host in file

This commit is contained in:
Jacob Windle 2019-04-17 14:57:07 -04:00
parent 258e2c8de3
commit 8935ad2e54
2 changed files with 22 additions and 2 deletions

View File

@ -13,4 +13,5 @@ I would like to get better with C, and will be using C much more in the near fut
1. Get delete working for my /etc/hosts editor.
2. Daemonize this program to be started up by systemd.
- As part of daemonization, remember and remove added hosts on teardown.
3. Log dns requests that look at the hosts file -- To see how many go where
3. Log dns requests that look at the hosts file -- To see how many go where
4. As part of daemonization -- only block hosts within a time limit.

21
main.c
View File

@ -5,6 +5,10 @@
#include <sys/types.h>
#include <sys/wait.h>
/**
* TODO - daemonize, add in reading of config file,
* block sites within a certain time limit.
*/
const char *blockString = "0.0.0.0 ";
FILE *fopenHostsFile(int mode)
@ -59,6 +63,21 @@ void showHosts()
}
}
void readToHost(char *host, FILE *hostsFile)
{
char buf[256];
char *ptr;
while ((fgets(buf, 256, hostsFile)) != NULL)
{
ptr = strcasestr(host, buf);
if (ptr != NULL)
break;
}
// FILE should be read to the host itself.
}
/**
* Entrypoint.
*/
@ -95,4 +114,4 @@ int main(int argc, char **argv)
if (hostsFile != NULL)
fclose(hostsFile);
}
}