aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-08-31 13:54:48 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-08-31 15:11:29 +0200
commit529eecdb9771cbb9140af015e4a8a5fdb3df59a7 (patch)
tree9ac5c6409d2db50cdf4685dba842d1eaab707401
parentab7f558a2c6376396c021d57175c6faaba57554c (diff)
modem-helpers: new helper to convert from netmask string to CIDR
-rw-r--r--src/mm-modem-helpers.c12
-rw-r--r--src/mm-modem-helpers.h2
2 files changed, 14 insertions, 0 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index 4c93045b..e595c45b 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -22,6 +22,7 @@
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
+#include <arpa/inet.h>
#include <ModemManager.h>
#include <libmm-common.h>
@@ -135,6 +136,17 @@ mm_create_device_identifier (guint vid,
/*****************************************************************************/
+guint
+mm_netmask_to_cidr (const gchar *netmask)
+{
+ guint32 num = 0;
+
+ inet_pton (AF_INET, netmask, &num);
+ return mm_count_bits_set (num);
+}
+
+/*****************************************************************************/
+
/* +CREG: <stat> (GSM 07.07 CREG=1 unsolicited) */
#define CREG1 "\\+(CREG|CGREG):\\s*0*([0-9])"
diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h
index 4754e7f9..26169e97 100644
--- a/src/mm-modem-helpers.h
+++ b/src/mm-modem-helpers.h
@@ -58,6 +58,8 @@ gchar *mm_create_device_identifier (guint vid,
const gchar *model,
const gchar *manf);
+guint mm_netmask_to_cidr (const gchar *netmask);
+
/*****************************************************************************/
/* 3GPP specific helpers and utilities */
/*****************************************************************************/