mirror of
https://github.com/luckfox-eng29/kvm.git
synced 2026-01-18 03:28:19 +01:00
chore(log): add wolLogger
This commit is contained in:
9
wol.go
9
wol.go
@@ -3,7 +3,6 @@ package kvm
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
@@ -12,7 +11,7 @@ func rpcSendWOLMagicPacket(macAddress string) error {
|
||||
// Parse the MAC address
|
||||
mac, err := net.ParseMAC(macAddress)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid MAC address: %v", err)
|
||||
return ErrorfL(&wolLogger, "invalid MAC address", err)
|
||||
}
|
||||
|
||||
// Create the magic packet
|
||||
@@ -21,16 +20,18 @@ func rpcSendWOLMagicPacket(macAddress string) error {
|
||||
// Set up UDP connection
|
||||
conn, err := net.Dial("udp", "255.255.255.255:9")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to establish UDP connection: %v", err)
|
||||
return ErrorfL(&wolLogger, "failed to establish UDP connection", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
// Send the packet
|
||||
_, err = conn.Write(packet)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to send WOL packet: %v", err)
|
||||
return ErrorfL(&wolLogger, "failed to send WOL packet", err)
|
||||
}
|
||||
|
||||
wolLogger.Info().Str("mac", macAddress).Msg("WOL packet sent")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user