aboutsummaryrefslogtreecommitdiffstats
path: root/dyndhcpd.c
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2013-11-14 23:02:02 +0100
committerGravatar Christian Hesse <mail@eworm.de>2013-11-14 23:02:02 +0100
commit2afc18b5b49bfc1e3f21f62b458c367bc6e87bfb (patch)
treed7ab4fcd8f60772e37f375ed9e89742f3e142e9b /dyndhcpd.c
parentf45a34df0be309c62788f6b46024357505863743 (diff)
downloaddyndhcpd-2afc18b5b49bfc1e3f21f62b458c367bc6e87bfb.tar.gz
dyndhcpd-2afc18b5b49bfc1e3f21f62b458c367bc6e87bfb.tar.zst
bail on small networks, serve complete range and exclude self
Diffstat (limited to 'dyndhcpd.c')
-rw-r--r--dyndhcpd.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/dyndhcpd.c b/dyndhcpd.c
index d6743f1..883349d 100644
--- a/dyndhcpd.c
+++ b/dyndhcpd.c
@@ -154,14 +154,14 @@ int main(int argc, char ** argv) {
s_broadcast.s_addr = v_host->s_addr |~ v_mask->s_addr;
s_netaddress.s_addr = v_host->s_addr & v_mask->s_addr;
- if (ntohl(s_broadcast.s_addr) - ntohl(v_host->s_addr) < ntohl(v_host->s_addr) - ntohl(s_netaddress.s_addr)) {
- s_minhost.s_addr = htonl(ntohl(s_netaddress.s_addr) + 1);
- s_maxhost.s_addr = htonl(ntohl(v_host->s_addr) - 1);
- } else {
- s_minhost.s_addr = htonl(ntohl(v_host->s_addr) + 1);
- s_maxhost.s_addr = htonl(ntohl(s_broadcast.s_addr) - 1);
+ if (ntohl(s_broadcast.s_addr) - ntohl(s_netaddress.s_addr) < 2) {
+ fprintf(stderr, "We do not have addresses to serve, need a netmask with 28 bit minimum.\n");
+ return EXIT_FAILURE;
}
+ s_minhost.s_addr = htonl(ntohl(s_netaddress.s_addr) + 1);
+ s_maxhost.s_addr = htonl(ntohl(s_broadcast.s_addr) - 1);
+
if (inet_ntop(AF_INET, &s_broadcast, c_broadcast, INET_ADDRSTRLEN) != NULL &&
inet_ntop(AF_INET, &s_netaddress, c_netaddress, INET_ADDRSTRLEN) != NULL &&
inet_ntop(AF_INET, &s_minhost, c_minhost, INET_ADDRSTRLEN) != NULL &&