Hi Ankit,

On 09/01/2017 12:53 AM, Ankit Navik wrote:
---
  drivers/atmodem/atutil.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
  drivers/atmodem/atutil.h |  3 +++
  2 files changed, 47 insertions(+)

diff --git a/drivers/atmodem/atutil.c b/drivers/atmodem/atutil.c
index 1487348..1067f20 100644
--- a/drivers/atmodem/atutil.c
+++ b/drivers/atmodem/atutil.c
@@ -27,6 +27,7 @@
  #include <gatchat.h>
  #include <string.h>
  #include <stdlib.h>
+#include <errno.h>
#define OFONO_API_SUBJECT_TO_CHANGE
  #include <ofono/log.h>
@@ -614,3 +615,46 @@ void at_util_sim_state_query_free(struct 
at_util_sim_state_query *req)
g_free(req);
  }
+
+/*
+ * CGCONTRDP returns addr + netmask in the same string in the form
+ * of "a.b.c.d.m.m.m.m" for IPv4.
+ * TODO: Add logic for IPv6.
+ */
Put a comment here stating that address/netmask must be able to hold
255.255.255.255 + null = 16 characters

+int at_util_set_address_and_netmask(const char *addrnetmask, char *address,
+                                       char *netmask)

Lets call this at_util_get_ipv4_address_and_netmask

+{
+       char *dup = strdup(addrnetmask);

You could avoid a strdup entirely by marking the position of the 4th dot and doing some pointer math...

+       char *s = dup;
+
+       const char *addr = s;
+       const char *net = NULL;
+
+       int ret = -EINVAL;
+       int i;
+
+       /* Count 7 dots for ipv4, less or more means error. */
+       for (i = 0; i < 8; i++, s++) {

This doesn't actually check that the number of dots > 7 ...

+               s = strchr(s, '.');
+
+               if (!s)
+                       break;
+
+               if (i == 3) {
+                       /* set netmask ptr and break the string */
+                       net = s + 1;
+                       s[0] = 0;
+               }
+       }
+
+       if (i == 7) {
+               strncpy(address, addr, strlen(addr));
+               strncpy(netmask, net, strlen(net));

This would appear not to copy the null terminator. Not sure this is intended?

+
+               ret = 0;
+       }
+
+       free(dup);
+
+       return ret;
+}
diff --git a/drivers/atmodem/atutil.h b/drivers/atmodem/atutil.h
index 5cb88b7..cc8fc52 100644
--- a/drivers/atmodem/atutil.h
+++ b/drivers/atmodem/atutil.h
@@ -83,6 +83,9 @@ struct at_util_sim_state_query 
*at_util_sim_state_query_new(GAtChat *chat,
                                                GDestroyNotify destroy);
  void at_util_sim_state_query_free(struct at_util_sim_state_query *req);
+int at_util_set_address_and_netmask(const char *addrnetmask, char *address,
+                                               char *netmask);
+
  struct cb_data {
        void *cb;
        void *data;


Regards,
-Denis
_______________________________________________
ofono mailing list
[email protected]
https://lists.ofono.org/mailman/listinfo/ofono

Reply via email to