Commit 7837afe8 authored by Thomas Haller's avatar Thomas Haller
Browse files

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().
parent a31f1706
......@@ -862,21 +862,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)
{
......@@ -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]);
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment