IRC messages are not nul terminated, thus strlen will not work. Use return value of recv instead. This should fix most text garbling.