Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
David Graeff committed Apr 6, 2021
1 parent 08c2393 commit b9e01b1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 33 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ enable LLMNR name resolution over IPv6 use:
$ llmnrd -6
```

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

```
$ llmnrd -H a_name -H another_name
Expand Down
51 changes: 26 additions & 25 deletions llmnr.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static bool llmnr_ipv6 = false;
/* Host name in DNS name format (length octet + name + 0 byte) */
#define LLMNR_LABEL_LEN (LLMNR_LABEL_MAX_SIZE + 2)
static char** llmnr_hostnames = NULL;
int llmnr_hostname_count = 0;
size_t llmnr_hostname_count = 0;

static void set_hostname(int entry_index, const char *hostname)
{
Expand All @@ -51,7 +51,7 @@ static void set_hostname(int entry_index, const char *hostname)
llmnr_hostnames[entry_index] = xzalloc(LLMNR_LABEL_LEN);
entry_llmnr_hostname = llmnr_hostnames[entry_index];

entry_llmnr_hostname[0] = strlen(hostname);
entry_llmnr_hostname[0] = (uint8_t)strlen(hostname);
strncpy(&entry_llmnr_hostname[1], hostname, LLMNR_LABEL_MAX_SIZE);
entry_llmnr_hostname[LLMNR_LABEL_MAX_SIZE + 1] = '\0';
}
Expand All @@ -61,44 +61,45 @@ void llmnr_set_hostname(const char *hostname)
set_hostname(0, hostname);
}

void llmnr_init(const char *hostnames[], int hostname_count, bool ipv6)
void llmnr_init(const char *hostnames[], size_t hostname_count, bool ipv6)
{
int name_i = 0;
size_t i;
llmnr_hostname_count = hostname_count;
llmnr_hostnames = xzalloc(hostname_count);
for (;name_i < hostname_count; ++name_i) {
set_hostname(name_i, hostnames[name_i]);
for (i = 0; i < hostname_count; ++i) {
set_hostname(i, hostnames[i]);
}
llmnr_ipv6 = ipv6;
}

void llmnr_release() {
int name_i = 0;
for(; name_i < llmnr_hostname_count; ++name_i) {
free(llmnr_hostnames[name_i]);
void llmnr_release(void)
{
size_t i;
for(i = 0; i < llmnr_hostname_count; ++i) {
free(llmnr_hostnames[i]);
}
free(llmnr_hostnames);
}

/* Return the matched name entry (first byte represents the string length) or NULL */
static char* llmnr_name_matches(const uint8_t *query)
static char *llmnr_name_matches(const uint8_t *query)
{
uint8_t n;
int name_i = 0;
uint8_t n;
size_t i;

for(; name_i < llmnr_hostname_count; ++name_i) {
n = llmnr_hostnames[name_i][0];
for (i = 0; i < llmnr_hostname_count; ++i) {
n = llmnr_hostnames[i][0];

/* length */
if (query[0] != n)
continue;
/* NULL byte */
if (query[1 + n] != 0)
continue;
/* length */
if (query[0] != n)
continue;
/* NULL byte */
if (query[1 + n] != 0)
continue;

if (strncasecmp((const char *)&query[1], &llmnr_hostnames[name_i][1], n) == 0)
return llmnr_hostnames[name_i];
}
if (strncasecmp((const char *) &query[1], &llmnr_hostnames[i][1], n) == 0)
return llmnr_hostnames[i];
}


return NULL;
Expand Down Expand Up @@ -231,7 +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;
char* matched_hostname_entry;

/* Query too short? */
if (len < sizeof(struct llmnr_hdr))
Expand Down
2 changes: 1 addition & 1 deletion llmnr.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <stdbool.h>

void llmnr_set_hostname(const char *hostname);
void llmnr_init(const char *hostnames[], int hostname_count, bool ipv6);
void llmnr_init(const char *hostnames[], size_t hostname_count, bool ipv6);
void llmnr_release(void);
void llmnr_recv(int sock);

Expand Down
10 changes: 5 additions & 5 deletions llmnrd.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ int main(int argc, char **argv)
long num_arg;
bool daemonize = false, ipv6 = false;
char **hostnames = NULL;
int name_count = 0, name_i = 0;
size_t name_count = 0, name_i = 0;
char *iface = NULL;
uint16_t port = LLMNR_UDP_PORT;
int llmnrd_sock_rtnl = -1;
Expand Down Expand Up @@ -270,10 +270,10 @@ int main(int argc, char **argv)
rm_pid_file = true;
}

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

for(name_i = 0; name_i < name_count; ++name_i)
log_info("%s\n", hostnames[name_i]);

if (iface)
log_info("Binding to interface %s\n", iface);
Expand Down

0 comments on commit b9e01b1

Please sign in to comment.