diff --git a/THANKS b/THANKS
index 4bb123d..8fe47e0 100644
--- a/THANKS
+++ b/THANKS
@@ -49,3 +49,4 @@ Mark Sangster
Brent Swingle
Mathieu Morier
Jean Benoit
+Belkacem Daheb
diff --git a/src/dhcpd-pools.h b/src/dhcpd-pools.h
index 0f93b80..aff6b6a 100644
--- a/src/dhcpd-pools.h
+++ b/src/dhcpd-pools.h
@@ -102,6 +102,9 @@ enum prefix_t {
PREFIX_BINDING_STATE_ACTIVE,
PREFIX_BINDING_STATE_BACKUP,
PREFIX_HARDWARE_ETHERNET,
+ PREFIX_STARTS,
+ PREFIX_ENDS,
+ PREFIX_HOSTNAME,
NUM_OF_PREFIX
};
@@ -180,6 +183,9 @@ struct leases_t {
char *ethernet;
UT_hash_handle hh;
enum ltype type;
+ char *ends;
+ char *starts;
+ char *hostname;
};
/*! \enum limbits
diff --git a/src/getdata.c b/src/getdata.c
index 7863a6b..966fe5d 100644
--- a/src/getdata.c
+++ b/src/getdata.c
@@ -83,7 +83,7 @@ enum isc_conf_parser {
int parse_leases(struct conf_t *state)
{
FILE *dhcpd_leases;
- char *line, *ipstring, macstring[20], *stop;
+ char *line, *ipstring, macstring[20], *stop, endsstr[30], startsstr[30], hostnamestr[MAXLEN];
union ipaddr_t addr;
struct leases_t *lease;
@@ -100,6 +100,9 @@ int parse_leases(struct conf_t *state)
line[0] = '\0';
ipstring = xmalloc(sizeof(char) * MAXLEN);
ipstring[0] = '\0';
+ endsstr[0] = '\0';
+ startsstr[0] = '\0';
+ hostnamestr[0] = '\0';
while (!feof(dhcpd_leases)) {
if (!fgets(line, MAXLEN, dhcpd_leases) && ferror(dhcpd_leases))
error(EXIT_FAILURE, errno, "parse_leases: %s", state->dhcpdlease_file);
@@ -142,8 +145,32 @@ int parse_leases(struct conf_t *state)
break;
memcpy(macstring, line + 20, 17);
macstring[17] = '\0';
- if ((lease = find_lease(state, &addr)) != NULL)
+ if ((lease = find_lease(state, &addr)) != NULL) {
lease->ethernet = xstrdup(macstring);
+ lease->starts = xstrdup(startsstr);
+ lease->ends = xstrdup(endsstr);
+ }
+ break;
+ case PREFIX_ENDS:
+ if (state->print_mac_addreses == 0)
+ break;
+ strncpy(endsstr, line + 7, sizeof(endsstr)-1);
+ endsstr[strlen(endsstr)-2] = '\0';
+ break;
+ case PREFIX_STARTS:
+ if (state->print_mac_addreses == 0)
+ break;
+ strncpy(startsstr, line + 9, sizeof(startsstr)-1);
+ startsstr[strlen(startsstr)-2] = '\0';
+ break;
+ case PREFIX_HOSTNAME:
+ if (state->print_mac_addreses == 0)
+ break;
+ strncpy(hostnamestr, line + 19, sizeof(hostnamestr)-1);
+ hostnamestr[strlen(hostnamestr)-3] = '\0';
+ if ((lease = find_lease(state, &addr)) != NULL) {
+ lease->hostname = xstrdup(hostnamestr);
+ }
break;
default:
/* do nothing */ ;
diff --git a/src/hash.c b/src/hash.c
index 77ecd79..eb434df 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -66,6 +66,9 @@ void add_lease_v4(struct conf_t *state, union ipaddr_t *addr, enum ltype type)
l->type = type;
HASH_ADD_INT(state->leases, ip.v4, l);
l->ethernet = NULL;
+ l->ends = NULL;
+ l->starts = NULL;
+ l->hostname = NULL;
}
void add_lease_v6(struct conf_t *state, union ipaddr_t *addr, enum ltype type)
@@ -77,6 +80,9 @@ void add_lease_v6(struct conf_t *state, union ipaddr_t *addr, enum ltype type)
l->type = type;
HASH_ADD_V6(state->leases, ip.v6, l);
l->ethernet = NULL;
+ l->ends = NULL;
+ l->starts = NULL;
+ l->hostname = NULL;
}
/*! \brief Find pointer to lease from hash array.
@@ -110,6 +116,9 @@ struct leases_t *find_lease_v6(struct conf_t *state, union ipaddr_t *addr)
void delete_lease(struct conf_t *state, struct leases_t *lease)
{
free(lease->ethernet);
+ free(lease->ends);
+ free(lease->starts);
+ free(lease->hostname);
HASH_DEL(state->leases, lease);
free(lease);
}
@@ -122,6 +131,9 @@ void delete_all_leases(struct conf_t *state)
HASH_ITER(hh, state->leases, l, tmp) {
free(l->ethernet);
+ free(l->ends);
+ free(l->starts);
+ free(l->hostname);
HASH_DEL(state->leases, l);
free(l);
}
@@ -134,6 +146,9 @@ void delete_all_leases(struct conf_t *state)
l = state->leases;
free(l->ethernet);
+ free(l->ends);
+ free(l->starts);
+ free(l->hostname);
HASH_DEL(state->leases, l); /* leases advances to next on delete */
free(l);
}
diff --git a/src/other.c b/src/other.c
index 21a19f4..b319a2d 100644
--- a/src/other.c
+++ b/src/other.c
@@ -417,6 +417,12 @@ int
}
if (!memcmp("lease ", str, 6))
return PREFIX_LEASE;
+ else if (!memcmp(" starts ", str, 9))
+ return PREFIX_STARTS;
+ else if (!memcmp(" ends ", str, 7))
+ return PREFIX_ENDS;
+ else if (!memcmp(" client-hostname ", str, 18))
+ return PREFIX_HOSTNAME;
return NUM_OF_PREFIX;
}
@@ -472,6 +478,12 @@ int
}
if (!memcmp(" iaaddr ", str, 9))
return PREFIX_LEASE;
+ else if (!memcmp(" starts ", str, 9))
+ return PREFIX_STARTS;
+ else if (!memcmp(" ends ", str, 7))
+ return PREFIX_ENDS;
+ else if (!memcmp(" client-hostname ", str, 18))
+ return PREFIX_HOSTNAME;
return NUM_OF_PREFIX;
}
diff --git a/src/output.c b/src/output.c
index 4cd0226..17745d4 100644
--- a/src/output.c
+++ b/src/output.c
@@ -387,7 +387,19 @@ static int output_xml(struct conf_t *state)
if (l->ethernet != NULL) {
fputs(l->ethernet, outfile);
}
- fputs("\n\n", outfile);
+ fputs("\n\t", outfile);
+ if (l->starts != NULL) {
+ fputs(l->starts, outfile);
+ }
+ fputs("\n\t", outfile);
+ if (l->ends != NULL) {
+ fputs(l->ends, outfile);
+ }
+ fputs("\n\t", outfile);
+ if (l->hostname != NULL) {
+ fputs(l->hostname, outfile);
+ }
+ fputs("\n\n", outfile);
}
}
}
@@ -481,6 +493,18 @@ static int output_json(struct conf_t *state)
if (l->ethernet != NULL) {
fputs(l->ethernet, outfile);
}
+ fputs("\", \"starts\":\"", outfile);
+ if (l->starts != NULL) {
+ fputs(l->starts, outfile);
+ }
+ fputs("\", \"ends\":\"", outfile);
+ if (l->ends != NULL) {
+ fputs(l->ends, outfile);
+ }
+ fputs("\", \"hostname\":\"", outfile);
+ if (l->hostname != NULL) {
+ fputs(l->hostname, outfile);
+ }
fputs("\" }", outfile);
}
}
diff --git a/tests/expected/same-twice-json b/tests/expected/same-twice-json
index f572972..f23d1b0 100644
--- a/tests/expected/same-twice-json
+++ b/tests/expected/same-twice-json
@@ -1,6 +1,6 @@
{
"active_leases": [
- { "ip":"10.0.0.5", "macaddress":"00:00:00:00:00:00" }
+ { "ip":"10.0.0.5", "macaddress":"00:00:00:00:00:00", "starts":"", "ends":"", "hostname":"" }
],
"subnets": [
{ "location":"All networks", "range":"10.0.0.1 - 10.0.0.10", "first_ip":"10.0.0.1", "last_ip":"10.0.0.10", "defined":10, "used":1, "touched":0, "free":9, "percent":10, "touch_count":1, "touch_percent":10, "status":0 }
diff --git a/tests/expected/same-twice-xml b/tests/expected/same-twice-xml
index 93612d6..7897f7f 100644
--- a/tests/expected/same-twice-xml
+++ b/tests/expected/same-twice-xml
@@ -2,6 +2,9 @@
10.0.0.5
00:00:00:00:00:00
+
+
+
All networks