Guest User

8945770

a guest
Jan 23rd, 2012
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import <Foundation/Foundation.h>
  2. #import <string>
  3. #import <iostream>
  4.  
  5. @interface toff : NSObject {}
  6. @property(strong) NSData* dataRead;
  7. -(void) process:(NSNotification*)notification;
  8. @end
  9.  
  10. @implementation toff
  11. &synthesize dataRead
  12.  
  13. -(void) process:(NSNotification*)notification{
  14.     printf("Packet caught!\n");
  15. //2    NSLog(@"Notif: %@", notification);
  16. //3    NSLog(@"Object: %@", [notification object]);
  17. //4    dataRead = [[notification object] readDataToEndOfFile];
  18. //5    NSLog(@"Data extracted.");
  19. //1    [[notification object] waitForDataInBackgroundAndNotify]
  20. }
  21. @end
  22.  
  23. int main (int argc, const char * argv[]){
  24.     @autoreleasepool {
  25.         NSTask* tshark = [[NSTask alloc] init];
  26.         NSPipe* p = [NSPipe pipe];
  27.         NSFileHandle* read = [p fileHandleForReading];
  28.         toff* t1 = [[toff alloc] init];
  29.         NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
  30.  
  31.         [read waitForDataInBackgroundAndNotify];
  32.         [nc addObserver:t1 selector:@selector(process:) name:NSFileHandleDataAvailableNotification object:read];
  33.  
  34.         [tshark setLaunchPath:@"/usr/local/bin/tshark"];
  35.         [tshark setStandardOutput:p];
  36.         [tshark launch];
  37.         [tshark waitUntilExit];
  38.     }
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment