-
Notifications
You must be signed in to change notification settings - Fork 20
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
Allow to provide multiple host names #39
base: master
Are you sure you want to change the base?
Conversation
1e51de4
to
08c2393
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Haven't looked at the PR in detail yet, a few minor comments inline.
Please also add a commit message (not just a PR description) and also add Fixes #38
to it.
I'll give this a closer look some time later this week.
4f51b53
to
b9e01b1
Compare
RFC 4795 allows an IP to be represented by not just one but multiple names. The "--hostname" / "-H" parameter can be given multiple times now. The use of a dynamic array of host names require a new public API method: `llmnr_release(void)` Keep llmnr_set_hostname function signature. This will always only update the first entry and is mainly used when no --hostname parameter has been provided and llmnrd reacts to system hostname changes. API changes: * Adapt llmnr_init to take an array of host name strings. Signed-off-by: David Graeff <[email protected]>
b9e01b1
to
c432935
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay with reviewing this. Some more comments inline, mostly minor formatting nits (yes, I should add a .clang-format
file 😃).
In addition to README.md
, please also update the usage of the -H
option (i.e. that it can be specified multiple times) in the llmnrd.1
man page and in the in-program usage text.
size_t i; | ||
llmnr_hostname_count = hostname_count; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an empty line after variable declaration:
size_t i; | |
llmnr_hostname_count = hostname_count; | |
size_t i; | |
llmnr_hostname_count = hostname_count; |
llmnr_set_hostname(hostname); | ||
size_t i; | ||
llmnr_hostname_count = hostname_count; | ||
llmnr_hostnames = xzalloc(hostname_count); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should allocate hostname_count * sizeof(*llmnr_hostnames)
.
static char llmnr_hostname[LLMNR_LABEL_MAX_SIZE + 2]; | ||
#define LLMNR_LABEL_LEN (LLMNR_LABEL_MAX_SIZE + 2) | ||
static char** llmnr_hostnames = NULL; | ||
size_t llmnr_hostname_count = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this static
, it's not used outside the file.
size_t i; | ||
for(i = 0; i < llmnr_hostname_count; ++i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an empty line after variable declaration and add a space after the for
keyword:
size_t i; | |
for(i = 0; i < llmnr_hostname_count; ++i) { | |
size_t i; | |
for (i = 0; i < llmnr_hostname_count; ++i) { |
uint8_t n; | ||
n = llmnr_hostnames[i][0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assign this on declaration:
uint8_t n; | |
n = llmnr_hostnames[i][0]; | |
uint8_t n = llmnr_hostnames[i][0]; |
@@ -196,6 +232,7 @@ static void llmnr_packet_process(int ifindex, const uint8_t *pktbuf, size_t len, | |||
const uint8_t *query; | |||
size_t query_len; | |||
uint8_t name_len; | |||
char* matched_hostname_entry; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
char* matched_hostname_entry; | |
const char* matched_hostname; |
/* First count given (host)names, if any, to allocate memory */ | ||
while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) { | ||
if (c == 'H') | ||
++name_count; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like the idea of iterating the options twice. But I guess there is no alternative to this :-(
|
||
if (!name_count) | ||
name_count = 1; | ||
hostnames = xzalloc(name_count); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should allocate name_count * sizeof(*hostnames)
.
@@ -332,7 +349,11 @@ int main(int argc, char **argv) | |||
close(llmnrd_sock_ipv6); | |||
if (llmnrd_sock_ipv4 >= 0) | |||
close(llmnrd_sock_ipv4); | |||
free(hostname); | |||
for(name_i = 0; name_i < name_count; ++name_i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a space after the for
keyword:
for(name_i = 0; name_i < name_count; ++name_i) { | |
for (name_i = 0; name_i < name_count; ++name_i) { |
log_info("Starting llmnrd on port %u, hostname %s\n", port, hostname); | ||
log_info("Starting llmnrd on port %u. Assigned hostname(s):\n", port); | ||
|
||
for(name_i = 0; name_i < name_count; ++name_i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a space after the for keyword:
for(name_i = 0; name_i < name_count; ++name_i) | |
for (name_i = 0; name_i < name_count; ++name_i) |
Allow to provide multiple host names
void llmnr_release(void);
method for string array cleanupllmnr_set_hostname
function signature. This will always only update the first entry.llmnr_init
to take an array of host name strings.Fixes #38