From 3e2eeb18f140c821d12e714b5cb3731e28794ca4 Mon Sep 17 00:00:00 2001 From: save Date: Wed, 14 Oct 2009 09:56:24 +0000 Subject: 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 --- cleopatre/application/libspid/src/misc.c | 80 ++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 cleopatre/application/libspid/src/misc.c (limited to 'cleopatre/application/libspid/src/misc.c') 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 + * + * <<>> + * + * }}} */ +/** + * \file application/libspid/src/misc.c + * \brief misc functions + * \ingroup libspid + * + */ + +#include +#include +#include +#include +#include +#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).
+ * The array to store the binary MAC address needs to be provided.
+ * 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.
+ * The array to store the string MAC address needs to be provided with minimal + * size of 18 bytes (LIBSPID_MAC_STR_LEN).
+ * 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; +} + -- cgit v1.2.3