mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-18 08:47:00 +00:00
Version 2.10
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
573418a9e4
commit
e4282e8a3d
40 changed files with 4398 additions and 22737 deletions
|
|
@ -45,6 +45,9 @@ extern char *malloc();
|
|||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#define _XOPEN_SOURCE 600
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "dhcpd-pools.h"
|
||||
#include "defaults.h"
|
||||
|
|
@ -65,7 +68,16 @@ int parse_leases(void)
|
|||
eprintf("parse_leases: %s:", config.dhcpdlease_file);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
posix_fadvise((long) dhcpd_leases, 0, 0, POSIX_FADV_NOREUSE);
|
||||
if (errno) {
|
||||
eprintf("parse_leases: fadvise:");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
posix_fadvise((long) dhcpd_leases, 0, 0, POSIX_FADV_SEQUENTIAL);
|
||||
if (errno) {
|
||||
eprintf("parse_leases: fadvise:");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
/* I found out that there's one lease address per 300 bytes in
|
||||
* dhcpd.leases file. Malloc is little bit pessimistic and uses
|
||||
* 250. If someone has higher density in lease file I'm
|
||||
|
|
@ -86,24 +98,20 @@ int parse_leases(void)
|
|||
|
||||
while (!feof(dhcpd_leases)) {
|
||||
fgets(line, MAXLEN, dhcpd_leases);
|
||||
/* It's a lease */
|
||||
/* It's a lease, save IP */
|
||||
if (strstr(line, "lease") == line) {
|
||||
strncpy(ipstring, line, (size_t) MAXLEN - 1);
|
||||
}
|
||||
/* And this is lease state which we are interested about */
|
||||
else if (strstr(line, "binding state active")) {
|
||||
strncpy(ipstring, line, (size_t) MAXLEN);
|
||||
nth_field(2, ipstring, ipstring);
|
||||
inet_aton(ipstring, &inp);
|
||||
}
|
||||
/* Copy IP to correct array */
|
||||
else if (strstr(line, "binding state active")) {
|
||||
leases[num_leases] = htonl(inp.s_addr);
|
||||
num_leases++;
|
||||
} else if (strstr(line, " binding state free")) {
|
||||
nth_field(2, ipstring, ipstring);
|
||||
inet_aton(ipstring, &inp);
|
||||
touches[num_touches] = htonl(inp.s_addr);
|
||||
num_touches++;
|
||||
} else if (strstr(line, " binding state backup")) {
|
||||
nth_field(2, ipstring, ipstring);
|
||||
inet_aton(ipstring, &inp);
|
||||
if (num_backups == 0) {
|
||||
backups =
|
||||
safe_malloc((size_t) sizeof(long int) *
|
||||
|
|
@ -125,9 +133,11 @@ int parse_leases(void)
|
|||
* come. */
|
||||
int nth_field(int n, char *dest, const char *src)
|
||||
{
|
||||
int i, j = 0, wordn = 0;
|
||||
int i, j = 0, wordn = 0, len;
|
||||
|
||||
for (i = 0; i < MAXLEN; i++) {
|
||||
len = strlen(src);
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if (isspace(src[i])) {
|
||||
if (!(wordn < n)) {
|
||||
dest[j] = '\0';
|
||||
|
|
@ -188,6 +198,16 @@ char *parse_config(char *config_file, char *current_shared_name,
|
|||
eprintf("parse_config: %s:", config_file);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
posix_fadvise((long) dhcpd_config, 0, 0, POSIX_FADV_NOREUSE);
|
||||
if (errno) {
|
||||
eprintf("parse_config: fadvise:");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
posix_fadvise((long) dhcpd_config, 0, 0, POSIX_FADV_SEQUENTIAL);
|
||||
if (errno) {
|
||||
eprintf("parse_config: fadvise:");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Very hairy stuff begins. */
|
||||
while (!feof(dhcpd_config)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue