Adding to README, adding in new code for reading to a host in file
This commit is contained in:
parent
258e2c8de3
commit
8935ad2e54
@ -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.
|
1. Get delete working for my /etc/hosts editor.
|
||||||
2. Daemonize this program to be started up by systemd.
|
2. Daemonize this program to be started up by systemd.
|
||||||
- As part of daemonization, remember and remove added hosts on teardown.
|
- 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
21
main.c
@ -5,6 +5,10 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.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 ";
|
const char *blockString = "0.0.0.0 ";
|
||||||
|
|
||||||
FILE *fopenHostsFile(int mode)
|
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.
|
* Entrypoint.
|
||||||
*/
|
*/
|
||||||
@ -95,4 +114,4 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
if (hostsFile != NULL)
|
if (hostsFile != NULL)
|
||||||
fclose(hostsFile);
|
fclose(hostsFile);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user