Getting the pid from NEFilterFlow in Objective C

I've tried copying this code and converting it to Objective C with no luck from this link https://developer.apple.com/forums/thread/126820

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
    }
}

}

Any ideas? Thanks

I've tried copying this code and converting it to Objective C with no luck from this link

Checkout Quinn's answer that is marked correct on the post.

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com

I'd like to see the Objective C example if possible.

Apple’s sample code and documentation will be increasingly written in Swift. If you’re using [Objective-]C[++], I encourage you to get a reading knowledge of Swift so that you can translate these resources to your preferred language.

The translation in this case is super easy. Accessing the audit token from Swift is hard because of Swift’s stricter type checking. In a C-based language you can just cast:

audit_token_t auditToken = * (audit_token_t *) self.sourceAppAuditToken.bytes;

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Getting the pid from NEFilterFlow in Objective C
 
 
Q