summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-10-04 17:27:20 +0200
committerThomas Haller <thaller@redhat.com>2017-10-06 11:12:34 +0200
commit7837afe87f0f269c0cc4de1c9c217529d760e83b (patch)
treec0a593a5b1462b5ac89c2dec787be1c005e48e8d
parenta31f1706e5ed4a58f65cd6f77ff3ee86c693d8dd (diff)
downloadNetworkManager-7837afe87f0f269c0cc4de1c9c217529d760e83b.tar.gz
wwan: replace utils function ip4_string_to_num() with nm_utils_parse_inaddr_bin()
One might already question the existance of nm_utils_parse_inaddr_bin(), because it only wraps inet_pton(), which by itself isn't terrible API. The reason nm_utils_parse_inaddr_bin() exists, is to mirror to nm_utils_parse_inaddr() function, which has additional functionality on top of inet_pton(). But we shouldn't have more then one wrapper for inet_pton().
-rw-r--r--src/devices/wwan/nm-modem-broadband.c23
-rw-r--r--src/devices/wwan/nm-modem-ofono.c31
2 files changed, 14 insertions, 40 deletions
diff --git a/src/devices/wwan/nm-modem-broadband.c b/src/devices/wwan/nm-modem-broadband.c
index 9d5475fddd..fbd29b1e24 100644
--- a/src/devices/wwan/nm-modem-broadband.c
+++ b/src/devices/wwan/nm-modem-broadband.c
@@ -863,21 +863,6 @@ set_mm_enabled (NMModem *_self,
/* IPv4 method static */
static gboolean
-ip4_string_to_num (const gchar *str, guint32 *out)
-{
- guint32 addr = 0;
- gboolean success = FALSE;
-
- if (!str || inet_pton (AF_INET, str, &addr) != 1)
- addr = 0;
- else
- success = TRUE;
-
- *out = (guint32)addr;
- return success;
-}
-
-static gboolean
static_stage3_ip4_done (NMModemBroadband *self)
{
GError *error = NULL;
@@ -886,7 +871,7 @@ static_stage3_ip4_done (NMModemBroadband *self)
const gchar *address_string;
const gchar *gw_string;
guint32 address_network;
- guint32 gw;
+ guint32 gw = 0;
NMPlatformIP4Address address;
const gchar **dns;
guint i;
@@ -898,7 +883,7 @@ static_stage3_ip4_done (NMModemBroadband *self)
/* Fully fail if invalid IP address retrieved */
address_string = mm_bearer_ip_config_get_address (self->_priv.ipv4_config);
- if (!ip4_string_to_num (address_string, &address_network)) {
+ if (!nm_utils_parse_inaddr_bin (AF_INET, address_string, &address_network)) {
error = g_error_new (NM_DEVICE_ERROR,
NM_DEVICE_ERROR_INVALID_CONNECTION,
"(%s) retrieving IP4 configuration failed: invalid address given '%s'",
@@ -909,7 +894,7 @@ static_stage3_ip4_done (NMModemBroadband *self)
/* Missing gateway not a hard failure */
gw_string = mm_bearer_ip_config_get_gateway (self->_priv.ipv4_config);
- ip4_string_to_num (gw_string, &gw);
+ nm_utils_parse_inaddr_bin (AF_INET, gw_string, &gw);
data_port = mm_bearer_get_interface (self->_priv.bearer);
g_assert (data_port);
@@ -934,7 +919,7 @@ static_stage3_ip4_done (NMModemBroadband *self)
/* DNS servers */
dns = mm_bearer_ip_config_get_dns (self->_priv.ipv4_config);
for (i = 0; dns && dns[i]; i++) {
- if ( ip4_string_to_num (dns[i], &address_network)
+ if ( nm_utils_parse_inaddr_bin (AF_INET, dns[i], &address_network)
&& address_network > 0) {
nm_ip4_config_add_nameserver (config, address_network);
_LOGI (" DNS %s", dns[i]);
diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c
index 841fefc262..7f43afc9e1 100644
--- a/src/devices/wwan/nm-modem-ofono.c
+++ b/src/devices/wwan/nm-modem-ofono.c
@@ -104,22 +104,6 @@ G_DEFINE_TYPE (NMModemOfono, nm_modem_ofono, NM_TYPE_MODEM)
/*****************************************************************************/
-static gboolean
-ip_string_to_network_address (const gchar *str,
- guint32 *out)
-{
- guint32 addr = 0;
- gboolean success = FALSE;
-
- if (!str || inet_pton (AF_INET, str, &addr) != 1)
- addr = 0;
- else
- success = TRUE;
-
- *out = (guint32)addr;
- return success;
-}
-
static void
get_capabilities (NMModem *_self,
NMDeviceModemCapabilities *modem_caps,
@@ -919,7 +903,8 @@ context_property_changed (GDBusProxy *proxy,
if (g_variant_lookup (v_dict, "Address", "&s", &addr_s)) {
_LOGD ("Address: %s", addr_s);
- if (ip_string_to_network_address (addr_s, &address_network)) {
+ if ( addr_s
+ && nm_utils_parse_inaddr_bin (AF_INET, addr_s, &address_network)) {
addr.address = address_network;
addr.addr_source = NM_IP_CONFIG_SOURCE_WWAN;
} else {
@@ -935,7 +920,8 @@ context_property_changed (GDBusProxy *proxy,
if (g_variant_lookup (v_dict, "Netmask", "&s", &s)) {
_LOGD ("Netmask: %s", s);
- if (s && ip_string_to_network_address (s, &address_network)) {
+ if ( s
+ && nm_utils_parse_inaddr_bin (AF_INET, s, &address_network)) {
prefix = nm_utils_ip4_netmask_to_prefix (address_network);
if (prefix > 0)
addr.plen = prefix;
@@ -953,7 +939,8 @@ context_property_changed (GDBusProxy *proxy,
nm_ip4_config_add_address (priv->ip4_config, &addr);
if (g_variant_lookup (v_dict, "Gateway", "&s", &s)) {
- if (s && ip_string_to_network_address (s, &gateway_network)) {
+ if ( s
+ && nm_utils_parse_inaddr_bin (AF_INET, s, &gateway_network)) {
_LOGI ("Gateway: %s", s);
nm_ip4_config_set_gateway (priv->ip4_config, gateway_network);
} else {
@@ -969,7 +956,8 @@ context_property_changed (GDBusProxy *proxy,
if (g_variant_lookup (v_dict, "DomainNameServers", "^a&s", &array)) {
if (array) {
for (iter = array; *iter; iter++) {
- if (ip_string_to_network_address (*iter, &address_network) && address_network > 0) {
+ if ( nm_utils_parse_inaddr_bin (AF_INET, *iter, &address_network)
+ && address_network) {
_LOGI ("DNS: %s", *iter);
nm_ip4_config_add_nameserver (priv->ip4_config, address_network);
} else {
@@ -991,7 +979,8 @@ context_property_changed (GDBusProxy *proxy,
if (g_variant_lookup (v_dict, "MessageProxy", "&s", &s)) {
_LOGI ("MessageProxy: %s", s);
- if (s && ip_string_to_network_address (s, &address_network)) {
+ if ( s
+ && nm_utils_parse_inaddr_bin (AF_INET, s, &address_network)) {
NMPlatformIP4Route mms_route;
mms_route.network = address_network;