diff mbox

[PATCH/API-NEXT,2/3] helper/eth: add conversion of mac address to string

Message ID 1467965654-34734-2-git-send-email-forrest.shi@linaro.org
State New
Headers show

Commit Message

Forrest Shi July 8, 2016, 8:14 a.m. UTC
From: Xuelin Shi <forrest.shi@linaro.org>


generate mac string representation (XX:XX:XX:XX:XX:XX) of odph_ethaddr_t

Signed-off-by: Xuelin Shi <forrest.shi@linaro.org>

---
 helper/eth.c                    | 10 ++++++++++
 helper/include/odp/helper/eth.h | 14 ++++++++++++++
 2 files changed, 24 insertions(+)

-- 
2.1.0.27.g96db324

Comments

Mike Holmes July 15, 2016, 12:20 p.m. UTC | #1
On 8 July 2016 at 04:14, <forrest.shi@linaro.org> wrote:

> From: Xuelin Shi <forrest.shi@linaro.org>

>

> generate mac string representation (XX:XX:XX:XX:XX:XX) of odph_ethaddr_t

>

> Signed-off-by: Xuelin Shi <forrest.shi@linaro.org>

> ---

>  helper/eth.c                    | 10 ++++++++++

>  helper/include/odp/helper/eth.h | 14 ++++++++++++++

>  2 files changed, 24 insertions(+)

>

> diff --git a/helper/eth.c b/helper/eth.c

> index 9a151fa..1dbe60e 100644

> --- a/helper/eth.c

> +++ b/helper/eth.c

> @@ -34,3 +34,13 @@ int odph_eth_addr_parse(odph_ethaddr_t *mac, const char

> *str)

>

>         return 0;

>  }

> +

> +char *odph_eth_addr_string(odph_ethaddr_t *mac, char *buf)

> +{

> +       uint8_t *byte;

> +

> +       byte = mac->addr;

> +       sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X",

> +               byte[0], byte[1], byte[2], byte[3], byte[4], byte[5]);

> +       return buf;

> +}

> diff --git a/helper/include/odp/helper/eth.h

> b/helper/include/odp/helper/eth.h

> index 9f47ddf..fb2b24f 100644

> --- a/helper/include/odp/helper/eth.h

> +++ b/helper/include/odp/helper/eth.h

> @@ -120,6 +120,20 @@ ODP_STATIC_ASSERT(sizeof(odph_vlanhdr_t) ==

> ODPH_VLANHDR_LEN,

>  int odph_eth_addr_parse(odph_ethaddr_t *mac, const char *str);

>

>  /**

> + * Generate text string representation of a MAC address

> + *

> + * The mac address string representation (xx:xx:xx:xx:xx:xx) is stored

> into a

> + * buffer specified by the second param, caller should gurantee the size

> of the

> + * buffer is big enough.

> + *

> + * @param mac   Pointer to MAC address

> + * @param buf   Pointer to buffer to store string

> + *

> + * @return     Pointer to the supplied buffer

> + */

> +char *odph_eth_addr_string(odph_ethaddr_t *mac, char *buf);

>


This new api is not tested by the validation tests


> +

> +/**

>   * @}

>   */

>

> --

> 2.1.0.27.g96db324

>

>



-- 
Mike Holmes
Technical Manager - Linaro Networking Group
Linaro.org <http://www.linaro.org/> *│ *Open source software for ARM SoCs
"Work should be fun and collaborative, the rest follows"
diff mbox

Patch

diff --git a/helper/eth.c b/helper/eth.c
index 9a151fa..1dbe60e 100644
--- a/helper/eth.c
+++ b/helper/eth.c
@@ -34,3 +34,13 @@  int odph_eth_addr_parse(odph_ethaddr_t *mac, const char *str)
 
 	return 0;
 }
+
+char *odph_eth_addr_string(odph_ethaddr_t *mac, char *buf)
+{
+	uint8_t *byte;
+
+	byte = mac->addr;
+	sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X",
+		byte[0], byte[1], byte[2], byte[3], byte[4], byte[5]);
+	return buf;
+}
diff --git a/helper/include/odp/helper/eth.h b/helper/include/odp/helper/eth.h
index 9f47ddf..fb2b24f 100644
--- a/helper/include/odp/helper/eth.h
+++ b/helper/include/odp/helper/eth.h
@@ -120,6 +120,20 @@  ODP_STATIC_ASSERT(sizeof(odph_vlanhdr_t) == ODPH_VLANHDR_LEN,
 int odph_eth_addr_parse(odph_ethaddr_t *mac, const char *str);
 
 /**
+ * Generate text string representation of a MAC address
+ *
+ * The mac address string representation (xx:xx:xx:xx:xx:xx) is stored into a
+ * buffer specified by the second param, caller should gurantee the size of the
+ * buffer is big enough.
+ *
+ * @param mac   Pointer to MAC address
+ * @param buf   Pointer to buffer to store string
+ *
+ * @return 	Pointer to the supplied buffer
+ */
+char *odph_eth_addr_string(odph_ethaddr_t *mac, char *buf);
+
+/**
  * @}
  */