aboutsummaryrefslogtreecommitdiffstats
path: root/firmware/x300/lib/print_addrs.c
diff options
context:
space:
mode:
authorBen Hilburn <ben.hilburn@ettus.com>2014-02-04 11:04:07 -0800
committerBen Hilburn <ben.hilburn@ettus.com>2014-02-04 11:04:07 -0800
commit178ac3f1c9950d383c8f64b3df464c0f943c4a23 (patch)
tree318ed621a7b59b7d34d4ce6e4a92f73f0bcef509 /firmware/x300/lib/print_addrs.c
parent2718ac110fa931cc29daf7cb3dc5ab6230ee02ab (diff)
downloaduhd-178ac3f1c9950d383c8f64b3df464c0f943c4a23.tar.gz
uhd-178ac3f1c9950d383c8f64b3df464c0f943c4a23.tar.bz2
uhd-178ac3f1c9950d383c8f64b3df464c0f943c4a23.zip
Merging USRP X300 and X310 support!!
Diffstat (limited to 'firmware/x300/lib/print_addrs.c')
-rw-r--r--firmware/x300/lib/print_addrs.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/firmware/x300/lib/print_addrs.c b/firmware/x300/lib/print_addrs.c
new file mode 100644
index 000000000..6a710f75c
--- /dev/null
+++ b/firmware/x300/lib/print_addrs.c
@@ -0,0 +1,64 @@
+// Copyright 2013 Ettus Research LLC
+
+#include <print_addrs.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <printf.h>
+
+#define MAX_MAC_CHARS 24
+#define MAX_IP_CHARS 16
+
+static const char hex[16] = "0123456789ABCDEF";
+
+char *mac_addr_to_str_r(const void *addr, char *str)
+{
+ uint8_t *p = (uint8_t *)addr;
+ size_t j = 0;
+ for(size_t i = 0; i < 6; i++)
+ {
+ if (i) str[j++] = ':';
+ str[j++] = hex[(p[i] >> 4) & 0xf];
+ str[j++] = hex[p[i] & 0xf];
+ }
+ str[j++] = '\0';
+ return str;
+}
+
+char *ip_addr_to_str_r(const void *addr, char *str)
+{
+ uint8_t *p = (uint8_t *)addr;
+ sprintf(str, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
+ return str;
+}
+
+char *mac_addr_to_str(const void *addr)
+{
+ static size_t index = 0;
+ index = (index + 1) % 4;
+ static char str[4][MAX_MAC_CHARS];
+ return mac_addr_to_str_r(addr, str[index]);
+}
+
+char *ip_addr_to_str(const void *addr)
+{
+ static size_t index = 0;
+ index = (index + 1) % 4;
+ static char str[4][MAX_IP_CHARS];
+ return ip_addr_to_str_r(addr, str[index]);
+}
+
+/*
+void print_mac_addr(const void *addr)
+{
+ char str[MAX_MAC_CHARS];
+ mac_addr_to_str_r(addr, str);
+ printf("%s", str);
+}
+
+void print_ip_addr(const void *addr)
+{
+ char str[MAX_IP_CHARS];
+ ip_addr_to_str_r(addr, str);
+ printf("%s", str);
+}
+*/