uuid.c
Go to the documentation of this file.
00001 /*
00002  * Universally Unique IDentifier (UUID)
00003  * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 2 as
00007  * published by the Free Software Foundation.
00008  *
00009  * Alternatively, this software may be distributed under the terms of BSD
00010  * license.
00011  *
00012  * See README and COPYING for more details.
00013  */
00014 
00015 #include "includes.h"
00016 
00017 #include "common.h"
00018 #include "uuid.h"
00019 
00020 int uuid_str2bin(const char *str, u8 *bin)
00021 {
00022         const char *pos;
00023         u8 *opos;
00024 
00025         pos = str;
00026         opos = bin;
00027 
00028         if (hexstr2bin(pos, opos, 4))
00029                 return -1;
00030         pos += 8;
00031         opos += 4;
00032 
00033         if (*pos++ != '-' || hexstr2bin(pos, opos, 2))
00034                 return -1;
00035         pos += 4;
00036         opos += 2;
00037 
00038         if (*pos++ != '-' || hexstr2bin(pos, opos, 2))
00039                 return -1;
00040         pos += 4;
00041         opos += 2;
00042 
00043         if (*pos++ != '-' || hexstr2bin(pos, opos, 2))
00044                 return -1;
00045         pos += 4;
00046         opos += 2;
00047 
00048         if (*pos++ != '-' || hexstr2bin(pos, opos, 6))
00049                 return -1;
00050 
00051         return 0;
00052 }
00053 
00054 
00055 int uuid_bin2str(const u8 *bin, char *str, size_t max_len)
00056 {
00057         int len;
00058         len = os_snprintf(str, max_len, "%02x%02x%02x%02x-%02x%02x-%02x%02x-"
00059                           "%02x%02x-%02x%02x%02x%02x%02x%02x",
00060                           bin[0], bin[1], bin[2], bin[3],
00061                           bin[4], bin[5], bin[6], bin[7],
00062                           bin[8], bin[9], bin[10], bin[11],
00063                           bin[12], bin[13], bin[14], bin[15]);
00064         if (len < 0 || (size_t) len >= max_len)
00065                 return -1;
00066         return 0;
00067 }
00068 
00069 
00070 int is_nil_uuid(const u8 *uuid)
00071 {
00072         int i;
00073         for (i = 0; i < UUID_LEN; i++)
00074                 if (uuid[i])
00075                         return 0;
00076         return 1;
00077 }


wpa_supplicant_node
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Jan 2 2014 11:25:15