Thanks for reply. I am showing pid value using string format in swift and "%d" formatter in c++.
Following is the my swift application structure & function.
struct ne_event_info_s {
var lport: Int32
var rport: Int32
var ip_size: Int32
var ip: String
var pid: pid_t
var direction : Int32
}
extension NEFilterFlow
{
var sourceAppAuditTokenQ: audit_token_t? {
guard
let tokenData = self.sourceAppAuditToken,
tokenData.count == MemoryLayout<audit_token_t>.size
else { return nil }
return tokenData.withUnsafeBytes { buf in
buf.baseAddress!.assumingMemoryBound(to: audit_token_t.self).pointee
}
}
var pid: pid_t {
return audit_token_to_pid(sourceAppAuditTokenQ!)
}
}
override func handleNewFlow(_ flow: NEFilterFlow) -> NEFilterNewFlowVerdict {
guard let socketFlow = flow as? NEFilterSocketFlow,
let remoteEndpoint = socketFlow.remoteEndpoint as? NWHostEndpoint,
let localEndpoint = socketFlow.localEndpoint as? NWHostEndpoint else {
return .allow()
}
			 var event_info = ne_event_info_t(
lport: Int32(localEndpoint.port) ?? 0,
rport: Int32(remoteEndpoint.port) ?? 0,
ip_size: Int32(remoteEndpoint.hostname.count),
ip: String(remoteEndpoint.hostname),
pid: flow.pid,
direction: dir == 2 ? 1 : 0)
os_log("event_info.lport = %@", String(event_info.lport))
os_log("event_info.rport = %@", String(event_info.rport))
os_log("event_info.ip_size = %@", String(event_info.ip_size))
os_log("event_info.pid = %@", String(event_info.pid))
os_log("Direction = %@", String(event_info.direction))
}
Following is C++ structure & function.
typedef struct ne_event_info_s {
int lport;
int rport;
int ip_size;
unsigned char ip[16];
pid_t pid;
int direction;
} ne_event_info_t;
void handleNEEvent(ne_event_info_t *info,) {
os_log("handleNEEvent: pid:%d, lport:%d,rport: %d\n", info->pid, info->lport,info->rport);
}
Topic:
Programming Languages
SubTopic:
Swift
Tags: