Charm production in the forward region: constraints on the small-x gluon and backgrounds for neutrino astronomy