fix util
This commit is contained in:
parent
cac931020c
commit
a3af3fde32
@ -66,6 +66,20 @@ struct SDLUtil {
|
|||||||
return String(cString: hostBuffer)
|
return String(cString: hostBuffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static func ipv6StrToData(_ ip: String) -> Data? {
|
||||||
|
let normalizedIp = String(ip.split(separator: "%", maxSplits: 1, omittingEmptySubsequences: false).first ?? "")
|
||||||
|
guard !normalizedIp.isEmpty else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var address = in6_addr()
|
||||||
|
guard inet_pton(AF_INET6, normalizedIp, &address) == 1 else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return withUnsafeBytes(of: &address) { Data($0) }
|
||||||
|
}
|
||||||
|
|
||||||
// 判断ip地址是否在同一个网络
|
// 判断ip地址是否在同一个网络
|
||||||
public static func inSameNetwork(ip: UInt32, compareIp: UInt32, maskLen: UInt8) -> Bool {
|
public static func inSameNetwork(ip: UInt32, compareIp: UInt32, maskLen: UInt8) -> Bool {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user