tcp: refactor ioctl helpers