Factor out msghdr processing into paired helpers.

Working towards #428.