STP is implemented in the kernel similar to TCP. It makes use of the same socket layer and IP code, and has the same API as TCP. In fact, from user level the only difference is that the socket() system call is called with a different protocol number than TCP.
More details can be found in the following documentation.
A FreeBSD implementation, no longer maintained, can be found here.
STP simulator scripts for the ns simulator are available here, recently (June 2003) updated for ns-2.26.
Finally, a perl script for converting tcpdumps of STP connections into xgraph representation can be found here.