Fix #3149: port mapping of TCP + UDP

Duplicate the code to fix the issue first.
Get back to re-factorize later.