aboutsummaryrefslogtreecommitdiff
path: root/helper/eth.c
diff options
context:
space:
mode:
authorPetri Savolainen <petri.savolainen@nokia.com>2016-02-09 14:25:07 +0200
committerMaxim Uvarov <maxim.uvarov@linaro.org>2016-03-03 22:32:04 +0300
commitcc03b63e667c3acf580f20765910dbb342d452b2 (patch)
tree491fc29041a2f0e75f9e4f89bfc1ae7ad268de80 /helper/eth.c
parent0ebc7f2d0788a2adec58e25032ba2317f9e089ac (diff)
helper: eth: added mac address parse
Ethernet MAC address parse function is commonly needed by test applications. A common parse function harmonizes the definition of MAC address as a command line parameter. Signed-off-by: Petri Savolainen <petri.savolainen@nokia.com> Reviewed-by: Juha-Matti Tilli <juha-matti.tilli@nokia.com> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'helper/eth.c')
-rw-r--r--helper/eth.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/helper/eth.c b/helper/eth.c
new file mode 100644
index 000000000..9a151fa23
--- /dev/null
+++ b/helper/eth.c
@@ -0,0 +1,36 @@
+/* Copyright (c) 2016, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <odp/helper/eth.h>
+
+#include <stdio.h>
+#include <string.h>
+
+int odph_eth_addr_parse(odph_ethaddr_t *mac, const char *str)
+{
+ int byte[ODPH_ETHADDR_LEN];
+ int i;
+
+ memset(byte, 0, sizeof(byte));
+
+ if (sscanf(str, "%x:%x:%x:%x:%x:%x",
+ &byte[0], &byte[1], &byte[2],
+ &byte[3], &byte[4], &byte[5]) != ODPH_ETHADDR_LEN)
+ return -1;
+
+ for (i = 0; i < ODPH_ETHADDR_LEN; i++)
+ if (byte[i] < 0 || byte[i] > 255)
+ return -1;
+
+ mac->addr[0] = byte[0];
+ mac->addr[1] = byte[1];
+ mac->addr[2] = byte[2];
+ mac->addr[3] = byte[3];
+ mac->addr[4] = byte[4];
+ mac->addr[5] = byte[5];
+
+ return 0;
+}