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

WIP: PR for allowing hostnames in config files #42

Open
wants to merge 2 commits into
base: auterion-router-latest
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 10 additions & 2 deletions src/mavlink-router/endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,11 @@ int UdpEndpoint::open(const char *ip, unsigned long port, bool to_bind)
} else {
#endif
sockaddr.sin_family = AF_INET;
sockaddr.sin_addr.s_addr = inet_addr(ip);
struct hostent *server;
server = gethostbyname(ip);
JonasVautherin marked this conversation as resolved.
Show resolved Hide resolved
bcopy((char *)server->h_addr,
(char *)&sockaddr.sin_addr.s_addr,
server->h_length);
sockaddr.sin_port = htons(port);
#ifdef ENABLE_IPV6
}
Expand Down Expand Up @@ -1147,7 +1151,11 @@ int TcpEndpoint::open(const char *ip, unsigned long port)
} else {
#endif
sockaddr.sin_family = AF_INET;
sockaddr.sin_addr.s_addr = inet_addr(ip);
struct hostent *server;
server = gethostbyname(ip);
bcopy((char *)server->h_addr,
(char *)&sockaddr.sin_addr.s_addr,
server->h_length);
sockaddr.sin_port = htons(port);
#ifdef ENABLE_IPV6
}
Expand Down
10 changes: 0 additions & 10 deletions src/mavlink-router/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,14 +797,9 @@ static int parse_confs(ConfFile &conf)
log_error("Expected 'port' key for section %.*s", (int)iter.name_len, iter.name);
ret = -EINVAL;
} else {
if (validate_ip(opt_udp.addr) < 0) {

Choose a reason for hiding this comment

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

What happens now if the ip/hostname is invalid? Does it crash somewhere, or does it just not work? Wouldn't it be nicer to have an error message similar to the one removed here?

Copy link
Author

Choose a reason for hiding this comment

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

Agree that it would be better to keep the validation check, but it looks like the check for valid hostnames can be quite extensive per RFC1123; maybe better to defer it to the hostname lookup stage?

Choose a reason for hiding this comment

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

But then won't it fail in the getaddrinfo call (line 1169)? Shouldn't it print an error message (some log_error()) there? Right now it feels like it just does exit(1), so we won't know what happened from the logs, right? Or did I miss something?

log_error("Invalid IP address in section %.*s: %s", (int)iter.name_len, iter.name, opt_udp.addr);
ret = -EINVAL;
} else {
ret = add_udp_endpoint_address(iter.name + offset, iter.name_len - offset, opt_udp.addr,
opt_udp.port, opt_udp.eavesdropping, opt_udp.filter, opt_udp.coalesce_bytes,
opt_udp.coalesce_ms, opt_udp.coalesce_nodelay, opt_udp.dropout_percentage);
}
}
}

Expand All @@ -823,13 +818,8 @@ static int parse_confs(ConfFile &conf)
ret = conf.extract_options(&iter, option_table_tcp, ARRAY_SIZE(option_table_tcp), &opt_tcp);

if (ret == 0) {
if (validate_ip(opt_tcp.addr) < 0) {
log_error("Invalid IP address in section %.*s: %s", (int)iter.name_len, iter.name, opt_tcp.addr);
ret = -EINVAL;
} else {
ret = add_tcp_endpoint_address(iter.name + offset, iter.name_len - offset, opt_tcp.addr,
opt_tcp.port, opt_tcp.timeout);
}
}
free(opt_tcp.addr);
if (ret < 0)
Expand Down