avtobiff / erlang-uuid

Erlang UUID
https://github.com/avtobiff/erlang-uuid
GNU Lesser General Public License v3.0
113 stars 77 forks source link

Fixes for hardware addresses that are zero or not six octets #20

Open WhiteRC opened 5 years ago

WhiteRC commented 5 years ago

Howdy, I've got two patches stored in my local git repository.

One corrects the directory hierarchy to move the include file into an include directory.

The other one fixes the case where a system has devices with hardware addresses that are zero or consist of other than six octets. Linux sit devices, for example, default to four bytes of zeros.

I can't create a text patch for the directory layout change, but the byte problem is included below.

If you want the direct (teste) push of both I need permissions.


src/uuid.erl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/uuid.erl b/src/uuid.erl
index 38a27c2..ecb7a66 100644
--- a/src/uuid.erl
+++ b/src/uuid.erl
@@ -318,8 +318,12 @@ hwaddr_find([{"lo", _IfConfig}|Rest]) ->
     hwaddr_find(Rest);
  hwaddr_find([{_IfName, IfConfig}|Rest]) ->
     case lists:keyfind(hwaddr, 1, IfConfig) of
-        {hwaddr, HwAddr} ->
+        {hwaddr, [0,0,0,0,0,0] = _HwAddr} ->
+            hwaddr_find(Rest);
+        {hwaddr, HwAddr} when length(HwAddr) == 6 ->
             list_to_binary(HwAddr);
+        {hwaddr, _HwAddr} ->
+            hwaddr_find(Rest);
         false ->
             hwaddr_find(Rest)
     end;
-- 
2.22.0
avtobiff commented 5 years ago

Thanks!

Can you push your repository to github and open a pull request?