|
| 1 | +// SPDX-FileCopyrightText: (C) 2024 Intel Corporation |
| 2 | +// SPDX-License-Identifier: Apache 2.0 |
| 3 | + |
| 4 | +package cmd |
| 5 | + |
| 6 | +// #cgo LDFLAGS: -framework CoreFoundation -framework IOKit |
| 7 | +// #include <CoreFoundation/CoreFoundation.h> |
| 8 | +// #include <IOKit/IOKitLib.h> |
| 9 | +// |
| 10 | +// const char * |
| 11 | +// getSerialNumber() |
| 12 | +// { |
| 13 | +// CFMutableDictionaryRef matching = IOServiceMatching("IOPlatformExpertDevice"); |
| 14 | +// io_service_t service = IOServiceGetMatchingService(kIOMainPortDefault, matching); |
| 15 | +// CFStringRef serialNumber = IORegistryEntryCreateCFProperty(service, |
| 16 | +// CFSTR("IOPlatformSerialNumber"), kCFAllocatorDefault, 0); |
| 17 | +// const char *str = CFStringGetCStringPtr(serialNumber, kCFStringEncodingUTF8); |
| 18 | +// IOObjectRelease(service); |
| 19 | +// |
| 20 | +// return str; |
| 21 | +// } |
| 22 | +import "C" |
| 23 | + |
| 24 | +import ( |
| 25 | + "fmt" |
| 26 | + "net" |
| 27 | +) |
| 28 | + |
| 29 | +func getSerial() (string, error) { |
| 30 | + serialNumber := C.GoString(C.getSerialNumber()) |
| 31 | + return serialNumber, nil |
| 32 | +} |
| 33 | + |
| 34 | +func getMac(iface string) (string, error) { |
| 35 | + interfaces, err := net.Interfaces() |
| 36 | + if err != nil { |
| 37 | + return "", err |
| 38 | + } |
| 39 | + for _, i := range interfaces { |
| 40 | + if i.Name == iface { |
| 41 | + if i.HardwareAddr.String() == "00:00:00:00:00:00" { |
| 42 | + return "", fmt.Errorf("mac address for %s is zero", iface) |
| 43 | + } |
| 44 | + return i.HardwareAddr.String(), nil |
| 45 | + } |
| 46 | + } |
| 47 | + return "", fmt.Errorf("mac address for %s not found", iface) |
| 48 | +} |
0 commit comments