├── .gitignore ├── LICENSE ├── README.md ├── VERSION.txt └── random-eui64.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | random-eui64 31 | 32 | # Debug files 33 | *.dSYM/ 34 | 35 | # backup files 36 | *.BAK 37 | *.CKP 38 | 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 MCCI Corporation 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # random-eui64 2 | 3 | Simple program for generating a locally-administered EUI, following the rules given in [IEEE 802](http://standards.ieee.org/getieee802/download/802-2014.pdf), section 8.2. 4 | 5 | A random EUI-64 may be useful for experimenters who are prototyping devices, and don't have access to a pool of globally-administered addresses. 6 | 7 | You'll have to judge whether you want to use a random ID. However, the definition of EUI-64 allows for this. 8 | 9 | Section 8.2 describes the u/l bit (bit 1) of byte 0 of EUI-64. If you set that bit, you have a "locally administered address". Bit 0 always has to be zero for addresses. So a legitimate way of generating a random address, with very low probability of collision, is to generate 8 random bytes, then set bit 1 of byte 0, clear bit 0 of byte 0. On Ubuntu, this simple program will do what you need. 10 | 11 | random-eui64 uses data from /dev/random to generate a suitable random address and prints it out in the canonical format. Becuase it uses /dev/random, it may delay indefinitely if your system doesn't have enough available entropy. 12 | 13 | Example: 14 | 15 | ```console 16 | $ random-eui64 17 | 4E-D9-09-C5-5E-57-B9-F6 18 | ``` 19 | 20 | ## Command-line Options 21 | 22 | This program is useful enough to merit a few options. 23 | 24 | `-eui48` causes it to generate a random 48-bit EUI rather than a 64-bit EUI. `-eui64` overrides this and restores the default. 25 | 26 | `-colon` causes the hex bytes of the address to be separated by `':'` characters. `-dash` overrides this, and causes the hex bytes to be separated by `'-'` characters. 27 | 28 | ## Building 29 | 30 | There's no makefile, but the default rules of `make` can be used. 31 | 32 | ```console 33 | $ make random-eui64 34 | cc random-eui64.c -o random-eui64 35 | ``` 36 | -------------------------------------------------------------------------------- /VERSION.txt: -------------------------------------------------------------------------------- 1 | V1.00 2 | -------------------------------------------------------------------------------- /random-eui64.c: -------------------------------------------------------------------------------- 1 | /* random-eui64.c Fri Jul 27 2018 19:59:57 tmm */ 2 | 3 | /* 4 | 5 | Module: random-eui64.c 6 | 7 | Function: 8 | Generate a random EUI-64 id. 9 | 10 | Version: 11 | V1.02 Fri Jul 27 2018 19:59:57 tmm Edit level 2 12 | 13 | Copyright notice: 14 | This file copyright (C) 2016, 2018 by 15 | 16 | MCCI Corporation 17 | 3520 Krums Corners Road 18 | Ithaca, NY 14850 19 | 20 | This code is released under the MIT license; see file named LICENSE in 21 | the same directory as this file. 22 | 23 | Author: 24 | Terry Moore, MCCI Corporation May 2016 25 | 26 | Revision history: 27 | 1.00 Sat May 14 2016 20:14:09 tmm 28 | Module created. 29 | 30 | 1.02 Fri Jul 27 2018 19:59:57 tmm 31 | Add options, eui-48 generation, etc. 32 | 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | int main(int ac, char **av) 43 | { 44 | int fd, iArg; 45 | unsigned char eui[8]; 46 | unsigned sizeEui, iEui; 47 | char cSep; 48 | 49 | sizeEui = 8; 50 | cSep = '-'; 51 | 52 | for (iArg = 1; iArg < ac; ++iArg) 53 | { 54 | if (strcmp(av[iArg], "-eui48") == 0) 55 | sizeEui = 6; 56 | else if (strcmp(av[iArg], "-eui64") == 0) 57 | sizeEui = 8; 58 | else if (strcmp(av[iArg], "-colon") == 0) 59 | cSep = ':'; 60 | else if (strcmp(av[iArg], "-dash") == 0) 61 | cSep = '-'; 62 | else if (strcmp(av[iArg], "-h") == 0 || 63 | strcmp(av[iArg], "--help") == 0 || 64 | strcmp(av[iArg], "-help") == 0) 65 | { 66 | errx(EXIT_SUCCESS, "usage: [-eui48 -eui64 -colon -dash]"); 67 | } 68 | else 69 | errx(EXIT_FAILURE, "invalid argument: %s", av[iArg]); 70 | } 71 | 72 | fd = open("/dev/random", O_RDONLY); 73 | if (fd < 0) 74 | { 75 | perror("can't open /dev/random"); 76 | exit(1); 77 | } 78 | 79 | if (read(fd, eui, sizeEui) != sizeEui) 80 | { 81 | fprintf(stderr, "couldn't read %u bytes\n", sizeEui); 82 | exit(1); 83 | } 84 | 85 | eui[0] = (eui[0] & ~1) | 2; 86 | for (iEui = 0; iEui < sizeEui; ++iEui) 87 | { 88 | printf("%02X%c", eui[iEui], iEui == sizeEui - 1 ? '\n' : cSep); 89 | } 90 | 91 | return 0; 92 | } 93 | --------------------------------------------------------------------------------