Menu ▾ ▴

#454 QNX vos_getMacAddress implementation

3.0.1.0
closed
2440 (1) 2444 (1)
2024-05-31
2024-05-29
No

On QNX 7.1, vos_getMacAddress is currently not implemented. Below is a possible implementation. It also fixes a warning "control reaches end of non-void function" in vos_getVlanId.

--- src/vos/posix/vos_sock.c    (revision 2439)
+++ src/vos/posix/vos_sock.c    (working copy)
@@ -80,6 +80,7 @@
 #   include <net/if.h>
 #   include <net/if_types.h>
 #ifdef __QNXNTO__
+#   include <net/if_dl.h>
 #   include <gulliver.h>
 #   define bswap_16(x) ENDIAN_RET16(x)
 #   define bswap_32(x) ENDIAN_RET32(x)
@@ -309,7 +310,37 @@
     return found;

 #elif defined(__QNXNTO__)
-#   warning "no definition for get_mac_address() on this platform!"

+    struct ifaddrs  *pIfList;
+    BOOL8           found   = FALSE;
+    const char      *pName  = cDefaultIface;
+
+    if (pIfName != NULL)
+    {
+        pName = pIfName;
+    }
+
+    if (getifaddrs(&pIfList) == 0)
+    {
+        struct ifaddrs *cur;
+
+        for (cur = pIfList; pName != NULL && cur != NULL; cur = cur->ifa_next)
+        {
+            if (cur->ifa_addr &&
+                (cur->ifa_addr->sa_family == AF_LINK) &&
+                (strcmp(cur->ifa_name, pName) == 0))
+            {
+                struct sockaddr_dl *p = (struct sockaddr_dl *)(cur->ifa_addr);
+                memcpy(pMacAddr, LLADDR(p), VOS_MAC_SIZE);
+                found = TRUE;
+                break;
+            }
+        }
+
+        freeifaddrs(pIfList);
+    }
+
+    return found;
+
 #else
 #   error no definition for get_mac_address() on this platform!
 #endif
@@ -353,11 +384,13 @@
     return vlan_id;

 #elif defined(__APPLE__)
-#   warning "no definition for get_mac_address() on this platform!"
+#   warning "no definition for vos_getVlanId() on this platform!"

+    return 0;
 #elif defined(__QNXNTO__)
-#   warning "no definition for get_mac_address() on this platform!"
+#   warning "no definition for vos_getVlanId() on this platform!"
+    return 0;
 #else
-#   error no definition for get_mac_address() on this platform!
+#   error no definition for vos_getVlanId() on this platform!
 #endif
 }

Discussion

  • Armin-Hagen Weiss

    • labels: --> 2440
    • status: open --> closed
    • assigned_to: Armin-Hagen Weiss
     
  • Armin-Hagen Weiss

    Thanks for the fix Renaat !

     
  • Renaat Debaene

    Renaat Debaene - 2024-05-30

    I'm afraid the "#include <net if_dl.h="">" didn't make it in the commit. Without this line, the code doesn't compile/link on QNX</net>

     
  • Armin-Hagen Weiss

    • labels: 2440 --> 2440, 2444
     

Log in to post a comment.