You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/09/15 22:18:08 UTC

[2/3] incubator-mynewt-core git commit: mn_socket; mn_inet_ntop() for ipv6.

mn_socket; mn_inet_ntop() for ipv6.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/5951351e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/5951351e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/5951351e

Branch: refs/heads/develop
Commit: 5951351e34ae7651aa381e2b8fae9cea1a626dfd
Parents: fc14ad8
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Sep 15 13:44:45 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Sep 15 13:44:45 2016 -0700

----------------------------------------------------------------------
 sys/mn_socket/src/mn_socket_aconv.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5951351e/sys/mn_socket/src/mn_socket_aconv.c
----------------------------------------------------------------------
diff --git a/sys/mn_socket/src/mn_socket_aconv.c b/sys/mn_socket/src/mn_socket_aconv.c
index 23c500b..1ca6010 100644
--- a/sys/mn_socket/src/mn_socket_aconv.c
+++ b/sys/mn_socket/src/mn_socket_aconv.c
@@ -18,7 +18,7 @@
  */
 #include <ctype.h>
 #include <stdio.h>
-#include <os/queue.h>
+#include <os/endian.h>
 #include "mn_socket/mn_socket.h"
 
 int
@@ -61,7 +61,9 @@ const char *
 mn_inet_ntop(int af, const void *src_v, void *dst, int len)
 {
     const unsigned char *src = src_v;
+    const struct mn_in6_addr *a6;
     int rc;
+    int i;
 
     if (af == MN_PF_INET) {
         rc = snprintf(dst, len, "%u.%u.%u.%u",
@@ -72,6 +74,22 @@ mn_inet_ntop(int af, const void *src_v, void *dst, int len)
             return dst;
         }
     } else {
-        return NULL;
+        a6 = src_v;
+        rc = 0;
+
+        for (i = 0; i < sizeof(*a6); i += 2) {
+            rc += snprintf(dst + rc, len - rc, "%x",
+              htons(*(uint16_t *)&a6->s_addr[i]));
+            if (rc >= len) {
+                return NULL;
+            }
+            if (i < sizeof(*a6) - 2) {
+                rc += snprintf(dst + rc, len - rc, ":");
+                if (rc >= len) {
+                    return NULL;
+                }
+            }
+        }
+        return dst;
     }
 }