shared: add nm_utils_parse_inaddr_bin_full() to support legacy IPv4 formats as inet_aton()

inet_aton() also supports IPv4 addresses in octal (with a leading '0')
or where not all 4 digits of the address are present.

Add nm_utils_parse_inaddr_bin_full() to optionally fallback to
parse the address with inet_aton().

Note taht inet_aton() also supports all crazy formats, including
ignoring trailing garbage after a whitespace. We don't want to accept
that in general.

Note that even in legacy format we:

  - accept everything that inet_pton() would accept

  - additionally, we also accept some forms which inet_aton() would
    accept, but not all.

That means, the legacy format that we accept is a superset of
inet_pton() and a subset of inet_aton(). Which is desirable.
This commit is contained in:
Thomas Haller
2019-09-03 13:49:47 +02:00
parent 06a976358b
commit 8fbf67d138
2 changed files with 106 additions and 10 deletions

View File

@@ -542,10 +542,19 @@ gboolean nm_utils_ip_is_site_local (int addr_family,
/*****************************************************************************/
gboolean nm_utils_parse_inaddr_bin (int addr_family,
const char *text,
int *out_addr_family,
gpointer out_addr);
gboolean nm_utils_parse_inaddr_bin_full (int addr_family,
gboolean accept_legacy,
const char *text,
int *out_addr_family,
gpointer out_addr);
static inline gboolean
nm_utils_parse_inaddr_bin (int addr_family,
const char *text,
int *out_addr_family,
gpointer out_addr)
{
return nm_utils_parse_inaddr_bin_full (addr_family, FALSE, text, out_addr_family, out_addr);
}
gboolean nm_utils_parse_inaddr (int addr_family,
const char *text,