Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <Foundation/Foundation.h>
- #import <string>
- #import <iostream>
- @interface toff : NSObject {}
- @property(strong) NSData* dataRead;
- -(void) process:(NSNotification*)notification;
- @end
- @implementation toff
- &synthesize dataRead
- -(void) process:(NSNotification*)notification{
- printf("Packet caught!\n");
- //2 NSLog(@"Notif: %@", notification);
- //3 NSLog(@"Object: %@", [notification object]);
- //4 dataRead = [[notification object] readDataToEndOfFile];
- //5 NSLog(@"Data extracted.");
- //1 [[notification object] waitForDataInBackgroundAndNotify]
- }
- @end
- int main (int argc, const char * argv[]){
- @autoreleasepool {
- NSTask* tshark = [[NSTask alloc] init];
- NSPipe* p = [NSPipe pipe];
- NSFileHandle* read = [p fileHandleForReading];
- toff* t1 = [[toff alloc] init];
- NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
- [read waitForDataInBackgroundAndNotify];
- [nc addObserver:t1 selector:@selector(process:) name:NSFileHandleDataAvailableNotification object:read];
- [tshark setLaunchPath:@"/usr/local/bin/tshark"];
- [tshark setStandardOutput:p];
- [tshark launch];
- [tshark waitUntilExit];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment