What exactly will you be tracing?

Do you mean a network trace like traceroute?

If so, take a look at any of the Open Source OSs. Ping and traceroute are the commands you'll need. Most of it is written in C though.

Here's the source from FreeBSD:

ping.c
traceroute

Have a look at http://www.samspade.org for a webinterface to traceroute.