summaryrefslogtreecommitdiff
path: root/cleopatre/application/libspid/src/misc.c
diff options
context:
space:
mode:
authorsave2009-10-14 09:56:24 +0000
committersave2009-10-14 09:56:24 +0000
commit3e2eeb18f140c821d12e714b5cb3731e28794ca4 (patch)
tree36a04921020c2ecf955c0c7995b442e9863e71ae /cleopatre/application/libspid/src/misc.c
parent48766cc853fa280fb58021d43ad8153bdb106e14 (diff)
cleo/application/spidlib: change spidlib name into libspid, closes #558
- spidlib names will be libspid - SPIDLIB... macros will be LIBSPID... - generated files will be libspid.a and libspid.so - linker option will be -lspid git-svn-id: svn+ssh://pessac/svn/cesar/trunk@6113 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cleopatre/application/libspid/src/misc.c')
-rw-r--r--cleopatre/application/libspid/src/misc.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/cleopatre/application/libspid/src/misc.c b/cleopatre/application/libspid/src/misc.c
new file mode 100644
index 0000000000..1c10bd0ef0
--- /dev/null
+++ b/cleopatre/application/libspid/src/misc.c
@@ -0,0 +1,80 @@
+/* SPC300 bundle {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file application/libspid/src/misc.c
+ * \brief misc functions
+ * \ingroup libspid
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <errno.h>
+#include "libspid.h"
+
+/**
+ * Convert a MAC address in string format aa:bb:cc:dd:ee:ff into a
+ * MAC address in binary format (6 bytes).<br>
+ * The array to store the binary MAC address needs to be provided.<br>
+ * Example : "00:23:54:ae:f5:24" ---> { 0x00, 0x23, 0x54, 0xae, 0xf5, 0x24 }
+ *
+ * \param str MAC address string
+ * \param bin MAC address returned in binary format
+ * \return error type (LIBSPID_SUCCESS if success)
+ * \return LIBSPID_ERROR_PARAM: bad input parameters
+ */
+
+libspid_error_t libspid_mac_str_to_bin(const char *str, unsigned char *bin)
+{
+ int i;
+ char *s, *e;
+
+ if( (bin == NULL) || (str == NULL) )
+ {
+ return LIBSPID_ERROR_PARAM;
+ }
+
+ s = (char *)str;
+ for (i = 0; i < 6; ++i)
+ {
+ bin[i] = s ? strtoul (s, &e, 16) : 0;
+ if (s)
+ s = (*e) ? e + 1 : e;
+ }
+
+ return LIBSPID_SUCCESS;
+}
+
+/**
+ * Convert a MAC address in binary format (6 bytes) into a MAC address
+ * in string format aa:bb:cc:dd:ee:ff.<br>
+ * The array to store the string MAC address needs to be provided with minimal
+ * size of 18 bytes (LIBSPID_MAC_STR_LEN).<br>
+ * Example : { 0x00, 0x23, 0x54, 0xae, 0xf5, 0x24 } ---> "00:23:54:ae:f5:24"
+ *
+ * \param bin MAC address returned in binary format
+ * \param str MAC address string
+ * \return error type (LIBSPID_SUCCESS if success)
+ * \return LIBSPID_ERROR_PARAM: bad input parameters
+ */
+
+libspid_error_t libspid_mac_bin_to_str(const unsigned char *bin, char *str)
+{
+ if( (bin == NULL) || (str == NULL) )
+ {
+ return LIBSPID_ERROR_PARAM;
+ }
+
+ sprintf ( str, "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
+ bin[0], bin[1], bin[2], bin[3], bin[4], bin[5] );
+
+ return LIBSPID_SUCCESS;
+}
+