I have a client app which does not permit specifying a non-standard destination port. In this example, it is an LDAP client which will only contact a host on the local network on the standard port 389. The LDAP server it is trying to contact is in the local network at 193.168.4.253, but listening on the non-standard port 712. So, I had to set up a port translation for outgoing connections. The code to achieve this is as follows (must be run with sudo privileges, or as root in a launchd startup daemon to make it persistent):
sysctl -w net.inet.ip.forwarding=1
ipfw add 01000 divert natd tcp from me to 192.168.4.253 389 via en0
ipfw add 01000 divert natd tcp from 192.168.4.253 712 to me via en0
cat > natd.conf << end
interface en0
reverse
same_ports
redirect_port tcp 192.168.4.253:712 192.168.4.253:389
redirect_port tcp 192.168.4.253:389 192.168.4.253:712
end
natd -f natd.conf
Specifically, what this does is enable ipfw forwarding, then set up that ipfw should pass all traffic to host 192.168.4.253 on port 389, and from host 192.168.4.253 port 712 to the natd daemon. natd gets launched as a daemon and is told to rewrite the outgoing connection to the host's port 389 to the "real" port 712. All returning packets from the host's port 712 are then translated back to the original port 389 expected by the client application.
[robg adds: I haven't tested this one.]

