2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-25 15:07:05 +00:00

Use ip_parse() and ipv6_parse() and variants in more places.

This saves some code and improves clarity, in my opinion.

Some of these changes just change an inet_pton() call into a similar
ip_parse() or ipv6_parse() call.  In those cases the benefit is better
type safety, since inet_pton()'s output parameter is type "void *".

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Justin Pettit <jpettit@ovn.org>
This commit is contained in:
Ben Pfaff
2015-12-15 18:04:20 -08:00
parent 2b02db1b4c
commit e769509208
7 changed files with 33 additions and 70 deletions

View File

@@ -151,7 +151,7 @@ addr_is_ipv6(const char *host_name)
int
lookup_ip(const char *host_name, struct in_addr *addr)
{
if (!inet_pton(AF_INET, host_name, addr)) {
if (!ip_parse(host_name, &addr->s_addr)) {
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
VLOG_ERR_RL(&rl, "\"%s\" is not a valid IP address", host_name);
return ENOENT;
@@ -165,7 +165,7 @@ lookup_ip(const char *host_name, struct in_addr *addr)
int
lookup_ipv6(const char *host_name, struct in6_addr *addr)
{
if (inet_pton(AF_INET6, host_name, addr) != 1) {
if (!ipv6_parse(host_name, addr)) {
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
VLOG_ERR_RL(&rl, "\"%s\" is not a valid IPv6 address", host_name);
return ENOENT;
@@ -188,7 +188,7 @@ lookup_hostname(const char *host_name, struct in_addr *addr)
struct addrinfo *result;
struct addrinfo hints;
if (inet_pton(AF_INET, host_name, addr)) {
if (ip_parse(host_name, &addr->s_addr)) {
return 0;
}
@@ -371,14 +371,14 @@ parse_sockaddr_components(struct sockaddr_storage *ss,
sin6->sin6_family = AF_INET6;
sin6->sin6_port = htons(port);
if (!inet_pton(AF_INET6, host_s, sin6->sin6_addr.s6_addr)) {
if (!ipv6_parse(host_s, &sin6->sin6_addr)) {
VLOG_ERR("%s: bad IPv6 address \"%s\"", s, host_s);
goto exit;
}
} else {
sin->sin_family = AF_INET;
sin->sin_port = htons(port);
if (!inet_pton(AF_INET, host_s, &sin->sin_addr.s_addr)) {
if (!ip_parse(host_s, &sin->sin_addr.s_addr)) {
VLOG_ERR("%s: bad IPv4 address \"%s\"", s, host_s);
goto exit;
}