Does anyone know of a code sample in objective-c for traceroute? NOTE- I am looking for a code implementation of traceroute/tcptraceroute, NOT a utility.
A:
If you want to re-implement traceroute in Objective-C, then you're on your own. If you just want to run traceroute from Objective-C, NSTask will probably be the easiest for you, but it won't be possible on the iPhone.
Azeem.Butt
2009-12-28 11:33:45
I do in fact, wish to re-implement Traceroute in Objective-C. It does look like I'll need to port it from C, myself, but was hoping to not have to reinvent the wheel.
Gene M.
2009-12-28 11:36:37
A re-implementation is, by definition, re-inventing the wheel. Plain C code will run just fine in an Objective-C application.
Azeem.Butt
2009-12-28 11:39:28
OK, so you understand my motivation of re-implementing this in Objective-C; Plain C calls block the runloop in Mac OSX/iPhone development. Reimplementing traceroute so it doesn't block the runloop is not trivial, but necessary, if you wish to create a visual utility that updates as each TTL sequence is returned.
Gene M.
2009-12-28 11:47:43
Objective-C messages will block the runloop just as much as a C function call--primarily because Objective-C messages *are* a lengthy series of C function calls. Use a thread.
Azeem.Butt
2009-12-28 12:35:25
Objective-c messages **are not** a lengthy set of function calls. objc_msgSend() is, in the common case, a short sequence of assembly instructions followed by a tail call jump to the method's IMP (a standard C function). (Though, yes, any call will block the main event loop.)
bbum
2009-12-29 20:48:40
+1
A:
As far as I know the standard traceroute requires raw sockets (i.e. root access). On Mac OS X the traceroute binary is setuid:
cristi:~ diciu$ ls -la /usr/sbin/traceroute
-r-sr-xr-x 1 root wheel 110112 Oct 16 12:28 /usr/sbin/traceroute
I don't think you can use raw sockets on the iPhone - maybe tcptraceroute is an option?
diciu
2009-12-28 11:43:06
diciu- thanks, great headsup- tcptraceroute looks like a better option, also because it can it can bypass firewall filters as well. I appreciate the good feedback
Gene M.
2009-12-28 12:07:07