add debug info
This commit is contained in:
parent
2c05d71dbe
commit
77a631a001
@ -6,7 +6,14 @@
|
||||
//
|
||||
import Foundation
|
||||
|
||||
struct ARPPacket {
|
||||
struct ARPPacket: CustomStringConvertible {
|
||||
var description: String {
|
||||
return """
|
||||
opcode: \(self.opcode), sender_ip: \(SDLUtil.int32ToIp(self.senderIP)), sender_mac: \(SDLUtil.formatMacAddress(mac: senderMAC)),
|
||||
target_ip: \(SDLUtil.int32ToIp(self.targetIP)), target_mac: \(SDLUtil.formatMacAddress(mac: targetMAC))
|
||||
"""
|
||||
}
|
||||
|
||||
// ARP操作码
|
||||
enum Opcode: UInt16 {
|
||||
case request = 0x01
|
||||
|
||||
@ -232,7 +232,7 @@ public class SDLContext: @unchecked Sendable {
|
||||
private func handleSuperEvent(event: SDLSuperClient.SuperEvent) async throws {
|
||||
switch event {
|
||||
case .ready:
|
||||
self.logger.log("[SDLContext] get registerSuper, mac address: \(Self.formatMacAddress(mac: self.devAddr.mac))", level: .debug)
|
||||
self.logger.log("[SDLContext] get registerSuper, mac address: \(SDLUtil.formatMacAddress(mac: self.devAddr.mac))", level: .debug)
|
||||
guard let message = try await self.superClient?.registerSuper(context: self).get() else {
|
||||
return
|
||||
}
|
||||
@ -391,7 +391,7 @@ public class SDLContext: @unchecked Sendable {
|
||||
await self.arpServer.append(ip: arpPacket.senderIP, mac: arpPacket.senderMAC)
|
||||
}
|
||||
} else {
|
||||
self.logger.log("[SDLContext] get invalid arp packet, target_ip: \(arpPacket)", level: .debug)
|
||||
self.logger.log("[SDLContext] get invalid arp packet: \(arpPacket), target_ip: \(SDLUtil.int32ToIp(arpPacket.targetIP)), net ip: \(SDLUtil.int32ToIp(self.devAddr.netAddr))", level: .debug)
|
||||
}
|
||||
} else {
|
||||
self.logger.log("[SDLContext] get invalid arp packet", level: .debug)
|
||||
@ -622,11 +622,4 @@ public class SDLContext: @unchecked Sendable {
|
||||
return Data(macAddress)
|
||||
}
|
||||
|
||||
// 将mac地址转换成字符串
|
||||
private static func formatMacAddress(mac: Data) -> String {
|
||||
let bytes = [UInt8](mac)
|
||||
|
||||
return bytes.map { String(format: "%02X", $0) }.joined(separator: ":").lowercased()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -42,5 +42,11 @@ struct SDLUtil {
|
||||
|
||||
return ip & mask == compareIp & mask
|
||||
}
|
||||
|
||||
public static func formatMacAddress(mac: Data) -> String {
|
||||
let bytes = [UInt8](mac)
|
||||
|
||||
return bytes.map { String(format: "%02X", $0) }.joined(separator: ":").lowercased()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user