well, you'd need to have a main loop using the listen function to accept incoming connections on port 23. when a connection is accepted, you'd fork into a child and a parent. the parent would continue to listen or new connections and the child would then handle all commands from the newly-connected client.
writing a full-fledged telnet server could be a difficult thing to do. keep in mind that there are many freeware telnet servers that may do exactly what you need.