Commit 75a0c200 authored by Ivan Tyagov's avatar Ivan Tyagov

Do not try to generate unique UUIDs as if they are used a human should do....

Do not try to generate unique UUIDs as if they are used a human should do. Move code to a more re-usable file.
parent 5b0472e9
......@@ -35,3 +35,20 @@ loadFile(const char *const path) {
return fileContents;
}
char *randomString(size_t length)
{
static char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
char *randomString = NULL;
if (length) {
randomString = malloc(sizeof(char) * (length +1));
if (randomString) {
for (int n = 0;n < length;n++) {
int key = rand() % (int)(sizeof(charset) -1);
randomString[n] = charset[key];
}
randomString[length] = '\0';
}
}
return randomString;
}
......@@ -33,24 +33,6 @@
const int DEFAULT_OPC_UA_PORT = 4840;
const int DEFAULT_MODE = 0;
char *randomString(size_t length)
{
static char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
char *randomString = NULL;
if (length) {
randomString = malloc(sizeof(char) * (length +1));
if (randomString) {
for (int n = 0;n < length;n++) {
int key = rand() % (int)(sizeof(charset) -1);
randomString[n] = charset[key];
}
randomString[length] = '\0';
}
}
return randomString;
}
// CLI arguments handling
const char *argp_program_version = "OSIE OPC-UA coupler 0.0.1";
const char *argp_program_bug_address = "ivan@nexedi.com";
......@@ -152,11 +134,6 @@ int main(int argc, char **argv)
arguments.uuid = "";
argp_parse(&argp, argc, argv, 0, 0, &arguments);
// if no uuid define, generate a random one
if (!strlen(arguments.uuid)) {
arguments.uuid = randomString(12);
}
printf("Mode=%d\n", arguments.mode);
printf("Listening port=%d\n", arguments.port);
printf("Block device=%s\n", arguments.device);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment