mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-15 04:24:32 +00:00
2007-09-12 Dan Williams <dcbw@redhat.com>
* src/NetworkManagerUtils.c src/NetworkManagerUtils.h - (nm_utils_hexstr2bin): new function git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2794 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
7e079e3111
commit
ef1624f204
|
@ -1,3 +1,9 @@
|
|||
2007-09-12 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* src/NetworkManagerUtils.c
|
||||
src/NetworkManagerUtils.h
|
||||
- (nm_utils_hexstr2bin): new function
|
||||
|
||||
2007-09-11 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* src/nm-manager.c
|
||||
|
|
|
@ -645,3 +645,56 @@ nm_utils_same_ssid (const GByteArray * ssid1,
|
|||
return memcmp (ssid1->data, ssid2->data, ssid1_len) == 0 ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/* From hostap, Copyright (c) 2002-2005, Jouni Malinen <jkmaline@cc.hut.fi> */
|
||||
|
||||
static int hex2num (char c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
return c - '0';
|
||||
if (c >= 'a' && c <= 'f')
|
||||
return c - 'a' + 10;
|
||||
if (c >= 'A' && c <= 'F')
|
||||
return c - 'A' + 10;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int hex2byte (const char *hex)
|
||||
{
|
||||
int a, b;
|
||||
a = hex2num(*hex++);
|
||||
if (a < 0)
|
||||
return -1;
|
||||
b = hex2num(*hex++);
|
||||
if (b < 0)
|
||||
return -1;
|
||||
return (a << 4) | b;
|
||||
}
|
||||
|
||||
char *
|
||||
nm_utils_hexstr2bin (const char *hex,
|
||||
size_t len)
|
||||
{
|
||||
size_t i;
|
||||
int a;
|
||||
const char * ipos = hex;
|
||||
char * buf = NULL;
|
||||
char * opos;
|
||||
|
||||
/* Length must be a multiple of 2 */
|
||||
if ((len % 2) != 0)
|
||||
return NULL;
|
||||
|
||||
opos = buf = g_malloc0 ((len / 2) + 1);
|
||||
for (i = 0; i < len; i += 2) {
|
||||
a = hex2byte (ipos);
|
||||
if (a < 0) {
|
||||
g_free (buf);
|
||||
return NULL;
|
||||
}
|
||||
*opos++ = a;
|
||||
ipos += 2;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* End from hostap */
|
||||
|
|
|
@ -113,5 +113,7 @@ gboolean nm_utils_same_ssid (const GByteArray * ssid1,
|
|||
const GByteArray * ssid2,
|
||||
gboolean ignore_trailing_null);
|
||||
|
||||
char * nm_utils_hexstr2bin (const char *hex, size_t len);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in a new issue