-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make hardware address fallback more robust #6
Make hardware address fallback more robust #6
Conversation
The following code returns nil on my Linux machine, because the network interface for "localhost", the loopback device, doesn't have a hardware address. ``` clojure (-> (InetAddress/getLocalHost) NetworkInterface/getByInetAddress .getHardwareAddress) ``` This patch uses the same fallback strategy that is used when an UnknownHostException exception happens.
Thanks! |
@maxcountryman Could you also cut a release, please? I came accross this issue while trying to use https://github.com/xsc/kithara, and I thing @xsc would also be interested in this patch. Thanks! |
@r0man I think I need to change how we look for hardware addresses. Do you mind telling me if this (import '[java.net InetAddress NetworkInterface])
(def hardware-address
(some->> (NetworkInterface/getNetworkInterfaces)
enumeration-seq
(remove #(.isLoopback %))
(map #(.getHardwareAddress %))
(filter identity)
first)) |
@maxcountryman This returns the hardware address of my
Maybe filter also by
|
@r0man the Erlang implementation doesn't seem concerned with whether the interface is running or not, only that it has a non-null MAC and that the MAC isn't But I worry that by adding filters we risk failing to find a valid MAC more frequently than we should. (It's worth pointing out that the Erlang implementation does not fallback to a random array of bytes.) |
@r0man what about something like this, which closely mirrors the Erlang implementation? (def ifs (->> (NetworkInterface/getNetworkInterfaces)
enumeration-seq
(map #(.getHardwareAddress %))
(filter identity)
(remove #(every? zero? %)))) This will return any interface which has a non-null and non-zeroed MAC address. If we can make a case for applying further filters, as you suggest above, I'm open to that possibility as well provided we can ensure it doesn't mean we hit the |
@maxcountryman Sounds good. Thanks for looking into this again! |
The following code returns nil on my Linux machine, because the network
interface for "localhost", the loopback device, doesn't have a hardware
address.
This patch uses the same fallback strategy that is used when an
UnknownHostException exception happens.