Re: [Solved partially] NSTask with complexe command
Re: [Solved partially] NSTask with complexe command
- Subject: Re: [Solved partially] NSTask with complexe command
- From: Vincent Pottier <email@hidden>
- Date: Sat, 20 Mar 2004 12:24:02 +0100
Well in fact, it was working, but the probleme is that i get data only
when 8026 caracteres (don't know why this number) is sent to the
NSFileHandle, then i got two notifications (4013 caracteres each) and i
get data without any probleme.
But for my use i need getting data even for small caracteres quantity.
Does anyone have an idea, why i can't get small number of data?
Thanks in advance.
Vincent
Le 18 mars 04, ` 14:05, Vincent Pottier a icrit :
Hello,
I'm writing an application who notify me when a new network connection
is set. I've find a good way to do so: using tcpdump (available since
last security uptdate) via command:
sudo tcpdump -nqt 'tcp[tcpflags] & (tcp-syn|tcp-fin) != 0' //in fact
notify when connection closed to
So to use this command in cocoa i've write a daemon launch with
previlege (executeWithPrivilege...) calling tcpdump via NSTask and
NSFileHandle. And here is my problem, tcpdump is launch with sucess,
but no way to get the output, i'm using readInBackgroundAndNotify (Full
code at mail end) but gotData: function is never call. So i've try with
"tcpdump ip", gotData: fonction is call regulary, but no data is
available (i've lot of active connection).
Does someone know how to get output? Thanks in advance and sorry for
my poor English.
Vincent
- (void)myFunction
{
NSTask *tcpdump=[[NSTask alloc] init];
NSPipe *pipe=[[NSPipe alloc] init];
handle = [[pipe fileHandleForReading] retain];
[tcpdump setLaunchPath:@"/usr/sbin/tcpdump"];
[tcpdump setArguments:[NSArray arrayWithObjects:@"-nqt",
@"tcp[tcpflags] & (tcp-syn|tcp-fin) != 0", nil]];
[tcpdump setStandardOutput:pipe];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(gotData:) name:NSFileHandleDataAvailableNotification
object:handle]; // async read
[handle waitForDataInBackgroundAndNotify];
[tcpdump launch];
[tcpdump waitUntilExit];
}
- (void)gotData:(NSNotification *)myNotification
{
NSData *messageData = [[myNotification userInfo] objectForKey
NSFileHandleNotificationDataItem];
NSString *string=[[NSString alloc] initWithData:messageData
encoding:NSASCIIStringEncoding];
NSLog(@"String data: %@", string);
[handle waitForDataInBackgroundAndNotify];
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.