Adding configuration option for TCP and fixing a buffer overflow found by tosiara(https://github.com/tosiara)