Skip to content

Commit b9e01b1

Browse files
author
David Graeff
committed
Address review comments
1 parent 08c2393 commit b9e01b1

File tree

4 files changed

+34
-33
lines changed

4 files changed

+34
-33
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ enable LLMNR name resolution over IPv6 use:
6464
$ llmnrd -6
6565
```
6666

67-
By default, `llmnrd` respond to name requests matching the systems hostname.
68-
Provide one or more additional names via the `-H` argument:
67+
By default, `llmnrd` responds to name requests matching the systems hostname.
68+
Instead you can provide one or more names via the `-H` argument:
6969

7070
```
7171
$ llmnrd -H a_name -H another_name

llmnr.c

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static bool llmnr_ipv6 = false;
4242
/* Host name in DNS name format (length octet + name + 0 byte) */
4343
#define LLMNR_LABEL_LEN (LLMNR_LABEL_MAX_SIZE + 2)
4444
static char** llmnr_hostnames = NULL;
45-
int llmnr_hostname_count = 0;
45+
size_t llmnr_hostname_count = 0;
4646

4747
static void set_hostname(int entry_index, const char *hostname)
4848
{
@@ -51,7 +51,7 @@ static void set_hostname(int entry_index, const char *hostname)
5151
llmnr_hostnames[entry_index] = xzalloc(LLMNR_LABEL_LEN);
5252
entry_llmnr_hostname = llmnr_hostnames[entry_index];
5353

54-
entry_llmnr_hostname[0] = strlen(hostname);
54+
entry_llmnr_hostname[0] = (uint8_t)strlen(hostname);
5555
strncpy(&entry_llmnr_hostname[1], hostname, LLMNR_LABEL_MAX_SIZE);
5656
entry_llmnr_hostname[LLMNR_LABEL_MAX_SIZE + 1] = '\0';
5757
}
@@ -61,44 +61,45 @@ void llmnr_set_hostname(const char *hostname)
6161
set_hostname(0, hostname);
6262
}
6363

64-
void llmnr_init(const char *hostnames[], int hostname_count, bool ipv6)
64+
void llmnr_init(const char *hostnames[], size_t hostname_count, bool ipv6)
6565
{
66-
int name_i = 0;
66+
size_t i;
6767
llmnr_hostname_count = hostname_count;
6868
llmnr_hostnames = xzalloc(hostname_count);
69-
for (;name_i < hostname_count; ++name_i) {
70-
set_hostname(name_i, hostnames[name_i]);
69+
for (i = 0; i < hostname_count; ++i) {
70+
set_hostname(i, hostnames[i]);
7171
}
7272
llmnr_ipv6 = ipv6;
7373
}
7474

75-
void llmnr_release() {
76-
int name_i = 0;
77-
for(; name_i < llmnr_hostname_count; ++name_i) {
78-
free(llmnr_hostnames[name_i]);
75+
void llmnr_release(void)
76+
{
77+
size_t i;
78+
for(i = 0; i < llmnr_hostname_count; ++i) {
79+
free(llmnr_hostnames[i]);
7980
}
8081
free(llmnr_hostnames);
8182
}
8283

8384
/* Return the matched name entry (first byte represents the string length) or NULL */
84-
static char* llmnr_name_matches(const uint8_t *query)
85+
static char *llmnr_name_matches(const uint8_t *query)
8586
{
86-
uint8_t n;
87-
int name_i = 0;
87+
uint8_t n;
88+
size_t i;
8889

89-
for(; name_i < llmnr_hostname_count; ++name_i) {
90-
n = llmnr_hostnames[name_i][0];
90+
for (i = 0; i < llmnr_hostname_count; ++i) {
91+
n = llmnr_hostnames[i][0];
9192

92-
/* length */
93-
if (query[0] != n)
94-
continue;
95-
/* NULL byte */
96-
if (query[1 + n] != 0)
97-
continue;
93+
/* length */
94+
if (query[0] != n)
95+
continue;
96+
/* NULL byte */
97+
if (query[1 + n] != 0)
98+
continue;
9899

99-
if (strncasecmp((const char *)&query[1], &llmnr_hostnames[name_i][1], n) == 0)
100-
return llmnr_hostnames[name_i];
101-
}
100+
if (strncasecmp((const char *) &query[1], &llmnr_hostnames[i][1], n) == 0)
101+
return llmnr_hostnames[i];
102+
}
102103

103104

104105
return NULL;
@@ -231,7 +232,7 @@ static void llmnr_packet_process(int ifindex, const uint8_t *pktbuf, size_t len,
231232
const uint8_t *query;
232233
size_t query_len;
233234
uint8_t name_len;
234-
char* matched_hostname_entry;
235+
char* matched_hostname_entry;
235236

236237
/* Query too short? */
237238
if (len < sizeof(struct llmnr_hdr))

llmnr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <stdbool.h>
2323

2424
void llmnr_set_hostname(const char *hostname);
25-
void llmnr_init(const char *hostnames[], int hostname_count, bool ipv6);
25+
void llmnr_init(const char *hostnames[], size_t hostname_count, bool ipv6);
2626
void llmnr_release(void);
2727
void llmnr_recv(int sock);
2828

llmnrd.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ int main(int argc, char **argv)
188188
long num_arg;
189189
bool daemonize = false, ipv6 = false;
190190
char **hostnames = NULL;
191-
int name_count = 0, name_i = 0;
191+
size_t name_count = 0, name_i = 0;
192192
char *iface = NULL;
193193
uint16_t port = LLMNR_UDP_PORT;
194194
int llmnrd_sock_rtnl = -1;
@@ -270,10 +270,10 @@ int main(int argc, char **argv)
270270
rm_pid_file = true;
271271
}
272272

273-
log_info("Starting llmnrd on port %u, hostname(s): ", port);
274-
for(name_i = 0; name_i < name_count; ++name_i)
275-
log_info("%s ", hostnames[name_i]);
276-
log_info("\n");
273+
log_info("Starting llmnrd on port %u. Assigned hostname(s):\n", port);
274+
275+
for(name_i = 0; name_i < name_count; ++name_i)
276+
log_info("%s\n", hostnames[name_i]);
277277

278278
if (iface)
279279
log_info("Binding to interface %s\n", iface);

0 commit comments

Comments
 (0)