1 // Copyright 2017 Google Inc. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
11 var interfaces []net.Interface // cached list of interfaces
13 // getHardwareInterface returns the name and hardware address of interface name.
14 // If name is "" then the name and hardware address of one of the system's
15 // interfaces is returned. If no interfaces are found (name does not exist or
16 // there are no interfaces) then "", nil is returned.
18 // Only addresses of at least 6 bytes are returned.
19 func getHardwareInterface(name string) (string, []byte) {
20 if interfaces == nil {
22 interfaces, err = net.Interfaces()
27 for _, ifs := range interfaces {
28 if len(ifs.HardwareAddr) >= 6 && (name == "" || name == ifs.Name) {
29 return ifs.Name, ifs.HardwareAddr