Ok – I am writing a daemon in Objective C that checks the connected router mac address every 5 seconds.
I am completely new to objective C, and I am looking for a better way to do what I’m already doing.
I’m currently calling “arp -a” and parsing the results via “Task”:
NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath: @"/usr/sbin/arp"];
NSArray *arguments;
arguments = [NSArray arrayWithObjects: @"-a", nil];
[task setArguments: arguments];
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
[task launch];
NSData *data;
data = [file readDataToEndOfFile];
I’m afraid that this isn’t very efficient.
Any suggestions? I am running this codeblock once every 5 seconds.
Apple’s implementation of
arpis open source. Take a look at the file for an idea of its implementation… it’s not terribly convoluted. It is pure ANSI C, though.You should be able to simply copy-paste the majority of the functionality… and instead of printing the results, just store the raw address.
Edit: Here’s a stripped down version of the source that just runs the equivalent of
arp -a. This should compile without any special directives.