views:

319

answers:

3

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
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.
A re-implementation is, by definition, re-inventing the wheel. Plain C code will run just fine in an Objective-C application.
Azeem.Butt
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.
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
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
+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
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.
+3  A: 

You can grab the source code from here. But I agree with diciu, you will not be able to use it on raw sockets on a none-jailbreaked iphone

epatel
Thanks epatel. I already have a copy of the traceroute source. FYI, now looking at tcptraceroute http://michael.toren.net/code/tcptraceroute/
Gene M.
@Gene Myers Sounds like a good path to investigate
epatel