Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove libm dependency #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ CXXFLAGS+= \
-Weffc++

LFLAGS+= \
-flto \
-lm
-flto

ifeq ($(DEBUG),1)
CFLAGS+= \
Expand Down
19 changes: 15 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <arpa/inet.h>
#include <assert.h>
#include <getopt.h>
#include <math.h>
#include <netinet/in.h>
#include <sys/un.h>
#include <sys/types.h>
Expand Down Expand Up @@ -211,7 +210,9 @@ int main(int argc, char** argv) {
srand((unsigned int)time(NULL));

ddhcp_config config;
config.block_size = 32;
unsigned int block_size_pow = 5;

config.block_size = 1 << block_size_pow;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to initialize block_size here at all? Is it used anywhere before l.423?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A quick scan through the source showed no places where this field seems to be read in the affected part of the code. Not tested, but it should be safe to drop that assignment in line 215.

config.claiming_blocks_amount = 0;

inet_aton("10.0.0.0", &config.prefix);
Expand Down Expand Up @@ -266,7 +267,7 @@ int main(int argc, char** argv) {
break;

case 'b':
config.block_size = (uint8_t)(1 << atoi(optarg));
block_size_pow = atoi(optarg);
break;

case 'B':
Expand Down Expand Up @@ -338,6 +339,10 @@ int main(int argc, char** argv) {
ERROR("Are you the internet? CIDR less than 8 seems strange.\n");
exit(1);
}
if (config.prefix_len > 32) {
ERROR("Are you alone? Prefix length larger than address space.\n");
exit(1);
}
} while (0);
break;

Expand Down Expand Up @@ -416,7 +421,13 @@ int main(int argc, char** argv) {
LOG("WARNING: Requested verbosity is higher than maximum supported by this build\n");
}

config.number_of_blocks = (uint32_t)pow(2u, (32u - config.prefix_len - ceil(log2(config.block_size))));
if (32u - config.prefix_len < block_size_pow) {
ERROR("Allocated network not large enough to hold any blocks.");
exit(1);
}

config.number_of_blocks = 1u << (32u - config.prefix_len - block_size_pow);
config.block_size = 1u << block_size_pow;

if (config.disable_dhcp) {
config.spare_leases_needed = 0;
Expand Down